Skip to content

Commit 9b96046

Browse files
chriscoolgitster
authored andcommitted
gc: add gc.repackFilterTo config option
A previous commit implemented the `gc.repackFilter` config option to specify a filter that should be used by `git gc` when performing repacks. Another previous commit has implemented `git repack --filter-to=<dir>` to specify the location of the packfile containing filtered out objects when using a filter. Let's implement the `gc.repackFilterTo` config option to specify that location in the config when `gc.repackFilter` is used. Now when `git gc` will perform a repack with a <dir> configured through this option and not empty, the repack process will be passed a corresponding `--filter-to=<dir>` argument. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 71c5aec commit 9b96046

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

Documentation/config/gc.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,17 @@ gc.repackFilter::
150150
objects into a separate packfile. See the
151151
`--filter=<filter-spec>` option of linkgit:git-repack[1].
152152

153+
gc.repackFilterTo::
154+
When repacking and using a filter, see `gc.repackFilter`, the
155+
specified location will be used to create the packfile
156+
containing the filtered out objects. **WARNING:** The
157+
specified location should be accessible, using for example the
158+
Git alternates mechanism, otherwise the repo could be
159+
considered corrupt by Git as it migh not be able to access the
160+
objects in that packfile. See the `--filter-to=<dir>` option
161+
of linkgit:git-repack[1] and the `objects/info/alternates`
162+
section of linkgit:gitrepository-layout[5].
163+
153164
gc.rerereResolved::
154165
Records of conflicted merge you resolved earlier are
155166
kept for this many days when 'git rerere gc' is run.

builtin/gc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ static const char *gc_log_expire = "1.day.ago";
6262
static const char *prune_expire = "2.weeks.ago";
6363
static const char *prune_worktrees_expire = "3.months.ago";
6464
static char *repack_filter;
65+
static char *repack_filter_to;
6566
static unsigned long big_pack_threshold;
6667
static unsigned long max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE;
6768

@@ -172,6 +173,7 @@ static void gc_config(void)
172173
git_config_get_ulong("pack.deltacachesize", &max_delta_cache_size);
173174

174175
git_config_get_string("gc.repackfilter", &repack_filter);
176+
git_config_get_string("gc.repackfilterto", &repack_filter_to);
175177

176178
git_config(git_default_config, NULL);
177179
}
@@ -361,6 +363,8 @@ static void add_repack_all_option(struct string_list *keep_pack)
361363

362364
if (repack_filter && *repack_filter)
363365
strvec_pushf(&repack, "--filter=%s", repack_filter);
366+
if (repack_filter_to && *repack_filter_to)
367+
strvec_pushf(&repack, "--filter-to=%s", repack_filter_to);
364368
}
365369

366370
static void add_repack_incremental_option(void)

t/t6500-gc.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ test_expect_success 'one of gc.reflogExpire{Unreachable,}=never does not skip "e
203203
'
204204

205205
test_expect_success 'gc.repackFilter launches repack with a filter' '
206-
test_when_finished "rm -rf bare.git" &&
207206
git clone --no-local --bare . bare.git &&
208207
209208
git -C bare.git -c gc.cruftPacks=false gc &&
@@ -215,6 +214,18 @@ test_expect_success 'gc.repackFilter launches repack with a filter' '
215214
grep -E "^trace: (built-in|exec|run_command): git repack .* --filter=blob:none ?.*" trace.out
216215
'
217216

217+
test_expect_success 'gc.repackFilterTo store filtered out objects' '
218+
test_when_finished "rm -rf bare.git filtered.git" &&
219+
220+
git init --bare filtered.git &&
221+
git -C bare.git -c gc.repackFilter=blob:none \
222+
-c gc.repackFilterTo=../filtered.git/objects/pack/pack \
223+
-c repack.writeBitmaps=false -c gc.cruftPacks=false gc &&
224+
225+
test_stdout_line_count = 1 ls bare.git/objects/pack/*.pack &&
226+
test_stdout_line_count = 1 ls filtered.git/objects/pack/*.pack
227+
'
228+
218229
prepare_cruft_history () {
219230
test_commit base &&
220231

0 commit comments

Comments
 (0)