Skip to content

Commit 1cd43a9

Browse files
chriscoolgitster
authored andcommitted
gc: add gc.repackFilter config option
A previous commit has implemented `git repack --filter=<filter-spec>` to allow users to filter out some objects from the main pack and move them into a new different pack. Users might want to perform such a cleanup regularly at the same time as they perform other repacks and cleanups, so as part of `git gc`. Let's allow them to configure a <filter-spec> for that purpose using a new gc.repackFilter config option. Now when `git gc` will perform a repack with a <filter-spec> configured through this option and not empty, the repack process will be passed a corresponding `--filter=<filter-spec>` argument. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 48a9b67 commit 1cd43a9

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

Documentation/config/gc.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ Multiple hooks are supported, but all must exit successfully, else the
145145
operation (either generating a cruft pack or unpacking unreachable
146146
objects) will be halted.
147147

148+
gc.repackFilter::
149+
When repacking, use the specified filter to move certain
150+
objects into a separate packfile. See the
151+
`--filter=<filter-spec>` option of linkgit:git-repack[1].
152+
148153
gc.rerereResolved::
149154
Records of conflicted merge you resolved earlier are
150155
kept for this many days when 'git rerere gc' is run.

builtin/gc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ static timestamp_t gc_log_expire_time;
6161
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";
64+
static char *repack_filter;
6465
static unsigned long big_pack_threshold;
6566
static unsigned long max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE;
6667

@@ -170,6 +171,8 @@ static void gc_config(void)
170171
git_config_get_ulong("gc.bigpackthreshold", &big_pack_threshold);
171172
git_config_get_ulong("pack.deltacachesize", &max_delta_cache_size);
172173

174+
git_config_get_string("gc.repackfilter", &repack_filter);
175+
173176
git_config(git_default_config, NULL);
174177
}
175178

@@ -355,6 +358,9 @@ static void add_repack_all_option(struct string_list *keep_pack)
355358

356359
if (keep_pack)
357360
for_each_string_list(keep_pack, keep_one_pack, NULL);
361+
362+
if (repack_filter && *repack_filter)
363+
strvec_pushf(&repack, "--filter=%s", repack_filter);
358364
}
359365

360366
static void add_repack_incremental_option(void)

t/t6500-gc.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,19 @@ test_expect_success 'one of gc.reflogExpire{Unreachable,}=never does not skip "e
202202
grep -E "^trace: (built-in|exec|run_command): git reflog expire --" trace.out
203203
'
204204

205+
test_expect_success 'gc.repackFilter launches repack with a filter' '
206+
test_when_finished "rm -rf bare.git" &&
207+
git clone --no-local --bare . bare.git &&
208+
209+
git -C bare.git -c gc.cruftPacks=false gc &&
210+
test_stdout_line_count = 1 ls bare.git/objects/pack/*.pack &&
211+
212+
GIT_TRACE=$(pwd)/trace.out git -C bare.git -c gc.repackFilter=blob:none \
213+
-c repack.writeBitmaps=false -c gc.cruftPacks=false gc &&
214+
test_stdout_line_count = 2 ls bare.git/objects/pack/*.pack &&
215+
grep -E "^trace: (built-in|exec|run_command): git repack .* --filter=blob:none ?.*" trace.out
216+
'
217+
205218
prepare_cruft_history () {
206219
test_commit base &&
207220

0 commit comments

Comments
 (0)