From 5133ead5286546d65b038b9381ef8b1cd4663c0b Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 16 Jul 2024 12:56:25 -0700 Subject: Revert "reflog expire: don't use lookup_commit_reference_gently()" During Git 2.35 timeframe, daf1d828 (reflog expire: don't use lookup_commit_reference_gently(), 2021-12-22) replaced a call to lookup_commit_reference_gently() with a call to lookup_commit(). What it failed to consider was that our refs do not necessarily point at commits (most notably, we have annotated and signed tags), and more importantly that lookup_commit() does not dereference a tag to return a commit; instead it returns NULL when a tag is given. Since the commit returned is used as a starting point for the reachability check, this ejected the commits that are reachable only by an annotated tag out of the set of reachable commits, breaking the computation to correctly implement the "--expire-unreachable" option. We also started giving an error message that the API function expected to be fed a commit object. This problem hasn't been reported or noticed for a long time, probably because the "refs/tags/" hierarchy by default is not covered by reflogs, as nobody usually moves tags. Revert the change to correctly find the commit pointed at by the ref to restore the previous behaviour, but do so only in a more modern codebase, as we had significant code churn since then and it is not grave enough to worry about for older maintenance tracks. Signed-off-by: Junio C Hamano --- reflog.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'reflog.c') diff --git a/reflog.c b/reflog.c index 0a1bc35e8c..2e45a17e12 100644 --- a/reflog.c +++ b/reflog.c @@ -330,7 +330,8 @@ void reflog_expiry_prepare(const char *refname, if (!cb->cmd.expire_unreachable || is_head(refname)) { cb->unreachable_expire_kind = UE_HEAD; } else { - commit = lookup_commit(the_repository, oid); + commit = lookup_commit_reference_gently(the_repository, + oid, 1); if (commit && is_null_oid(&commit->object.oid)) commit = NULL; cb->unreachable_expire_kind = commit ? UE_NORMAL : UE_ALWAYS; -- cgit v1.2.3