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 4264dc15e19 (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>
Ævar Arnfjörð Bjarmason committed
Aug 23, 2021 at 13:36 UTC
7aa7829f754ab722d558e0408ec6f3dbf23ba70f
1 file changed
+13
refs/files-backend.c
+13
@@ -3061,6 +3061,19 @@ static int files_reflog_expire(struct ref_store *ref_store,
3061
strbuf_release(&err);
3062
return -1;
3063
}
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
+ */
3077
if (!refs_reflog_exists(ref_store, refname)) {
3078
unlock_ref(lock);
3079
return 0;