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 <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
3ddaad0e06
commit
a95ce12430
|
@ -95,9 +95,11 @@ ifndef::git-pull[]
|
||||||
Allow several <repository> and <group> arguments to be
|
Allow several <repository> and <group> arguments to be
|
||||||
specified. No <refspec>s may be specified.
|
specified. No <refspec>s may be specified.
|
||||||
|
|
||||||
|
--[no-]auto-maintenance::
|
||||||
--[no-]auto-gc::
|
--[no-]auto-gc::
|
||||||
Run `git gc --auto` at the end to perform garbage collection
|
Run `git maintenance run --auto` at the end to perform automatic
|
||||||
if needed. This is enabled by default.
|
repository maintenance if needed. (`--[no-]auto-gc` is a synonym.)
|
||||||
|
This is enabled by default.
|
||||||
|
|
||||||
--[no-]write-commit-graph::
|
--[no-]write-commit-graph::
|
||||||
Write a commit-graph after fetching. This overrides the config
|
Write a commit-graph after fetching. This overrides the config
|
||||||
|
|
|
@ -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
|
other Git command that makes any existing commit unreferenced) in the
|
||||||
source repository, some objects may become unreferenced (or dangling).
|
source repository, some objects may become unreferenced (or dangling).
|
||||||
These objects may be removed by normal Git operations (such as `git commit`)
|
These objects may be removed by normal Git operations (such as `git commit`)
|
||||||
which automatically call `git gc --auto`. (See linkgit:git-gc[1].)
|
which automatically call `git maintenance run --auto`. (See
|
||||||
If these objects are removed and were referenced by the cloned repository,
|
linkgit:git-maintenance[1].) If these objects are removed and were referenced
|
||||||
then the cloned repository will become corrupt.
|
by the cloned repository, then the cloned repository will become corrupt.
|
||||||
+
|
+
|
||||||
Note that running `git repack` without the `--local` option in a repository
|
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
|
cloned with `--shared` will copy objects from the source repository into a pack
|
||||||
|
|
|
@ -1795,7 +1795,7 @@ next:
|
||||||
if (!state->rebasing) {
|
if (!state->rebasing) {
|
||||||
am_destroy(state);
|
am_destroy(state);
|
||||||
close_object_store(the_repository->objects);
|
close_object_store(the_repository->objects);
|
||||||
run_auto_gc(state->quiet);
|
run_auto_maintenance(state->quiet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1702,7 +1702,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
|
||||||
git_test_write_commit_graph_or_die();
|
git_test_write_commit_graph_or_die();
|
||||||
|
|
||||||
repo_rerere(the_repository, 0);
|
repo_rerere(the_repository, 0);
|
||||||
run_auto_gc(quiet);
|
run_auto_maintenance(quiet);
|
||||||
run_commit_hook(use_editor, get_index_file(), "post-commit", NULL);
|
run_commit_hook(use_editor, get_index_file(), "post-commit", NULL);
|
||||||
if (amend && !no_post_rewrite) {
|
if (amend && !no_post_rewrite) {
|
||||||
commit_post_rewrite(the_repository, current_head, &oid);
|
commit_post_rewrite(the_repository, current_head, &oid);
|
||||||
|
|
|
@ -199,8 +199,10 @@ static struct option builtin_fetch_options[] = {
|
||||||
OPT_STRING_LIST(0, "negotiation-tip", &negotiation_tip, N_("revision"),
|
OPT_STRING_LIST(0, "negotiation-tip", &negotiation_tip, N_("revision"),
|
||||||
N_("report that we have only objects reachable from this object")),
|
N_("report that we have only objects reachable from this object")),
|
||||||
OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
|
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,
|
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,
|
OPT_BOOL(0, "show-forced-updates", &fetch_show_forced_updates,
|
||||||
N_("check for forced-updates on all updated branches")),
|
N_("check for forced-updates on all updated branches")),
|
||||||
OPT_BOOL(0, "write-commit-graph", &fetch_write_commit_graph,
|
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);
|
close_object_store(the_repository->objects);
|
||||||
|
|
||||||
if (enable_auto_gc)
|
if (enable_auto_gc)
|
||||||
run_auto_gc(verbosity < 0);
|
run_auto_maintenance(verbosity < 0);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -456,7 +456,7 @@ static void finish(struct commit *head_commit,
|
||||||
* user should see them.
|
* user should see them.
|
||||||
*/
|
*/
|
||||||
close_object_store(the_repository->objects);
|
close_object_store(the_repository->objects);
|
||||||
run_auto_gc(verbosity < 0);
|
run_auto_maintenance(verbosity < 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (new_head && show_diffstat) {
|
if (new_head && show_diffstat) {
|
||||||
|
|
|
@ -728,10 +728,10 @@ static int finish_rebase(struct rebase_options *opts)
|
||||||
apply_autostash(state_dir_path("autostash", opts));
|
apply_autostash(state_dir_path("autostash", opts));
|
||||||
close_object_store(the_repository->objects);
|
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.
|
* 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) {
|
if (opts->type == REBASE_MERGE) {
|
||||||
struct replay_opts replay = REPLAY_OPTS_INIT;
|
struct replay_opts replay = REPLAY_OPTS_INIT;
|
||||||
|
|
||||||
|
|
|
@ -1866,15 +1866,13 @@ int run_processes_parallel_tr2(int n, get_next_task_fn get_next_task,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int run_auto_gc(int quiet)
|
int run_auto_maintenance(int quiet)
|
||||||
{
|
{
|
||||||
struct strvec argv_gc_auto = STRVEC_INIT;
|
struct child_process maint = CHILD_PROCESS_INIT;
|
||||||
int status;
|
|
||||||
|
|
||||||
strvec_pushl(&argv_gc_auto, "gc", "--auto", NULL);
|
maint.git_cmd = 1;
|
||||||
if (quiet)
|
strvec_pushl(&maint.args, "maintenance", "run", "--auto", NULL);
|
||||||
strvec_push(&argv_gc_auto, "--quiet");
|
strvec_push(&maint.args, quiet ? "--quiet" : "--no-quiet");
|
||||||
status = run_command_v_opt(argv_gc_auto.v, RUN_GIT_CMD);
|
|
||||||
strvec_clear(&argv_gc_auto);
|
return run_command(&maint);
|
||||||
return status;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -221,7 +221,7 @@ int run_hook_ve(const char *const *env, const char *name, va_list args);
|
||||||
/*
|
/*
|
||||||
* Trigger an auto-gc
|
* Trigger an auto-gc
|
||||||
*/
|
*/
|
||||||
int run_auto_gc(int quiet);
|
int run_auto_maintenance(int quiet);
|
||||||
|
|
||||||
#define RUN_COMMAND_NO_STDIN 1
|
#define RUN_COMMAND_NO_STDIN 1
|
||||||
#define RUN_GIT_CMD 2 /*If this is to be git sub-command */
|
#define RUN_GIT_CMD 2 /*If this is to be git sub-command */
|
||||||
|
|
|
@ -934,7 +934,7 @@ test_expect_success 'fetching with auto-gc does not lock up' '
|
||||||
git config fetch.unpackLimit 1 &&
|
git config fetch.unpackLimit 1 &&
|
||||||
git config gc.autoPackLimit 1 &&
|
git config gc.autoPackLimit 1 &&
|
||||||
git config gc.autoDetach false &&
|
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 &&
|
test_i18ngrep "Auto packing the repository" fetch.out &&
|
||||||
! grep "Should I try again" fetch.out
|
! grep "Should I try again" fetch.out
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue