Skip to content

Commit 7390f05

Browse files
rcoupgitster
authored andcommitted
fetch: after refetch, encourage auto gc repacking
After invoking `fetch --refetch`, the object db will likely contain many duplicate objects. If auto-maintenance is enabled, invoke it with appropriate settings to encourage repacking/consolidation. * gc.autoPackLimit: unless this is set to 0 (disabled), override the value to 1 to force pack consolidation. * maintenance.incremental-repack.auto: unless this is set to 0, override the value to -1 to force incremental repacking. Signed-off-by: Robert Coup <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 011b775 commit 7390f05

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

Documentation/fetch-options.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ ifndef::git-pull[]
169169
associated objects that are already present locally, this option fetches
170170
all objects as a fresh clone would. Use this to reapply a partial clone
171171
filter from configuration or using `--filter=` when the filter
172-
definition has changed.
172+
definition has changed. Automatic post-fetch maintenance will perform
173+
object database pack consolidation to remove any duplicate objects.
173174
endif::git-pull[]
174175

175176
--refmap=<refspec>::

builtin/fetch.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2226,8 +2226,25 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
22262226
NULL);
22272227
}
22282228

2229-
if (enable_auto_gc)
2229+
if (enable_auto_gc) {
2230+
if (refetch) {
2231+
/*
2232+
* Hint auto-maintenance strongly to encourage repacking,
2233+
* but respect config settings disabling it.
2234+
*/
2235+
int opt_val;
2236+
if (git_config_get_int("gc.autopacklimit", &opt_val))
2237+
opt_val = -1;
2238+
if (opt_val != 0)
2239+
git_config_push_parameter("gc.autoPackLimit=1");
2240+
2241+
if (git_config_get_int("maintenance.incremental-repack.auto", &opt_val))
2242+
opt_val = -1;
2243+
if (opt_val != 0)
2244+
git_config_push_parameter("maintenance.incremental-repack.auto=-1");
2245+
}
22302246
run_auto_maintenance(verbosity < 0);
2247+
}
22312248

22322249
cleanup:
22332250
string_list_clear(&list, 0);

t/t5616-partial-clone.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,35 @@ test_expect_success 'fetch --refetch works with a shallow clone' '
216216
test_line_count = 6 observed
217217
'
218218

219+
test_expect_success 'fetch --refetch triggers repacking' '
220+
GIT_TRACE2_CONFIG_PARAMS=gc.autoPackLimit,maintenance.incremental-repack.auto &&
221+
export GIT_TRACE2_CONFIG_PARAMS &&
222+
223+
GIT_TRACE2_EVENT="$PWD/trace1.event" \
224+
git -C pc1 fetch --refetch origin &&
225+
test_subcommand git maintenance run --auto --no-quiet <trace1.event &&
226+
grep \"param\":\"gc.autopacklimit\",\"value\":\"1\" trace1.event &&
227+
grep \"param\":\"maintenance.incremental-repack.auto\",\"value\":\"-1\" trace1.event &&
228+
229+
GIT_TRACE2_EVENT="$PWD/trace2.event" \
230+
git -c protocol.version=0 \
231+
-c gc.autoPackLimit=0 \
232+
-c maintenance.incremental-repack.auto=1234 \
233+
-C pc1 fetch --refetch origin &&
234+
test_subcommand git maintenance run --auto --no-quiet <trace2.event &&
235+
grep \"param\":\"gc.autopacklimit\",\"value\":\"0\" trace2.event &&
236+
grep \"param\":\"maintenance.incremental-repack.auto\",\"value\":\"-1\" trace2.event &&
237+
238+
GIT_TRACE2_EVENT="$PWD/trace3.event" \
239+
git -c protocol.version=0 \
240+
-c gc.autoPackLimit=1234 \
241+
-c maintenance.incremental-repack.auto=0 \
242+
-C pc1 fetch --refetch origin &&
243+
test_subcommand git maintenance run --auto --no-quiet <trace3.event &&
244+
grep \"param\":\"gc.autopacklimit\",\"value\":\"1\" trace3.event &&
245+
grep \"param\":\"maintenance.incremental-repack.auto\",\"value\":\"0\" trace3.event
246+
'
247+
219248
test_expect_success 'partial clone with transfer.fsckobjects=1 works with submodules' '
220249
test_create_repo submodule &&
221250
test_commit -C submodule mycommit &&

0 commit comments

Comments
 (0)