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 <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Oct 2, 2023 at 18:55 UTC 1cd43a9ed96831b983fada37a71daacb6be373dc
3 files changed +24
Documentation/config/gc.txt
+5
@@ -145,6 +145,11 @@ Multiple hooks are supported, but all must exit successfully, else the
145 operation (either generating a cruft pack or unpacking unreachable
146 objects) will be halted.
147
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 +
153 gc.rerereResolved::
154 Records of conflicted merge you resolved earlier are
155 kept for this many days when 'git rerere gc' is run.
builtin/gc.c
+6
@@ -61,6 +61,7 @@ static timestamp_t gc_log_expire_time;
61 static const char *gc_log_expire = "1.day.ago";
62 static const char *prune_expire = "2.weeks.ago";
63 static const char *prune_worktrees_expire = "3.months.ago";
64 +static char *repack_filter;
65 static unsigned long big_pack_threshold;
66 static unsigned long max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE;
67
@@ -170,6 +171,8 @@ static void gc_config(void)
171 git_config_get_ulong("gc.bigpackthreshold", &big_pack_threshold);
172 git_config_get_ulong("pack.deltacachesize", &max_delta_cache_size);
173
174 + git_config_get_string("gc.repackfilter", &repack_filter);
175 +
176 git_config(git_default_config, NULL);
177 }
178
@@ -355,6 +358,9 @@ static void add_repack_all_option(struct string_list *keep_pack)
358
359 if (keep_pack)
360 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);
364 }
365
366 static void add_repack_incremental_option(void)
t/t6500-gc.sh
+13
@@ -202,6 +202,19 @@ test_expect_success 'one of gc.reflogExpire{Unreachable,}=never does not skip "e
202 grep -E "^trace: (built-in|exec|run_command): git reflog expire --" trace.out
203 '
204
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 +
218 prepare_cruft_history () {
219 test_commit base &&
220