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

[PATCH 10/12] reflog expire: add progress output on --stale-fix

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Nov 30, 2021, 21:38 UTC
Message-ID
<patch-10.12-f54dee1f1cc-20211130T213319Z-avarab@gmail.com>
In-Reply-To
<cover-00.12-00000000000-20211130T213319Z-avarab@gmail.com>

Add progress output when the "git reflog expire --stale-fix" option is used. This output was previously only emitted under --verbose, but we shouldn't treat it the same way as the actually verbose "--verbose" output emitted in should_expire_reflog_ent().

Note that this code isn't going to be affected by the sort of bug we had to fix in 6b89a34c89f (gc: fix regression in 7b0f229222 impacting --quiet, 2018-09-19). I.e. "git gc" won't call it with the "--stale-fix" flag, that option is purely used as a one-off.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 Documentation/git-reflog.txt |  8 ++++++++
 builtin/reflog.c             | 18 +++++++++++++-----
 2 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-reflog.txt b/Documentation/git-reflog.txt
index ff487ff77d3..1735bbea9fb 100644
--- a/Documentation/git-reflog.txt
+++ b/Documentation/git-reflog.txt
@@ -69,6 +69,14 @@ Options for `show`
 Options for `expire`
 ~~~~~~~~~~~~~~~~~~~~
 
+--progress::
+--no-progress::
+	Progress status is reported on the standard error stream by
+	default when it is attached to a terminal. The `--progress
+	flag enables progress reporting even if not attached to a
+	terminal. Supplying `--no-progress` will suppress all progress
+	output.
+
 --all::
 	Process the reflogs of all references.
 
diff --git a/builtin/reflog.c b/builtin/reflog.c
index a77c0d96dce..cf0ef68d82d 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -11,6 +11,7 @@
 #include "revision.h"
 #include "reachable.h"
 #include "worktree.h"
+#include "progress.h"
 
 /* NEEDSWORK: switch to using parse_options */
 static const char reflog_expire_usage[] =
@@ -551,6 +552,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
 	int explicit_expiry = 0;
 	unsigned int flags = 0;
 	int verbose = 0;
+	int show_progress = -1;
 
 	default_reflog_expire_unreachable = now - 30 * 24 * 3600;
 	default_reflog_expire = now - 90 * 24 * 3600;
@@ -579,6 +581,10 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
 		}
 		else if (!strcmp(arg, "--stale-fix"))
 			cmd.stalefix = 1;
+		else if (!strcmp(arg, "--progress"))
+			show_progress = 1;
+		else if (!strcmp(arg, "--no-progress"))
+			show_progress = 0;
 		else if (!strcmp(arg, "--rewrite"))
 			flags |= EXPIRE_REFLOGS_REWRITE;
 		else if (!strcmp(arg, "--updateref"))
@@ -598,6 +604,8 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
 		else
 			break;
 	}
+	if (show_progress == -1)
+		show_progress = isatty(2);
 
 	/*
 	 * We can trust the commits and objects reachable from refs
@@ -606,16 +614,16 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
 	 */
 	if (cmd.stalefix) {
 		struct rev_info revs;
+		struct progress *progress = NULL;
 
+		if (show_progress)
+			progress = start_delayed_progress(_("Marking reachable objects"), 0);
 		repo_init_revisions(the_repository, &revs, prefix);
 		revs.do_not_die_on_missing_tree = 1;
 		revs.ignore_missing = 1;
 		revs.ignore_missing_links = 1;
-		if (verbose)
-			printf(_("Marking reachable objects..."));
-		mark_reachable_objects(&revs, 0, 0, NULL);
-		if (verbose)
-			putchar('\n');
+		mark_reachable_objects(&revs, 0, 0, progress);
+		stop_progress(&progress);
 	}
 
 	if (do_all) {
-- 
2.34.1.877.g7d5b0a3b8a6
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 11 of 37 in “reflog + gc: refactor, progress output, reftable-readyness”
  1. 00/12 reflog + gc: refactor, progress output, reftable-readynessÆvar Arnfjörð Bjarmason, Nov 30, 2021
  2. 01/12 reflog delete: narrow scope of "cmd" passed to count_reflog_ent()Ævar Arnfjörð Bjarmason, Nov 30, 2021
  3. 02/12 reflog expire: narrow scope of "cb" in cmd_reflog_expire()Ævar Arnfjörð Bjarmason, Nov 30, 2021
  4. 03/12 reflog: change one->many worktree->refnames to use a string_listÆvar Arnfjörð Bjarmason, Nov 30, 2021
  5. 04/12 reflog expire: don't do negative comparison on enum valuesÆvar Arnfjörð Bjarmason, Nov 30, 2021
  6. 05/12 reflog expire: refactor & use "tip_commit" only for UE_NORMALÆvar Arnfjörð Bjarmason, Nov 30, 2021
  7. 06/12 reflog expire: don't use lookup_commit_reference_gently()Ævar Arnfjörð Bjarmason, Nov 30, 2021
  8. 07/12 reflog: reduce scope of "struct rev_info"Ævar Arnfjörð Bjarmason, Nov 30, 2021
  9. 09/12 reflog + refs-backend: move "verbose" out of the backendÆvar Arnfjörð Bjarmason, Nov 30, 2021
  10. 11/12 gc + reflog: emit progress output from "reflog expire --all"Ævar Arnfjörð Bjarmason, Nov 30, 2021
  11. 10/12 reflog expire: add progress output on --stale-fixÆvar Arnfjörð Bjarmason, Nov 30, 2021
  12. 08/12 refs files-backend: assume cb->newlog if !EXPIRE_REFLOGS_DRY_RUNÆvar Arnfjörð Bjarmason, Nov 30, 2021
  13. 12/12 gc + reflog: don't stall before initial "git gc" progress outputÆvar Arnfjörð Bjarmason, Nov 30, 2021
  14. 0/9 reftable prep: have builtin/reflog.c handle "--verbose"Ævar Arnfjörð Bjarmason, Dec 16, 2021
  15. 1/9 reflog delete: narrow scope of "cmd" passed to count_reflog_ent()Ævar Arnfjörð Bjarmason, Dec 16, 2021
  16. 2/9 reflog expire: narrow scope of "cb" in cmd_reflog_expire()Ævar Arnfjörð Bjarmason, Dec 16, 2021
  17. 3/9 reflog: change one->many worktree->refnames to use a string_listÆvar Arnfjörð Bjarmason, Dec 16, 2021
  18. 4/9 reflog expire: don't do negative comparison on enum valuesÆvar Arnfjörð Bjarmason, Dec 16, 2021
  19. 5/9 reflog expire: refactor & use "tip_commit" only for UE_NORMALÆvar Arnfjörð Bjarmason, Dec 16, 2021
  20. 7/9 reflog: reduce scope of "struct rev_info"Ævar Arnfjörð Bjarmason, Dec 16, 2021
  21. 6/9 reflog expire: don't use lookup_commit_reference_gently()Ævar Arnfjörð Bjarmason, Dec 16, 2021
  22. 8/9 refs files-backend: assume cb->newlog if !EXPIRE_REFLOGS_DRY_RUNÆvar Arnfjörð Bjarmason, Dec 16, 2021
  23. 9/9 reflog + refs-backend: move "verbose" out of the backendÆvar Arnfjörð Bjarmason, Dec 16, 2021
  24. Junio C HamanoDec 16, 2021
  25. Ævar Arnfjörð BjarmasonDec 16, 2021
  26. Han-Wen NienhuysDec 21, 2021
  27. Ævar Arnfjörð BjarmasonDec 21, 2021
  28. 0/9 reftable prep: have builtin/reflog.c handle "--verbose"Ævar Arnfjörð Bjarmason, Dec 22, 2021
  29. 1/9 reflog delete: narrow scope of "cmd" passed to count_reflog_ent()Ævar Arnfjörð Bjarmason, Dec 22, 2021
  30. 2/9 reflog expire: narrow scope of "cb" in cmd_reflog_expire()Ævar Arnfjörð Bjarmason, Dec 22, 2021
  31. 4/9 reflog expire: use "switch" over enum valuesÆvar Arnfjörð Bjarmason, Dec 22, 2021
  32. 3/9 reflog: change one->many worktree->refnames to use a string_listÆvar Arnfjörð Bjarmason, Dec 22, 2021
  33. 7/9 reflog: reduce scope of "struct rev_info"Ævar Arnfjörð Bjarmason, Dec 22, 2021
  34. 6/9 reflog expire: don't use lookup_commit_reference_gently()Ævar Arnfjörð Bjarmason, Dec 22, 2021
  35. 5/9 reflog expire: refactor & use "tip_commit" only for UE_NORMALÆvar Arnfjörð Bjarmason, Dec 22, 2021
  36. 8/9 refs files-backend: assume cb->newlog if !EXPIRE_REFLOGS_DRY_RUNÆvar Arnfjörð Bjarmason, Dec 22, 2021
  37. 9/9 reflog + refs-backend: move "verbose" out of the backendÆvar Arnfjörð Bjarmason, Dec 22, 2021

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.