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

[PATCH v5 03/11] maintenance: replace run_auto_gc()

From
Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
Date
Sep 17, 2020, 18:11 UTC
Message-ID
<3cbdeeafb56d0cddabbcef7d9ac301704e2616e6.1600366313.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.695.v5.git.1600366313.gitgitgadget@gmail.com>
From: Derrick Stolee <dstolee@microsoft.com>

The run_auto_gc() method is used in several places to trigger a check for repo maintenance after some Git commands, such as 'git commit' or 'git fetch'.

To allow for extra customization of this maintenance activity, replace the 'git gc --auto [--quiet]' call with one to 'git maintenance run --auto [--quiet]'. As we extend the maintenance builtin with other steps, users will be able to select different maintenance activities.

Rename run_auto_gc() to run_auto_maintenance() to be clearer what is happening on this call, and to expose all callers in the current diff. Rewrite the method to use a struct child_process to simplify the calls slightly.

Since 'git fetch' already allows disabling the 'git gc --auto' subprocess, add an equivalent option with a different name to be more descriptive of the new behavior: '--[no-]maintenance'. Update the documentation to include these options at the same time.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/fetch-options.txt |  6 ++++--
 Documentation/git-clone.txt     |  6 +++---
 builtin/am.c                    |  2 +-
 builtin/commit.c                |  2 +-
 builtin/fetch.c                 |  6 ++++--
 builtin/merge.c                 |  2 +-
 builtin/rebase.c                |  4 ++--
 run-command.c                   | 16 +++++++---------
 run-command.h                   |  2 +-
 t/t5510-fetch.sh                |  2 +-
 10 files changed, 25 insertions(+), 23 deletions(-)
diff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt
index 07d06ff445..b65a758661 100644
--- a/Documentation/fetch-options.txt
+++ b/Documentation/fetch-options.txt
@@ -95,9 +95,11 @@ ifndef::git-pull[]
 	Allow several <repository> and <group> arguments to be
 	specified. No <refspec>s may be specified.
 
+--[no-]auto-maintenance::
 --[no-]auto-gc::
-	Run `git gc --auto` at the end to perform garbage collection
-	if needed. This is enabled by default.
+	Run `git maintenance run --auto` at the end to perform automatic
+	repository maintenance if needed. (`--[no-]auto-gc` is a synonym.)
+	This is enabled by default.
 
 --[no-]write-commit-graph::
 	Write a commit-graph after fetching. This overrides the config
diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt
index c898310099..097e6a86c5 100644
--- a/Documentation/git-clone.txt
+++ b/Documentation/git-clone.txt
@@ -78,9 +78,9 @@ repository using this option and then delete branches (or use any
 other Git command that makes any existing commit unreferenced) in the
 source repository, some objects may become unreferenced (or dangling).
 These objects may be removed by normal Git operations (such as `git commit`)
-which automatically call `git gc --auto`. (See linkgit:git-gc[1].)
-If these objects are removed and were referenced by the cloned repository,
-then the cloned repository will become corrupt.
+which automatically call `git maintenance run --auto`. (See
+linkgit:git-maintenance[1].) If these objects are removed and were referenced
+by the cloned repository, then the cloned repository will become corrupt.
 +
 Note that running `git repack` without the `--local` option in a repository
 cloned with `--shared` will copy objects from the source repository into a pack
diff --git a/builtin/am.c b/builtin/am.c
index dd4e6c2d9b..68e9d17379 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1795,7 +1795,7 @@ static void am_run(struct am_state *state, int resume)
 	if (!state->rebasing) {
 		am_destroy(state);
 		close_object_store(the_repository->objects);
-		run_auto_gc(state->quiet);
+		run_auto_maintenance(state->quiet);
 	}
 }
 
diff --git a/builtin/commit.c b/builtin/commit.c
index 69ac78d5e5..f9b0a0c05d 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1702,7 +1702,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 	git_test_write_commit_graph_or_die();
 
 	repo_rerere(the_repository, 0);
-	run_auto_gc(quiet);
+	run_auto_maintenance(quiet);
 	run_commit_hook(use_editor, get_index_file(), "post-commit", NULL);
 	if (amend && !no_post_rewrite) {
 		commit_post_rewrite(the_repository, current_head, &oid);
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 2eb8d6a5a5..cb38e6f5ec 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -199,8 +199,10 @@ static struct option builtin_fetch_options[] = {
 	OPT_STRING_LIST(0, "negotiation-tip", &negotiation_tip, N_("revision"),
 			N_("report that we have only objects reachable from this object")),
 	OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
+	OPT_BOOL(0, "auto-maintenance", &enable_auto_gc,
+		 N_("run 'maintenance --auto' after fetching")),
 	OPT_BOOL(0, "auto-gc", &enable_auto_gc,
-		 N_("run 'gc --auto' after fetching")),
+		 N_("run 'maintenance --auto' after fetching")),
 	OPT_BOOL(0, "show-forced-updates", &fetch_show_forced_updates,
 		 N_("check for forced-updates on all updated branches")),
 	OPT_BOOL(0, "write-commit-graph", &fetch_write_commit_graph,
@@ -1891,7 +1893,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
 	close_object_store(the_repository->objects);
 
 	if (enable_auto_gc)
-		run_auto_gc(verbosity < 0);
+		run_auto_maintenance(verbosity < 0);
 
 	return result;
 }
diff --git a/builtin/merge.c b/builtin/merge.c
index 74829a838e..8f31bfab56 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -456,7 +456,7 @@ static void finish(struct commit *head_commit,
 			 * user should see them.
 			 */
 			close_object_store(the_repository->objects);
-			run_auto_gc(verbosity < 0);
+			run_auto_maintenance(verbosity < 0);
 		}
 	}
 	if (new_head && show_diffstat) {
diff --git a/builtin/rebase.c b/builtin/rebase.c
index dadb52fa92..9ffba9009d 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -728,10 +728,10 @@ static int finish_rebase(struct rebase_options *opts)
 	apply_autostash(state_dir_path("autostash", opts));
 	close_object_store(the_repository->objects);
 	/*
-	 * We ignore errors in 'gc --auto', since the
+	 * We ignore errors in 'git maintenance run --auto', since the
 	 * user should see them.
 	 */
-	run_auto_gc(!(opts->flags & (REBASE_NO_QUIET|REBASE_VERBOSE)));
+	run_auto_maintenance(!(opts->flags & (REBASE_NO_QUIET|REBASE_VERBOSE)));
 	if (opts->type == REBASE_MERGE) {
 		struct replay_opts replay = REPLAY_OPTS_INIT;
 
diff --git a/run-command.c b/run-command.c
index cc9c3296ba..2ee59acdc8 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1866,15 +1866,13 @@ int run_processes_parallel_tr2(int n, get_next_task_fn get_next_task,
 	return result;
 }
 
-int run_auto_gc(int quiet)
+int run_auto_maintenance(int quiet)
 {
-	struct strvec argv_gc_auto = STRVEC_INIT;
-	int status;
+	struct child_process maint = CHILD_PROCESS_INIT;
 
-	strvec_pushl(&argv_gc_auto, "gc", "--auto", NULL);
-	if (quiet)
-		strvec_push(&argv_gc_auto, "--quiet");
-	status = run_command_v_opt(argv_gc_auto.v, RUN_GIT_CMD);
-	strvec_clear(&argv_gc_auto);
-	return status;
+	maint.git_cmd = 1;
+	strvec_pushl(&maint.args, "maintenance", "run", "--auto", NULL);
+	strvec_push(&maint.args, quiet ? "--quiet" : "--no-quiet");
+
+	return run_command(&maint);
 }
diff --git a/run-command.h b/run-command.h
index 8b9bfaef16..6472b38bde 100644
--- a/run-command.h
+++ b/run-command.h
@@ -221,7 +221,7 @@ int run_hook_ve(const char *const *env, const char *name, va_list args);
 /*
  * Trigger an auto-gc
  */
-int run_auto_gc(int quiet);
+int run_auto_maintenance(int quiet);
 
 #define RUN_COMMAND_NO_STDIN 1
 #define RUN_GIT_CMD	     2	/*If this is to be git sub-command */
diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
index 2a1abe91f0..a9682c5669 100755
--- a/t/t5510-fetch.sh
+++ b/t/t5510-fetch.sh
@@ -934,7 +934,7 @@ test_expect_success 'fetching with auto-gc does not lock up' '
 		git config fetch.unpackLimit 1 &&
 		git config gc.autoPackLimit 1 &&
 		git config gc.autoDetach false &&
-		GIT_ASK_YESNO="$D/askyesno" git fetch >fetch.out 2>&1 &&
+		GIT_ASK_YESNO="$D/askyesno" git fetch --verbose >fetch.out 2>&1 &&
 		test_i18ngrep "Auto packing the repository" fetch.out &&
 		! grep "Should I try again" fetch.out
 	)
-- 
gitgitgadget
Previous: Derrick Stolee via GitGitGadgetNext: Derrick Stolee via GitGitGadget
Message 82 of 91 in “Maintenance I: Command, gc and commit-graph tasks”
  1. 00/11 Maintenance I: Command, gc and commit-graph tasksDerrick Stolee via GitGitGadget, Aug 6, 2020
  2. 06/11 maintenance: add --task optionDerrick Stolee via GitGitGadget, Aug 6, 2020
  3. 08/11 maintenance: create maintenance.<task>.enabled configDerrick Stolee via GitGitGadget, Aug 6, 2020
  4. 05/11 maintenance: add commit-graph taskDerrick Stolee via GitGitGadget, Aug 6, 2020
  5. Martin ÅgrenAug 7, 2020
  6. Derrick StoleeAug 12, 2020
  7. Martin ÅgrenAug 14, 2020
  8. 04/11 maintenance: initialize task arrayDerrick Stolee via GitGitGadget, Aug 6, 2020
  9. 10/11 maintenance: add auto condition for commit-graph taskDerrick Stolee via GitGitGadget, Aug 6, 2020
  10. 11/11 maintenance: add trace2 regions for task executionDerrick Stolee via GitGitGadget, Aug 6, 2020
  11. 02/11 maintenance: add --quiet optionDerrick Stolee via GitGitGadget, Aug 6, 2020
  12. 01/11 maintenance: create basic maintenance runnerDerrick Stolee via GitGitGadget, Aug 6, 2020
  13. Martin ÅgrenAug 7, 2020
  14. Jonathan NiederAug 12, 2020
  15. Junio C HamanoAug 12, 2020
  16. Jonathan NiederAug 12, 2020
  17. Derrick StoleeAug 14, 2020
  18. 03/11 maintenance: replace run_auto_gc()Derrick Stolee via GitGitGadget, Aug 6, 2020
  19. 07/11 maintenance: take a lock on the objects directoryDerrick Stolee via GitGitGadget, Aug 6, 2020
  20. 09/11 maintenance: use pointers to check --autoDerrick Stolee via GitGitGadget, Aug 6, 2020
  21. 00/11 Maintenance I: Command, gc and commit-graph tasksDerrick Stolee via GitGitGadget, Aug 18, 2020
  22. 02/11 maintenance: add --quiet optionDerrick Stolee via GitGitGadget, Aug 18, 2020
  23. 01/11 maintenance: create basic maintenance runnerDerrick Stolee via GitGitGadget, Aug 18, 2020
  24. 03/11 maintenance: replace run_auto_gc()Derrick Stolee via GitGitGadget, Aug 18, 2020
  25. 04/11 maintenance: initialize task arrayDerrick Stolee via GitGitGadget, Aug 18, 2020
  26. Jonathan TanAug 18, 2020
  27. 06/11 maintenance: add --task optionDerrick Stolee via GitGitGadget, Aug 18, 2020
  28. Jonathan TanAug 19, 2020
  29. Junio C HamanoAug 19, 2020
  30. Derrick StoleeAug 19, 2020
  31. Jonathan TanAug 19, 2020
  32. 05/11 maintenance: add commit-graph taskDerrick Stolee via GitGitGadget, Aug 18, 2020
  33. Jonathan TanAug 18, 2020
  34. Derrick StoleeAug 19, 2020
  35. Jonathan TanAug 19, 2020
  36. 08/11 maintenance: create maintenance.<task>.enabled configDerrick Stolee via GitGitGadget, Aug 18, 2020
  37. 10/11 maintenance: add auto condition for commit-graph taskDerrick Stolee via GitGitGadget, Aug 18, 2020
  38. Jonathan TanAug 19, 2020
  39. Derrick StoleeAug 19, 2020
  40. 11/11 maintenance: add trace2 regions for task executionDerrick Stolee via GitGitGadget, Aug 18, 2020
  41. Jonathan TanAug 19, 2020
  42. 09/11 maintenance: use pointers to check --autoDerrick Stolee via GitGitGadget, Aug 18, 2020
  43. 07/11 maintenance: take a lock on the objects directoryDerrick Stolee via GitGitGadget, Aug 18, 2020
  44. Jonathan TanAug 19, 2020
  45. Derrick StoleeAug 19, 2020
  46. Junio C HamanoAug 18, 2020
  47. Derrick StoleeAug 19, 2020
  48. 00/11 Maintenance I: Command, gc and commit-graph tasksDerrick Stolee via GitGitGadget, Aug 25, 2020
  49. 01/11 maintenance: create basic maintenance runnerDerrick Stolee via GitGitGadget, Aug 25, 2020
  50. 03/11 maintenance: replace run_auto_gc()Derrick Stolee via GitGitGadget, Aug 25, 2020
  51. 02/11 maintenance: add --quiet optionDerrick Stolee via GitGitGadget, Aug 25, 2020
  52. 04/11 maintenance: initialize task arrayDerrick Stolee via GitGitGadget, Aug 25, 2020
  53. 06/11 maintenance: add --task optionDerrick Stolee via GitGitGadget, Aug 25, 2020
  54. 05/11 maintenance: add commit-graph taskDerrick Stolee via GitGitGadget, Aug 25, 2020
  55. 07/11 maintenance: take a lock on the objects directoryDerrick Stolee via GitGitGadget, Aug 25, 2020
  56. Jonathan TanAug 26, 2020
  57. 08/11 maintenance: create maintenance.<task>.enabled configDerrick Stolee via GitGitGadget, Aug 25, 2020
  58. 10/11 maintenance: add auto condition for commit-graph taskDerrick Stolee via GitGitGadget, Aug 25, 2020
  59. Jonathan TanAug 26, 2020
  60. Junio C HamanoAug 26, 2020
  61. 11/11 maintenance: add trace2 regions for task executionDerrick Stolee via GitGitGadget, Aug 25, 2020
  62. 09/11 maintenance: use pointers to check --autoDerrick Stolee via GitGitGadget, Aug 25, 2020
  63. 00/11 Maintenance I: Command, gc and commit-graph tasksDerrick Stolee via GitGitGadget, Sep 4, 2020
  64. 04/11 maintenance: initialize task arrayDerrick Stolee via GitGitGadget, Sep 4, 2020
  65. 05/11 maintenance: add commit-graph taskDerrick Stolee via GitGitGadget, Sep 4, 2020
  66. 03/11 maintenance: replace run_auto_gc()Derrick Stolee via GitGitGadget, Sep 4, 2020
  67. 07/11 maintenance: take a lock on the objects directoryDerrick Stolee via GitGitGadget, Sep 4, 2020
  68. 11/11 maintenance: add trace2 regions for task executionDerrick Stolee via GitGitGadget, Sep 4, 2020
  69. 09/11 maintenance: use pointers to check --autoDerrick Stolee via GitGitGadget, Sep 4, 2020
  70. 10/11 maintenance: add auto condition for commit-graph taskDerrick Stolee via GitGitGadget, Sep 4, 2020
  71. 06/11 maintenance: add --task optionDerrick Stolee via GitGitGadget, Sep 4, 2020
  72. 08/11 maintenance: create maintenance.<task>.enabled configDerrick Stolee via GitGitGadget, Sep 4, 2020
  73. 01/11 maintenance: create basic maintenance runnerDerrick Stolee via GitGitGadget, Sep 4, 2020
  74. 02/11 maintenance: add --quiet optionDerrick Stolee via GitGitGadget, Sep 4, 2020
  75. 00/11 Maintenance I: Command, gc and commit-graph tasksDerrick Stolee via GitGitGadget, Sep 17, 2020
  76. 04/11 maintenance: initialize task arrayDerrick Stolee via GitGitGadget, Sep 17, 2020
  77. 05/11 maintenance: add commit-graph taskDerrick Stolee via GitGitGadget, Sep 17, 2020
  78. 06/11 maintenance: add --task optionDerrick Stolee via GitGitGadget, Sep 17, 2020
  79. 01/11 maintenance: create basic maintenance runnerDerrick Stolee via GitGitGadget, Sep 17, 2020
  80. 10/11 maintenance: add auto condition for commit-graph taskDerrick Stolee via GitGitGadget, Sep 17, 2020
  81. 11/11 maintenance: add trace2 regions for task executionDerrick Stolee via GitGitGadget, Sep 17, 2020
  82. 03/11 maintenance: replace run_auto_gc()Derrick Stolee via GitGitGadget, Sep 17, 2020
  83. 08/11 maintenance: create maintenance.<task>.enabled configDerrick Stolee via GitGitGadget, Sep 17, 2020
  84. 09/11 maintenance: use pointers to check --autoDerrick Stolee via GitGitGadget, Sep 17, 2020
  85. 07/11 maintenance: take a lock on the objects directoryDerrick Stolee via GitGitGadget, Sep 17, 2020
  86. Ævar Arnfjörð BjarmasonSep 21, 2020
  87. Derrick StoleeSep 21, 2020
  88. Junio C HamanoSep 21, 2020
  89. 02/11 maintenance: add --quiet optionDerrick Stolee via GitGitGadget, Sep 17, 2020
  90. Junio C HamanoSep 17, 2020
  91. Johannes SchindelinSep 18, 2020

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.