{"thread":{"id":"58940","subject":"[PATCH] reflog: clear leftovers in reflog_expiry_cleanup()","startedAt":"2022-12-13T06:20:20Z","lastAt":"2022-12-13T06:20:20Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"468970","messageId":"a53d4df3-4b2c-585a-e8ad-2a9b9017fb8c@web.de","threadId":"58940","inReplyTo":null,"subject":"[PATCH] reflog: clear leftovers in reflog_expiry_cleanup()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2022-12-13T06:20:09Z","receivedAt":"2022-12-13T06:20:20Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"reflog_expiry_prepare() calls mark_reachable(), which recurively flags\ncommits as REACHABLE.  The traversal stops beyond a certain age\nthreshold; the boundary commits also marked as REACHABLE and put back\ninto mark_list at the end.  unreachable() finishes the traversal down to\nthe roots if necessary -- but if all interesting commits are younger\nthan the age threshold then only recent commits need to be visited.\n\nWhen this optimization works then the boundary commits still sit there\nin mark_list at the end.  Clear their REACHABLE flag and release the\ncommit list allocations.\n\nWhile at it remove a duplicate code line from mark_reachable(); the same\nflag is already set five lines up.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\nFormatted with -U5 for easier review.\n\n reflog.c | 4 +++-\n 1 file changed, 3 insertions(+), 1 deletion(-)\n\ndiff --git a/reflog.c b/reflog.c\nindex 78e9350e20..04630f56ec 100644\n--- a/reflog.c\n+++ b/reflog.c\n@@ -191,11 +191,10 @@ static void mark_reachable(struct expire_reflog_policy_cb *cb)\n \t\tcommit->object.flags |= REACHABLE;\n \t\tif (commit->date < expire_limit) {\n \t\t\tcommit_list_insert(commit, &leftover);\n \t\t\tcontinue;\n \t\t}\n-\t\tcommit->object.flags |= REACHABLE;\n \t\tparent = commit->parents;\n \t\twhile (parent) {\n \t\t\tcommit = parent->item;\n \t\t\tparent = parent->next;\n \t\t\tif (commit->object.flags & REACHABLE)\n@@ -369,10 +368,13 @@ void reflog_expiry_cleanup(void *cb_data)\n \t\tbreak;\n \tcase UE_NORMAL:\n \t\tclear_commit_marks(cb->tip_commit, REACHABLE);\n \t\tbreak;\n \t}\n+\tfor (elem = cb->mark_list; elem; elem = elem->next)\n+\t\tclear_commit_marks(elem->item, REACHABLE);\n+\tfree_commit_list(cb->mark_list);\n }\n\n int count_reflog_ent(struct object_id *ooid UNUSED,\n \t\t     struct object_id *noid UNUSED,\n \t\t     const char *email UNUSED,\n--\n2.38.2\n"}]}