Skip to content

Commit 7aa7829

Browse files
avargitster
authored andcommitted
refs/files: add a comment about refs_reflog_exists() call
Add a comment about why it is that we need to check for the the existence of a reflog we're deleting after we've successfully acquired the lock in files_reflog_expire(). As noted in [1] the lock protocol for reflogs is somewhat intuitive. This early exit code the comment applies to dates all the way back to 4264dc1 (git reflog expire, 2006-12-19). 1. https://lore.kernel.org/git/54DCDA42.2060800@alum.mit.edu/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 6f45ec8 commit 7aa7829

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

refs/files-backend.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3061,6 +3061,19 @@ static int files_reflog_expire(struct ref_store *ref_store,
30613061
strbuf_release(&err);
30623062
return -1;
30633063
}
3064+
3065+
/*
3066+
* When refs are deleted, their reflog is deleted before the
3067+
* ref itself is deleted. This is because there is no separate
3068+
* lock for reflog; instead we take a lock on the ref with
3069+
* lock_ref_oid_basic().
3070+
*
3071+
* If a race happens and the reflog doesn't exist after we've
3072+
* acquired the lock that's OK. We've got nothing more to do;
3073+
* We were asked to delete the reflog, but someone else
3074+
* deleted it! The caller doesn't care that we deleted it,
3075+
* just that it is deleted. So we can return successfully.
3076+
*/
30643077
if (!refs_reflog_exists(ref_store, refname)) {
30653078
unlock_ref(lock);
30663079
return 0;

0 commit comments

Comments
 (0)