git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/2] builtin/reflog: expire each reflog only once

From
LBLaveesh Bansal <laveeshb@laveeshbansal.com>
Date
Nov 10, 2026, 15:26 UTC
Message-ID
<0e5d78f552deaf3bd0ba2ec70666cebc2957c9e4.1794324064.git.laveeshb@laveeshbansal.com>
In-Reply-To
<cover.1794324064.git.laveeshb@laveeshbansal.com>

"git reflog expire" processes a reflog once for every time it is named, and reports it every time:

    $ git reflog expire --dry-run --verbose --expire=now main main
    would prune commit (initial): one
    would prune commit (initial): one

The same happens for two names of the same ref, such as "main" and "refs/heads/main", and for a name that --all already covers.

Skip a reflog that this run has already processed.
Signed-off-by: Laveesh Bansal <laveeshb@laveeshbansal.com>
---
Notes:
    With --updateref, the first pass can move the ref, so a second pass
    over the same reflog could prune entries that the new tip no longer
    reaches.  It now ends as if the name had been given once.
 builtin/reflog.c  |  8 ++++++++
 t/t1410-reflog.sh | 14 ++++++++++++++
 2 files changed, 22 insertions(+)
diff --git a/builtin/reflog.c b/builtin/reflog.c
index 42d37a3724..4221136298 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -190,6 +190,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
 	struct worktree_reflogs collected = {
 		.reflogs = STRING_LIST_INIT_DUP,
 	};
+	struct string_list seen = STRING_LIST_INIT_DUP;
 	struct string_list_item *item;
 	const struct option options[] = {
 		OPT_BIT('n', "dry-run", &flags, N_("do not actually prune any entries"),
@@ -285,6 +286,12 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
 		if (ref)
 			refname = ref;
 
+		if (string_list_has_string(&seen, refname)) {
+			free(ref);
+			continue;
+		}
+		string_list_insert(&seen, refname);
+
 		reflog_expire_options_set_refname(&cb.opts, refname);
 		status |= refs_reflog_expire(get_main_ref_store(the_repository),
 					     refname, flags,
@@ -295,6 +302,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
 		free(ref);
 	}
 	string_list_clear(&collected.reflogs, 0);
+	string_list_clear(&seen, 0);
 
 	reflog_clear_expire_config(&opts);
 
diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh
index 998a7e8667..d22216c36d 100755
--- a/t/t1410-reflog.sh
+++ b/t/t1410-reflog.sh
@@ -274,6 +274,20 @@ test_expect_success 'reflog expire --dry-run --verbose --all' '
 	test_cmp before after
 '
 
+test_expect_success 'reflog expire does not process a reflog twice' '
+	git reflog expire --dry-run --verbose \
+		--expire=$(($test_tick - 10000)) \
+		--expire-unreachable=$(($test_tick - 10000)) \
+		--stale-fix \
+		--all >once &&
+	git reflog expire --dry-run --verbose \
+		--expire=$(($test_tick - 10000)) \
+		--expire-unreachable=$(($test_tick - 10000)) \
+		--stale-fix \
+		--all main refs/heads/main main >twice &&
+	test_cmp once twice
+'
+
 test_expect_success 'reflog expire' '
 
 	git reflog expire --verbose \
-- 
2.54.0
Previous: Laveesh BansalNext: Patrick Steinhardt
Message 8 of 9 in “builtin/reflog: expire --all and named refs in one loop”
  1. builtin/reflog: expire --all and named refs in one loopLaveesh Bansal, Nov 8, 2026
  2. Patrick SteinhardtNov 9, 2026
  3. Laveesh BansalNov 9, 2026
  4. Patrick SteinhardtNov 10, 2026
  5. Junio C HamanoNov 9, 2026
  6. 0/2 builtin/reflog: expire each reflog only onceLaveesh Bansal, Nov 10, 2026
  7. 1/2 builtin/reflog: expire --all and named refs in one loopLaveesh Bansal, Nov 10, 2026
  8. 2/2 builtin/reflog: expire each reflog only onceLaveesh Bansal, Nov 10, 2026
  9. Patrick SteinhardtNov 11, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.