Skip to content

Commit a95ce12

Browse files
derrickstoleegitster
authored andcommitted
maintenance: replace run_auto_gc()
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3ddaad0 commit a95ce12

File tree

10 files changed

+25
-23
lines changed

10 files changed

+25
-23
lines changed

Documentation/fetch-options.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,11 @@ ifndef::git-pull[]
9595
Allow several <repository> and <group> arguments to be
9696
specified. No <refspec>s may be specified.
9797

98+
--[no-]auto-maintenance::
9899
--[no-]auto-gc::
99-
Run `git gc --auto` at the end to perform garbage collection
100-
if needed. This is enabled by default.
100+
Run `git maintenance run --auto` at the end to perform automatic
101+
repository maintenance if needed. (`--[no-]auto-gc` is a synonym.)
102+
This is enabled by default.
101103

102104
--[no-]write-commit-graph::
103105
Write a commit-graph after fetching. This overrides the config

Documentation/git-clone.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ repository using this option and then delete branches (or use any
7878
other Git command that makes any existing commit unreferenced) in the
7979
source repository, some objects may become unreferenced (or dangling).
8080
These objects may be removed by normal Git operations (such as `git commit`)
81-
which automatically call `git gc --auto`. (See linkgit:git-gc[1].)
82-
If these objects are removed and were referenced by the cloned repository,
83-
then the cloned repository will become corrupt.
81+
which automatically call `git maintenance run --auto`. (See
82+
linkgit:git-maintenance[1].) If these objects are removed and were referenced
83+
by the cloned repository, then the cloned repository will become corrupt.
8484
+
8585
Note that running `git repack` without the `--local` option in a repository
8686
cloned with `--shared` will copy objects from the source repository into a pack

builtin/am.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1795,7 +1795,7 @@ static void am_run(struct am_state *state, int resume)
17951795
if (!state->rebasing) {
17961796
am_destroy(state);
17971797
close_object_store(the_repository->objects);
1798-
run_auto_gc(state->quiet);
1798+
run_auto_maintenance(state->quiet);
17991799
}
18001800
}
18011801

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
17021702
git_test_write_commit_graph_or_die();
17031703

17041704
repo_rerere(the_repository, 0);
1705-
run_auto_gc(quiet);
1705+
run_auto_maintenance(quiet);
17061706
run_commit_hook(use_editor, get_index_file(), "post-commit", NULL);
17071707
if (amend && !no_post_rewrite) {
17081708
commit_post_rewrite(the_repository, current_head, &oid);

builtin/fetch.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,10 @@ static struct option builtin_fetch_options[] = {
199199
OPT_STRING_LIST(0, "negotiation-tip", &negotiation_tip, N_("revision"),
200200
N_("report that we have only objects reachable from this object")),
201201
OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
202+
OPT_BOOL(0, "auto-maintenance", &enable_auto_gc,
203+
N_("run 'maintenance --auto' after fetching")),
202204
OPT_BOOL(0, "auto-gc", &enable_auto_gc,
203-
N_("run 'gc --auto' after fetching")),
205+
N_("run 'maintenance --auto' after fetching")),
204206
OPT_BOOL(0, "show-forced-updates", &fetch_show_forced_updates,
205207
N_("check for forced-updates on all updated branches")),
206208
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)
18911893
close_object_store(the_repository->objects);
18921894

18931895
if (enable_auto_gc)
1894-
run_auto_gc(verbosity < 0);
1896+
run_auto_maintenance(verbosity < 0);
18951897

18961898
return result;
18971899
}

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ static void finish(struct commit *head_commit,
456456
* user should see them.
457457
*/
458458
close_object_store(the_repository->objects);
459-
run_auto_gc(verbosity < 0);
459+
run_auto_maintenance(verbosity < 0);
460460
}
461461
}
462462
if (new_head && show_diffstat) {

builtin/rebase.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,10 +728,10 @@ static int finish_rebase(struct rebase_options *opts)
728728
apply_autostash(state_dir_path("autostash", opts));
729729
close_object_store(the_repository->objects);
730730
/*
731-
* We ignore errors in 'gc --auto', since the
731+
* We ignore errors in 'git maintenance run --auto', since the
732732
* user should see them.
733733
*/
734-
run_auto_gc(!(opts->flags & (REBASE_NO_QUIET|REBASE_VERBOSE)));
734+
run_auto_maintenance(!(opts->flags & (REBASE_NO_QUIET|REBASE_VERBOSE)));
735735
if (opts->type == REBASE_MERGE) {
736736
struct replay_opts replay = REPLAY_OPTS_INIT;
737737

run-command.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,15 +1866,13 @@ int run_processes_parallel_tr2(int n, get_next_task_fn get_next_task,
18661866
return result;
18671867
}
18681868

1869-
int run_auto_gc(int quiet)
1869+
int run_auto_maintenance(int quiet)
18701870
{
1871-
struct strvec argv_gc_auto = STRVEC_INIT;
1872-
int status;
1871+
struct child_process maint = CHILD_PROCESS_INIT;
18731872

1874-
strvec_pushl(&argv_gc_auto, "gc", "--auto", NULL);
1875-
if (quiet)
1876-
strvec_push(&argv_gc_auto, "--quiet");
1877-
status = run_command_v_opt(argv_gc_auto.v, RUN_GIT_CMD);
1878-
strvec_clear(&argv_gc_auto);
1879-
return status;
1873+
maint.git_cmd = 1;
1874+
strvec_pushl(&maint.args, "maintenance", "run", "--auto", NULL);
1875+
strvec_push(&maint.args, quiet ? "--quiet" : "--no-quiet");
1876+
1877+
return run_command(&maint);
18801878
}

run-command.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ int run_hook_ve(const char *const *env, const char *name, va_list args);
221221
/*
222222
* Trigger an auto-gc
223223
*/
224-
int run_auto_gc(int quiet);
224+
int run_auto_maintenance(int quiet);
225225

226226
#define RUN_COMMAND_NO_STDIN 1
227227
#define RUN_GIT_CMD 2 /*If this is to be git sub-command */

t/t5510-fetch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ test_expect_success 'fetching with auto-gc does not lock up' '
934934
git config fetch.unpackLimit 1 &&
935935
git config gc.autoPackLimit 1 &&
936936
git config gc.autoDetach false &&
937-
GIT_ASK_YESNO="$D/askyesno" git fetch >fetch.out 2>&1 &&
937+
GIT_ASK_YESNO="$D/askyesno" git fetch --verbose >fetch.out 2>&1 &&
938938
test_i18ngrep "Auto packing the repository" fetch.out &&
939939
! grep "Should I try again" fetch.out
940940
)

0 commit comments

Comments
 (0)