reflog: clear leftovers in reflog_expiry_cleanup()

reflog_expiry_prepare() calls mark_reachable(), which recurively flags commits as REACHABLE. The traversal stops beyond a certain age threshold; the boundary commits also marked as REACHABLE and put back into mark_list at the end. unreachable() finishes the traversal down to the roots if necessary -- but if all interesting commits are younger than the age threshold then only recent commits need to be visited. When this optimization works then the boundary commits still sit there in mark_list at the end. Clear their REACHABLE flag and release the commit list allocations. While at it remove a duplicate code line from mark_reachable(); the same flag is already set five lines up. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Dec 13, 2022 at 07:20 UTC b07a819c05f47ac07dec9704c121a2cfb4857ebe
1 file changed +3 -1
reflog.c
+3 -1
@@ -193,7 +193,6 @@ static void mark_reachable(struct expire_reflog_policy_cb *cb)
193 commit_list_insert(commit, &leftover);
194 continue;
195 }
196 - commit->object.flags |= REACHABLE;
196 parent = commit->parents;
197 while (parent) {
198 commit = parent->item;
@@ -378,6 +377,9 @@ void reflog_expiry_cleanup(void *cb_data)
377 clear_commit_marks(cb->tip_commit, REACHABLE);
378 break;
379 }
380 + for (elem = cb->mark_list; elem; elem = elem->next)
381 + clear_commit_marks(elem->item, REACHABLE);
382 + free_commit_list(cb->mark_list);
383 }
384
385 int count_reflog_ent(struct object_id *ooid UNUSED,