pack-objects: allow setting `pack.allowPackReuse` to "single"

In e704fc7978 (pack-objects: introduce pack.allowPackReuse, 2019-12-18), the `pack.allowPackReuse` configuration option was introduced, allowing users to disable the pack reuse mechanism. To prepare for debugging multi-pack reuse, allow setting configuration to "single" in addition to the usual bool-or-int values. "single" implies the same behavior as "true", "1", "yes", and so on. But it will complement a new "multi" value (to be introduced in a future commit). When set to "single", we will only perform pack reuse on a single pack, regardless of whether or not there are multiple MIDX'd packs. This requires no code changes (yet), since we only support single pack reuse. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Dec 14, 2023 at 17:24 UTC 941074134cefe49fd7dc894665f1eb9804e06cf8
2 files changed +17 -4
Documentation/config/pack.txt
+1 -1
@@ -28,7 +28,7 @@ all existing objects. You can force recompression by passing the -F option
28 to linkgit:git-repack[1].
29
30 pack.allowPackReuse::
31 - When true, and when reachability bitmaps are enabled,
31 + When true or "single", and when reachability bitmaps are enabled,
32 pack-objects will try to send parts of the bitmapped packfile
33 verbatim. This can reduce memory and CPU usage to serve fetches,
34 but might result in sending a slightly larger pack. Defaults to
builtin/pack-objects.c
+16 -3
@@ -229,7 +229,10 @@ static struct bitmap *reuse_packfile_bitmap;
229
230 static int use_bitmap_index_default = 1;
231 static int use_bitmap_index = -1;
232 -static int allow_pack_reuse = 1;
232 +static enum {
233 + NO_PACK_REUSE = 0,
234 + SINGLE_PACK_REUSE,
235 +} allow_pack_reuse = SINGLE_PACK_REUSE;
236 static enum {
237 WRITE_BITMAP_FALSE = 0,
238 WRITE_BITMAP_QUIET,
@@ -3244,7 +3247,17 @@ static int git_pack_config(const char *k, const char *v,
3247 return 0;
3248 }
3249 if (!strcmp(k, "pack.allowpackreuse")) {
3247 - allow_pack_reuse = git_config_bool(k, v);
3250 + int res = git_parse_maybe_bool_text(v);
3251 + if (res < 0) {
3252 + if (!strcasecmp(v, "single"))
3253 + allow_pack_reuse = SINGLE_PACK_REUSE;
3254 + else
3255 + die(_("invalid pack.allowPackReuse value: '%s'"), v);
3256 + } else if (res) {
3257 + allow_pack_reuse = SINGLE_PACK_REUSE;
3258 + } else {
3259 + allow_pack_reuse = NO_PACK_REUSE;
3260 + }
3261 return 0;
3262 }
3263 if (!strcmp(k, "pack.threads")) {
@@ -3999,7 +4012,7 @@ static void loosen_unused_packed_objects(void)
4012 */
4013 static int pack_options_allow_reuse(void)
4014 {
4002 - return allow_pack_reuse &&
4015 + return allow_pack_reuse != NO_PACK_REUSE &&
4016 pack_to_stdout &&
4017 !ignore_packed_keep_on_disk &&
4018 !ignore_packed_keep_in_core &&