git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Han-Wen Nienhuys" <hanwen@google.com>,
	"Bagas Sanjaya" <bagasdotme@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 11/12] gc + reflog: emit progress output from "reflog expire --all"
Date: Tue, 30 Nov 2021 22:38:13 +0100	[thread overview]
Message-ID: <patch-11.12-794e6e677a8-20211130T213319Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-00.12-00000000000-20211130T213319Z-avarab@gmail.com>

Emit progress output on "git reflog expire --all", which is what "git
gc" runs. On my git.git checkout I'll now get:

    $ time GIT_PROGRESS_DELAY=0 ~/g/git/git reflog expire --all --dry-run
    Enumerating reflogs: 23782, done.
    Expiring reflogs: 100% (23782/23782), done.

    real    0m3.264s
    user    0m2.308s
    sys     0m0.941s

The "Enumerating reflogs" is too fast to appear for me except with
GIT_PROGRESS_DELAY=0. We'll also emit this at the top of "git gc"
output:

    $ ~/g/git/git --exec-path=$PWD gc
    Expiring reflogs: 100% (23782/23782), done.
    Enumerating objects: [...]

This goes a long way (but not quite, a subsequent commit will) to
addressing the seeming halting of "git gc" on startup. That usually
happens because of the "HEAD" case in "reflog expire --all" and
unreachable().

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).

This is because "git gc" even with "--auto" won't detach until after
it runs "git reflog -expire", so whatever output we emit will never
end up in the gc.log. We should still obey its --quiet to mean our
--no-progress, but we don't need a special-case for "daemonized" as
write_commit_graph_reachable() does.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 builtin/gc.c     |  4 +++-
 builtin/reflog.c | 19 ++++++++++++++++++-
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/builtin/gc.c b/builtin/gc.c
index bcef6a4c8da..872209e083e 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -593,8 +593,10 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
 		if (aggressive_window > 0)
 			strvec_pushf(&repack, "--window=%d", aggressive_window);
 	}
-	if (quiet)
+	if (quiet) {
+		strvec_push(&reflog, "--no-progress");
 		strvec_push(&repack, "-q");
+	}
 
 	if (auto_gc) {
 		/*
diff --git a/builtin/reflog.c b/builtin/reflog.c
index cf0ef68d82d..1a2a210ecf1 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -53,6 +53,7 @@ struct expire_reflog_policy_cb {
 struct worktree_reflogs {
 	struct worktree *worktree;
 	struct string_list reflogs;
+	struct progress *progress;
 };
 
 /* Remember to update object flag allocation in object.h */
@@ -324,7 +325,7 @@ static int should_expire_reflog_ent(struct object_id *ooid, struct object_id *no
 
 	return 0;
 expire:
-	if (cb->dry_run)
+	if (cb->verbose && cb->dry_run)
 		printf("would prune %s", message);
 	else if (cb->verbose)
 		printf("prune %s", message);
@@ -426,6 +427,7 @@ static int collect_reflog(const char *ref, const struct object_id *oid, int unus
 	if (!worktree->is_current && ref_type(ref) == REF_TYPE_NORMAL)
 		return 0;
 
+	display_progress(cb->progress, cb->reflogs.nr + 1);
 	strbuf_worktree_ref(worktree, &newref, ref);
 	string_list_append(&cb->reflogs, strbuf_detach(&newref, NULL));
 
@@ -627,11 +629,17 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
 	}
 
 	if (do_all) {
+		struct progress *progress = NULL;
 		struct worktree_reflogs collected = {
 			.reflogs = STRING_LIST_INIT_NODUP,
 		};
 		struct string_list_item *item;
 		struct worktree **worktrees, **p;
+		uint64_t progress_cnt;
+
+		if (show_progress)
+			collected.progress = start_delayed_progress(_("Enumerating reflogs"),
+								    0);
 
 		worktrees = get_worktrees();
 		for (p = worktrees; *p; p++) {
@@ -642,6 +650,13 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
 					     collect_reflog, &collected);
 		}
 		free_worktrees(worktrees);
+		stop_progress(&collected.progress);
+
+		if (show_progress) {
+			progress_cnt = 0;
+			progress = start_delayed_progress(_("Expiring reflogs"),
+							  collected.reflogs.nr);
+		}
 
 		for_each_string_list_item(item, &collected.reflogs) {
 			struct expire_reflog_policy_cb cb = {
@@ -650,6 +665,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
 				.verbose = verbose,
 			};
 
+			display_progress(progress, ++progress_cnt);
 			set_reflog_expiry_param(&cb.cmd, explicit_expiry, item->string);
 			status |= reflog_expire(item->string, flags,
 						reflog_expiry_prepare,
@@ -657,6 +673,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
 						reflog_expiry_cleanup,
 						&cb);
 		}
+		stop_progress(&progress);
 		collected.reflogs.strdup_strings = 1;
 		string_list_clear(&collected.reflogs, 0);
 	}
-- 
2.34.1.877.g7d5b0a3b8a6


  parent reply	other threads:[~2021-11-30 21:38 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-30 21:38 [PATCH 00/12] reflog + gc: refactor, progress output, reftable-readyness Ævar Arnfjörð Bjarmason
2021-11-30 21:38 ` [PATCH 01/12] reflog delete: narrow scope of "cmd" passed to count_reflog_ent() Ævar Arnfjörð Bjarmason
2021-11-30 21:38 ` [PATCH 02/12] reflog expire: narrow scope of "cb" in cmd_reflog_expire() Ævar Arnfjörð Bjarmason
2021-11-30 21:38 ` [PATCH 03/12] reflog: change one->many worktree->refnames to use a string_list Ævar Arnfjörð Bjarmason
2021-11-30 21:38 ` [PATCH 04/12] reflog expire: don't do negative comparison on enum values Ævar Arnfjörð Bjarmason
2021-11-30 21:38 ` [PATCH 05/12] reflog expire: refactor & use "tip_commit" only for UE_NORMAL Ævar Arnfjörð Bjarmason
2021-11-30 21:38 ` [PATCH 06/12] reflog expire: don't use lookup_commit_reference_gently() Ævar Arnfjörð Bjarmason
2021-11-30 21:38 ` [PATCH 07/12] reflog: reduce scope of "struct rev_info" Ævar Arnfjörð Bjarmason
2021-11-30 21:38 ` [PATCH 08/12] refs files-backend: assume cb->newlog if !EXPIRE_REFLOGS_DRY_RUN Ævar Arnfjörð Bjarmason
2021-11-30 21:38 ` [PATCH 09/12] reflog + refs-backend: move "verbose" out of the backend Ævar Arnfjörð Bjarmason
2021-11-30 21:38 ` [PATCH 10/12] reflog expire: add progress output on --stale-fix Ævar Arnfjörð Bjarmason
2021-11-30 21:38 ` Ævar Arnfjörð Bjarmason [this message]
2021-11-30 21:38 ` [PATCH 12/12] gc + reflog: don't stall before initial "git gc" progress output Ævar Arnfjörð Bjarmason
2021-12-16 13:45 ` [PATCH v2 0/9] reftable prep: have builtin/reflog.c handle "--verbose" Ævar Arnfjörð Bjarmason
2021-12-16 13:45   ` [PATCH v2 1/9] reflog delete: narrow scope of "cmd" passed to count_reflog_ent() Ævar Arnfjörð Bjarmason
2021-12-16 13:45   ` [PATCH v2 2/9] reflog expire: narrow scope of "cb" in cmd_reflog_expire() Ævar Arnfjörð Bjarmason
2021-12-16 13:45   ` [PATCH v2 3/9] reflog: change one->many worktree->refnames to use a string_list Ævar Arnfjörð Bjarmason
2021-12-16 13:45   ` [PATCH v2 4/9] reflog expire: don't do negative comparison on enum values Ævar Arnfjörð Bjarmason
2021-12-16 13:45   ` [PATCH v2 5/9] reflog expire: refactor & use "tip_commit" only for UE_NORMAL Ævar Arnfjörð Bjarmason
2021-12-16 13:45   ` [PATCH v2 6/9] reflog expire: don't use lookup_commit_reference_gently() Ævar Arnfjörð Bjarmason
2021-12-16 13:45   ` [PATCH v2 7/9] reflog: reduce scope of "struct rev_info" Ævar Arnfjörð Bjarmason
2021-12-16 13:45   ` [PATCH v2 8/9] refs files-backend: assume cb->newlog if !EXPIRE_REFLOGS_DRY_RUN Ævar Arnfjörð Bjarmason
2021-12-16 13:45   ` [PATCH v2 9/9] reflog + refs-backend: move "verbose" out of the backend Ævar Arnfjörð Bjarmason
2021-12-16 22:27   ` [PATCH v2 0/9] reftable prep: have builtin/reflog.c handle "--verbose" Junio C Hamano
2021-12-16 23:31     ` Ævar Arnfjörð Bjarmason
2021-12-21 14:24   ` Han-Wen Nienhuys
2021-12-21 15:21     ` Ævar Arnfjörð Bjarmason
2021-12-22  4:06   ` [PATCH v3 " Ævar Arnfjörð Bjarmason
2021-12-22  4:06     ` [PATCH v3 1/9] reflog delete: narrow scope of "cmd" passed to count_reflog_ent() Ævar Arnfjörð Bjarmason
2021-12-22  4:06     ` [PATCH v3 2/9] reflog expire: narrow scope of "cb" in cmd_reflog_expire() Ævar Arnfjörð Bjarmason
2021-12-22  4:06     ` [PATCH v3 3/9] reflog: change one->many worktree->refnames to use a string_list Ævar Arnfjörð Bjarmason
2021-12-22  4:06     ` [PATCH v3 4/9] reflog expire: use "switch" over enum values Ævar Arnfjörð Bjarmason
2021-12-22  4:06     ` [PATCH v3 5/9] reflog expire: refactor & use "tip_commit" only for UE_NORMAL Ævar Arnfjörð Bjarmason
2021-12-22  4:06     ` [PATCH v3 6/9] reflog expire: don't use lookup_commit_reference_gently() Ævar Arnfjörð Bjarmason
2021-12-22  4:06     ` [PATCH v3 7/9] reflog: reduce scope of "struct rev_info" Ævar Arnfjörð Bjarmason
2021-12-22  4:06     ` [PATCH v3 8/9] refs files-backend: assume cb->newlog if !EXPIRE_REFLOGS_DRY_RUN Ævar Arnfjörð Bjarmason
2021-12-22  4:06     ` [PATCH v3 9/9] reflog + refs-backend: move "verbose" out of the backend Ævar Arnfjörð Bjarmason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=patch-11.12-794e6e677a8-20211130T213319Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=bagasdotme@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=hanwen@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).