Skip to content

Commit 7521cc4

Browse files
rsahlberggitster
authored andcommitted
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 <[email protected]> Reviewed-by: Michael Haggerty <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 029cdb4 commit 7521cc4

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

refs.c

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,11 +2548,6 @@ int repack_without_refs(const char **refnames, int n, struct strbuf *err)
25482548
return ret;
25492549
}
25502550

2551-
static int repack_without_ref(const char *refname)
2552-
{
2553-
return repack_without_refs(&refname, 1, NULL);
2554-
}
2555-
25562551
static int delete_ref_loose(struct ref_lock *lock, int flag)
25572552
{
25582553
if (!(flag & REF_ISPACKED) || flag & REF_ISSYMREF) {
@@ -2570,24 +2565,22 @@ static int delete_ref_loose(struct ref_lock *lock, int flag)
25702565

25712566
int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
25722567
{
2573-
struct ref_lock *lock;
2574-
int ret = 0, flag = 0;
2568+
struct ref_transaction *transaction;
2569+
struct strbuf err = STRBUF_INIT;
25752570

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);
25782579
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;
25912584
}
25922585

25932586
/*

0 commit comments

Comments
 (0)