All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: Derrick Stolee <stolee@gmail.com>
Subject: [PATCH 14/15] builtin/gc: forward git-gc(1)'s `--auto` flag when packing refs
Date: Mon, 18 Mar 2024 11:53:28 +0100	[thread overview]
Message-ID: <474cf66b26f5e459dccd60a2dcd1a09eff86178c.1710706119.git.ps@pks.im> (raw)
In-Reply-To: <cover.1710706118.git.ps@pks.im>

[-- Attachment #1: Type: text/plain, Size: 6080 bytes --]

Forward the `--auto` flag to git-pack-refs(1) when it has been invoked
with this flag itself. This does not change anything for the "files"
backend, which will continue to eagerly pack refs. But it does ensure
that the "reftable" backend only compacts refs as required.

This change does not impact git-maintenance(1) as it won't ever end up
executing the pack-refs task when run with `--auto`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/gc.c               | 21 ++++++++++++---------
 t/t0610-reftable-basics.sh | 19 ++++++++++++++++---
 2 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/builtin/gc.c b/builtin/gc.c
index e0029c88f9..bf1f2a621a 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -212,6 +212,9 @@ static int maintenance_task_pack_refs(MAYBE_UNUSED struct maintenance_run_opts *
 
 	cmd.git_cmd = 1;
 	strvec_pushl(&cmd.args, "pack-refs", "--all", "--prune", NULL);
+	if (opts->auto_flag)
+		strvec_push(&cmd.args, "--auto");
+
 	return run_command(&cmd);
 }
 
@@ -572,7 +575,7 @@ static int report_last_gc_error(void)
 	return ret;
 }
 
-static void gc_before_repack(void)
+static void gc_before_repack(struct maintenance_run_opts *opts)
 {
 	/*
 	 * We may be called twice, as both the pre- and
@@ -583,7 +586,7 @@ static void gc_before_repack(void)
 	if (done++)
 		return;
 
-	if (pack_refs && maintenance_task_pack_refs(NULL))
+	if (pack_refs && maintenance_task_pack_refs(opts))
 		die(FAILED_RUN, "pack-refs");
 
 	if (prune_reflogs) {
@@ -599,7 +602,6 @@ static void gc_before_repack(void)
 int cmd_gc(int argc, const char **argv, const char *prefix)
 {
 	int aggressive = 0;
-	int auto_gc = 0;
 	int quiet = 0;
 	int force = 0;
 	const char *name;
@@ -608,6 +610,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
 	int keep_largest_pack = -1;
 	timestamp_t dummy;
 	struct child_process rerere_cmd = CHILD_PROCESS_INIT;
+	struct maintenance_run_opts opts = {0};
 
 	struct option builtin_gc_options[] = {
 		OPT__QUIET(&quiet, N_("suppress progress reporting")),
@@ -618,7 +621,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
 		OPT_MAGNITUDE(0, "max-cruft-size", &max_cruft_size,
 			      N_("with --cruft, limit the size of new cruft packs")),
 		OPT_BOOL(0, "aggressive", &aggressive, N_("be more thorough (increased runtime)")),
-		OPT_BOOL_F(0, "auto", &auto_gc, N_("enable auto-gc mode"),
+		OPT_BOOL_F(0, "auto", &opts.auto_flag, N_("enable auto-gc mode"),
 			   PARSE_OPT_NOCOMPLETE),
 		OPT_BOOL_F(0, "force", &force,
 			   N_("force running gc even if there may be another gc running"),
@@ -663,7 +666,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
 	if (quiet)
 		strvec_push(&repack, "-q");
 
-	if (auto_gc) {
+	if (opts.auto_flag) {
 		/*
 		 * Auto-gc should be least intrusive as possible.
 		 */
@@ -688,7 +691,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
 
 			if (lock_repo_for_gc(force, &pid))
 				return 0;
-			gc_before_repack(); /* dies on failure */
+			gc_before_repack(&opts); /* dies on failure */
 			delete_tempfile(&pidfile);
 
 			/*
@@ -713,7 +716,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
 
 	name = lock_repo_for_gc(force, &pid);
 	if (name) {
-		if (auto_gc)
+		if (opts.auto_flag)
 			return 0; /* be quiet on --auto */
 		die(_("gc is already running on machine '%s' pid %"PRIuMAX" (use --force if not)"),
 		    name, (uintmax_t)pid);
@@ -728,7 +731,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
 		atexit(process_log_file_at_exit);
 	}
 
-	gc_before_repack();
+	gc_before_repack(&opts);
 
 	if (!repository_format_precious_objects) {
 		struct child_process repack_cmd = CHILD_PROCESS_INIT;
@@ -783,7 +786,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
 					     !quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0,
 					     NULL);
 
-	if (auto_gc && too_many_loose_objects())
+	if (opts.auto_flag && too_many_loose_objects())
 		warning(_("There are too many unreachable loose objects; "
 			"run 'git prune' to remove them."));
 
diff --git a/t/t0610-reftable-basics.sh b/t/t0610-reftable-basics.sh
index 6de7529575..b37d8bf3b1 100755
--- a/t/t0610-reftable-basics.sh
+++ b/t/t0610-reftable-basics.sh
@@ -387,7 +387,9 @@ test_expect_success 'pack-refs: compaction raises locking errors' '
 	test_cmp expect err
 '
 
-test_expect_success 'pack-refs: auto compaction' '
+for command in pack-refs gc
+do
+test_expect_success "$command: auto compaction" '
 	test_when_finished "rm -rf repo" &&
 	git init repo &&
 	(
@@ -395,14 +397,24 @@ test_expect_success 'pack-refs: auto compaction' '
 
 		test_commit A &&
 
+		# We need a bit of setup to ensure that git-gc(1) actually
+		# triggers, and that it does not write anything to the refdb.
+		git config gc.auto 1 &&
+		git config gc.autoDetach 0 &&
+		git config gc.reflogExpire never &&
+		git config gc.reflogExpireUnreachable never &&
+		test_oid blob17_1 | git hash-object -w --stdin &&
+
 		# The tables should have been auto-compacted, and thus auto
 		# compaction should not have to do anything.
 		ls -1 .git/reftable >tables-expect &&
 		test_line_count = 4 tables-expect &&
-		git pack-refs --auto &&
+		git $command --auto &&
 		ls -1 .git/reftable >tables-actual &&
 		test_cmp tables-expect tables-actual &&
 
+		test_oid blob17_2 | git hash-object -w --stdin &&
+
 		# Lock all tables write some refs. Auto-compaction will be
 		# unable to compact tables and thus fails gracefully, leaving
 		# the stack in a sub-optimal state.
@@ -416,10 +428,11 @@ test_expect_success 'pack-refs: auto compaction' '
 		rm .git/reftable/*.lock &&
 		test_line_count = 5 .git/reftable/tables.list &&
 
-		git pack-refs --auto &&
+		git $command --auto &&
 		test_line_count = 1 .git/reftable/tables.list
 	)
 '
+done
 
 test_expect_success 'pack-refs: prunes stale tables' '
 	test_when_finished "rm -rf repo" &&
-- 
2.44.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2024-03-18 10:53 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-18 10:52 [PATCH 00/15] refs: introduce `--auto` to pack refs as needed Patrick Steinhardt
2024-03-18 10:52 ` [PATCH 01/15] reftable/stack: fix error handling in `reftable_stack_init_addition()` Patrick Steinhardt
2024-03-20 21:50   ` Karthik Nayak
2024-03-25  9:10     ` Patrick Steinhardt
2024-03-18 10:52 ` [PATCH 02/15] reftable/error: discern locked/outdated errors Patrick Steinhardt
2024-03-18 10:52 ` [PATCH 03/15] reftable/stack: use error codes when locking fails during compaction Patrick Steinhardt
2024-03-20 22:14   ` Karthik Nayak
2024-03-25  9:10     ` Patrick Steinhardt
2024-03-18 10:52 ` [PATCH 04/15] reftable/stack: gracefully handle failed auto-compaction due to locks Patrick Steinhardt
2024-03-20 22:22   ` Karthik Nayak
2024-03-25  9:10     ` Patrick Steinhardt
2024-03-18 10:52 ` [PATCH 05/15] refs/reftable: print errors on compaction failure Patrick Steinhardt
2024-03-18 10:52 ` [PATCH 06/15] t/helper: drop pack-refs wrapper Patrick Steinhardt
2024-03-18 10:52 ` [PATCH 07/15] refs: move `struct pack_refs_opts` to where it's used Patrick Steinhardt
2024-03-18 10:52 ` [PATCH 08/15] refs: remove `PACK_REFS_ALL` flag Patrick Steinhardt
2024-03-18 10:53 ` [PATCH 09/15] refs/reftable: expose auto compaction via new flag Patrick Steinhardt
2024-03-18 10:53 ` [PATCH 10/15] builtin/pack-refs: release allocated memory Patrick Steinhardt
2024-03-20 23:23   ` Karthik Nayak
2024-03-25  9:10     ` Patrick Steinhardt
2024-03-18 10:53 ` [PATCH 11/15] builtin/pack-refs: introduce new "--auto" flag Patrick Steinhardt
2024-03-18 10:53 ` [PATCH 12/15] builtin/gc: move `struct maintenance_run_opts` Patrick Steinhardt
2024-03-18 10:53 ` [PATCH 13/15] t6500: extract objects with "17" prefix Patrick Steinhardt
2024-03-18 10:53 ` Patrick Steinhardt [this message]
2024-03-20 23:56   ` [PATCH 14/15] builtin/gc: forward git-gc(1)'s `--auto` flag when packing refs Karthik Nayak
2024-03-25  9:10     ` Patrick Steinhardt
2024-03-18 10:53 ` [PATCH 15/15] builtin/gc: pack refs when using `git maintenance run --auto` Patrick Steinhardt
2024-03-20 23:59   ` Karthik Nayak
2024-03-25  9:10     ` Patrick Steinhardt
2024-03-20 19:30 ` [PATCH 00/15] refs: introduce `--auto` to pack refs as needed Karthik Nayak
2024-03-25  9:10   ` Patrick Steinhardt
2024-03-25 10:02 ` [PATCH v2 " Patrick Steinhardt
2024-03-25 10:02   ` [PATCH v2 01/15] reftable/stack: fix error handling in `reftable_stack_init_addition()` Patrick Steinhardt
2024-03-25 10:02   ` [PATCH v2 02/15] reftable/error: discern locked/outdated errors Patrick Steinhardt
2024-03-25 10:02   ` [PATCH v2 03/15] reftable/stack: use error codes when locking fails during compaction Patrick Steinhardt
2024-03-25 10:02   ` [PATCH v2 04/15] reftable/stack: gracefully handle failed auto-compaction due to locks Patrick Steinhardt
2024-03-25 11:22     ` Patrick Steinhardt
2024-03-25 10:02   ` [PATCH v2 05/15] refs/reftable: print errors on compaction failure Patrick Steinhardt
2024-03-25 10:02   ` [PATCH v2 06/15] t/helper: drop pack-refs wrapper Patrick Steinhardt
2024-03-25 10:03   ` [PATCH v2 07/15] refs: move `struct pack_refs_opts` to where it's used Patrick Steinhardt
2024-03-25 10:03   ` [PATCH v2 08/15] refs: remove `PACK_REFS_ALL` flag Patrick Steinhardt
2024-03-25 10:03   ` [PATCH v2 09/15] refs/reftable: expose auto compaction via new flag Patrick Steinhardt
2024-03-25 10:03   ` [PATCH v2 10/15] builtin/pack-refs: release allocated memory Patrick Steinhardt
2024-03-25 10:03   ` [PATCH v2 11/15] builtin/pack-refs: introduce new "--auto" flag Patrick Steinhardt
2024-03-25 10:03   ` [PATCH v2 12/15] builtin/gc: move `struct maintenance_run_opts` Patrick Steinhardt
2024-03-25 10:03   ` [PATCH v2 13/15] t6500: extract objects with "17" prefix Patrick Steinhardt
2024-03-25 10:03   ` [PATCH v2 14/15] builtin/gc: forward git-gc(1)'s `--auto` flag when packing refs Patrick Steinhardt
2024-03-25 10:03   ` [PATCH v2 15/15] builtin/gc: pack refs when using `git maintenance run --auto` Patrick Steinhardt
2024-03-25 11:23   ` [PATCH v2 00/15] refs: introduce `--auto` to pack refs as needed Karthik Nayak
2024-03-25 16:56     ` Junio C Hamano

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

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

  git send-email \
    --in-reply-to=474cf66b26f5e459dccd60a2dcd1a09eff86178c.1710706119.git.ps@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=stolee@gmail.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.