refs.c: make delete_ref use a transaction

Change delete_ref to use a ref transaction for the deletion. At the same time since we no longer have any callers of repack_without_ref we can now delete this function. Change delete_ref to return 0 on success and 1 on failure instead of the previous 0 on success either 1 or -1 on failure. Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ronnie Sahlberg committed Apr 30, 2014 at 09:22 UTC 7521cc4611a783f4a8174bd0fcec5f4a47357ac1
1 file changed +14 -21
refs.c
+14 -21
@@ -2548,11 +2548,6 @@ int repack_without_refs(const char **refnames, int n, struct strbuf *err)
2548 return ret;
2549 }
2550
2551 -static int repack_without_ref(const char *refname)
2552 -{
2553 - return repack_without_refs(&refname, 1, NULL);
2554 -}
2555 -
2551 static int delete_ref_loose(struct ref_lock *lock, int flag)
2552 {
2553 if (!(flag & REF_ISPACKED) || flag & REF_ISSYMREF) {
@@ -2570,24 +2565,22 @@ static int delete_ref_loose(struct ref_lock *lock, int flag)
2565
2566 int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
2567 {
2573 - struct ref_lock *lock;
2574 - int ret = 0, flag = 0;
2568 + struct ref_transaction *transaction;
2569 + struct strbuf err = STRBUF_INIT;
2570
2576 - lock = lock_ref_sha1_basic(refname, sha1, delopt, &flag);
2577 - if (!lock)
2571 + transaction = ref_transaction_begin(&err);
2572 + if (!transaction ||
2573 + ref_transaction_delete(transaction, refname, sha1, delopt,
2574 + sha1 && !is_null_sha1(sha1), &err) ||
2575 + ref_transaction_commit(transaction, NULL, &err)) {
2576 + error("%s", err.buf);
2577 + ref_transaction_free(transaction);
2578 + strbuf_release(&err);
2579 return 1;
2579 - ret |= delete_ref_loose(lock, flag);
2580 -
2581 - /* removing the loose one could have resurrected an earlier
2582 - * packed one. Also, if it was not loose we need to repack
2583 - * without it.
2584 - */
2585 - ret |= repack_without_ref(lock->ref_name);
2586 -
2587 - unlink_or_warn(git_path("logs/%s", lock->ref_name));
2588 - clear_loose_ref_cache(&ref_cache);
2589 - unlock_ref(lock);
2590 - return ret;
2580 + }
2581 + ref_transaction_free(transaction);
2582 + strbuf_release(&err);
2583 + return 0;
2584 }
2585
2586 /*