Skip to content

Commit 892d3fb

Browse files
committed
Merge branch 'nd/fetch-multi-gc-once'
"git fetch" that grabs from a group of remotes learned to run the auto-gc only once at the very end. * nd/fetch-multi-gc-once: fetch: only run 'gc' once when fetching multiple remotes
2 parents f4f7e75 + c3d6b70 commit 892d3fb

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

Documentation/fetch-options.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ ifndef::git-pull[]
8888
Allow several <repository> and <group> arguments to be
8989
specified. No <refspec>s may be specified.
9090

91+
--[no-]auto-gc::
92+
Run `git gc --auto` at the end to perform garbage collection
93+
if needed. This is enabled by default.
94+
9195
-p::
9296
--prune::
9397
Before fetching, remove any remote-tracking references that no

builtin/fetch.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static int prune_tags = -1; /* unspecified */
4848

4949
static int all, append, dry_run, force, keep, multiple, update_head_ok, verbosity, deepen_relative;
5050
static int progress = -1;
51+
static int enable_auto_gc = 1;
5152
static int tags = TAGS_DEFAULT, unshallow, update_shallow, deepen;
5253
static int max_children = 1;
5354
static enum transport_family family;
@@ -169,6 +170,8 @@ static struct option builtin_fetch_options[] = {
169170
OPT_STRING_LIST(0, "negotiation-tip", &negotiation_tip, N_("revision"),
170171
N_("report that we have only objects reachable from this object")),
171172
OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
173+
OPT_BOOL(0, "auto-gc", &enable_auto_gc,
174+
N_("run 'gc --auto' after fetching")),
172175
OPT_END()
173176
};
174177

@@ -1432,7 +1435,7 @@ static int fetch_multiple(struct string_list *list)
14321435
return errcode;
14331436
}
14341437

1435-
argv_array_pushl(&argv, "fetch", "--append", NULL);
1438+
argv_array_pushl(&argv, "fetch", "--append", "--no-auto-gc", NULL);
14361439
add_options_to_argv(&argv);
14371440

14381441
for (i = 0; i < list->nr; i++) {
@@ -1682,11 +1685,13 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
16821685

16831686
close_object_store(the_repository->objects);
16841687

1685-
argv_array_pushl(&argv_gc_auto, "gc", "--auto", NULL);
1686-
if (verbosity < 0)
1687-
argv_array_push(&argv_gc_auto, "--quiet");
1688-
run_command_v_opt(argv_gc_auto.argv, RUN_GIT_CMD);
1689-
argv_array_clear(&argv_gc_auto);
1688+
if (enable_auto_gc) {
1689+
argv_array_pushl(&argv_gc_auto, "gc", "--auto", NULL);
1690+
if (verbosity < 0)
1691+
argv_array_push(&argv_gc_auto, "--quiet");
1692+
run_command_v_opt(argv_gc_auto.argv, RUN_GIT_CMD);
1693+
argv_array_clear(&argv_gc_auto);
1694+
}
16901695

16911696
return result;
16921697
}

t/t5514-fetch-multiple.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,12 @@ test_expect_success 'git fetch --multiple (two remotes)' '
105105
git remote rm origin &&
106106
git remote add one ../one &&
107107
git remote add two ../two &&
108-
git fetch --multiple one two &&
108+
GIT_TRACE=1 git fetch --multiple one two 2>trace &&
109109
git branch -r > output &&
110-
test_cmp ../expect output)
110+
test_cmp ../expect output &&
111+
grep "built-in: git gc" trace >gc &&
112+
test_line_count = 1 gc
113+
)
111114
'
112115

113116
test_expect_success 'git fetch --multiple (bad remote names)' '

0 commit comments

Comments
 (0)