repack: move `pack_kept_objects` to `struct pack_objects_args`

The "pack_kept_objects" variable is defined as static to the repack builtin, but is inherently related to the pack-objects arguments that the builtin uses when generating new packs. Move that field into the "struct pack_objects_args", and shuffle around where we append the corresponding command-line option when preparing a pack-objects process. Specifically: - `write_cruft_pack()` always wants to pass "--honor-pack-keep", so explicitly set the `pack_kept_objects` field to "0" when initializing the `write_pack_opts` struct before calling `write_cruft_pack()`. - `write_filtered_pack()` no longer needs to handle writing the command-line option "--honor-pack-keep" when preparing a pack-objects process, since its call to `prepare_pack_objects()` will have already taken care of that. `write_filtered_pack()` also reads the `pack_kept_objects` field to determine whether to write the existing kept packs with a leading "^" character, so update that to read through the `po_args` pointer instead. - `cmd_repack()` also no longer has to write the "--honor-pack-keep" flag explicitly, since this is also handled via its call to `prepare_pack_objects()`. Since there is a default value for "pack_kept_objects" that relies on whether or not we are writing a bitmap (and not writing a MIDX), extract a default initializer for `struct pack_objects_args` that keeps this conditional default behavior. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Oct 15, 2025 at 18:29 UTC d278970aef66e2cfcbcbab650c1fc1b6613b40db
4 files changed +17 -19
builtin/repack.c
+7 -13
@@ -33,7 +33,6 @@
33 #define RETAIN_PACK 2
34
35 static int pack_everything;
36 -static int pack_kept_objects = -1;
36 static int write_bitmaps = -1;
37 static int use_delta_islands;
38 static int run_update_server_info = 1;
@@ -68,7 +67,7 @@ static int repack_config(const char *var, const char *value,
67 return 0;
68 }
69 if (!strcmp(var, "repack.packkeptobjects")) {
71 - pack_kept_objects = git_config_bool(var, value);
70 + po_args->pack_kept_objects = git_config_bool(var, value);
71 return 0;
72 }
73 if (!strcmp(var, "repack.writebitmaps") ||
@@ -122,8 +121,6 @@ static int write_filtered_pack(const struct write_pack_opts *opts,
121
122 strvec_push(&cmd.args, "--stdin-packs");
123
125 - if (!pack_kept_objects)
126 - strvec_push(&cmd.args, "--honor-pack-keep");
124 for_each_string_list_item(item, &existing->kept_packs)
125 strvec_pushf(&cmd.args, "--keep-pack=%s", item->string);
126
@@ -146,7 +143,7 @@ static int write_filtered_pack(const struct write_pack_opts *opts,
143 fprintf(in, "%s.pack\n", item->string);
144 for_each_string_list_item(item, &existing->cruft_packs)
145 fprintf(in, "%s.pack\n", item->string);
149 - caret = pack_kept_objects ? "" : "^";
146 + caret = opts->po_args->pack_kept_objects ? "" : "^";
147 for_each_string_list_item(item, &existing->kept_packs)
148 fprintf(in, "%s%s.pack\n", caret, item->string);
149 fclose(in);
@@ -208,7 +205,6 @@ static int write_cruft_pack(const struct write_pack_opts *opts,
205 strvec_pushf(&cmd.args, "--cruft-expiration=%s",
206 cruft_expiration);
207
211 - strvec_push(&cmd.args, "--honor-pack-keep");
208 strvec_push(&cmd.args, "--non-empty");
209
210 cmd.in = -1;
@@ -332,7 +328,7 @@ int cmd_repack(int argc,
328 OPT_UNSIGNED(0, "max-pack-size", &po_args.max_pack_size,
329 N_("maximum size of each packfile")),
330 OPT_PARSE_LIST_OBJECTS_FILTER(&po_args.filter_options),
335 - OPT_BOOL(0, "pack-kept-objects", &pack_kept_objects,
331 + OPT_BOOL(0, "pack-kept-objects", &po_args.pack_kept_objects,
332 N_("repack objects in packs marked with .keep")),
333 OPT_STRING_LIST(0, "keep-pack", &keep_pack_list, N_("name"),
334 N_("do not repack this pack")),
@@ -378,8 +374,8 @@ int cmd_repack(int argc,
374 (!(pack_everything & ALL_INTO_ONE) || !is_bare_repository()))
375 write_bitmaps = 0;
376 }
381 - if (pack_kept_objects < 0)
382 - pack_kept_objects = write_bitmaps > 0 && !write_midx;
377 + if (po_args.pack_kept_objects < 0)
378 + po_args.pack_kept_objects = write_bitmaps > 0 && !write_midx;
379
380 if (write_bitmaps && !(pack_everything & ALL_INTO_ONE) && !write_midx)
381 die(_(incremental_bitmap_conflict_error));
@@ -420,8 +416,7 @@ int cmd_repack(int argc,
416 if (geometry.split_factor) {
417 if (pack_everything)
418 die(_("options '%s' and '%s' cannot be used together"), "--geometric", "-A/-a");
423 - pack_geometry_init(&geometry, &existing, &po_args,
424 - pack_kept_objects);
419 + pack_geometry_init(&geometry, &existing, &po_args);
420 pack_geometry_split(&geometry);
421 }
422
@@ -430,8 +425,6 @@ int cmd_repack(int argc,
425 show_progress = !po_args.quiet && isatty(2);
426
427 strvec_push(&cmd.args, "--keep-true-parents");
433 - if (!pack_kept_objects)
434 - strvec_push(&cmd.args, "--honor-pack-keep");
428 for (i = 0; i < keep_pack_list.nr; i++)
429 strvec_pushf(&cmd.args, "--keep-pack=%s",
430 keep_pack_list.items[i].string);
@@ -581,6 +574,7 @@ int cmd_repack(int argc,
574 cruft_po_args.local = po_args.local;
575 cruft_po_args.quiet = po_args.quiet;
576 cruft_po_args.delta_base_offset = po_args.delta_base_offset;
577 + cruft_po_args.pack_kept_objects = 0;
578
579 ret = write_cruft_pack(&opts, cruft_expiration,
580 combine_cruft_below_size, &names,
repack-geometry.c
+2 -3
@@ -27,8 +27,7 @@ static int pack_geometry_cmp(const void *va, const void *vb)
27
28 void pack_geometry_init(struct pack_geometry *geometry,
29 struct existing_packs *existing,
30 - const struct pack_objects_args *args,
31 - int pack_kept_objects)
30 + const struct pack_objects_args *args)
31 {
32 struct packfile_store *packs = existing->repo->objects->packfiles;
33 struct packed_git *p;
@@ -43,7 +42,7 @@ void pack_geometry_init(struct pack_geometry *geometry,
42 */
43 continue;
44
46 - if (!pack_kept_objects) {
45 + if (!args->pack_kept_objects) {
46 /*
47 * Any pack that has its pack_keep bit set will
48 * appear in existing->kept_packs below, but
repack.c
+2
@@ -38,6 +38,8 @@ void prepare_pack_objects(struct child_process *cmd,
38 strvec_push(&cmd->args, "--quiet");
39 if (args->delta_base_offset)
40 strvec_push(&cmd->args, "--delta-base-offset");
41 + if (!args->pack_kept_objects)
42 + strvec_push(&cmd->args, "--honor-pack-keep");
43 strvec_push(&cmd->args, out);
44 cmd->git_cmd = 1;
45 cmd->out = -1;
repack.h
+6 -3
@@ -17,10 +17,14 @@ struct pack_objects_args {
17 int name_hash_version;
18 int path_walk;
19 int delta_base_offset;
20 + int pack_kept_objects;
21 struct list_objects_filter_options filter_options;
22 };
23
23 -#define PACK_OBJECTS_ARGS_INIT { .delta_base_offset = 1 }
24 +#define PACK_OBJECTS_ARGS_INIT { \
25 + .delta_base_offset = 1, \
26 + .pack_kept_objects = -1, \
27 +}
28
29 struct child_process;
30
@@ -104,8 +108,7 @@ struct pack_geometry {
108
109 void pack_geometry_init(struct pack_geometry *geometry,
110 struct existing_packs *existing,
107 - const struct pack_objects_args *args,
108 - int pack_kept_objects);
111 + const struct pack_objects_args *args);
112 void pack_geometry_split(struct pack_geometry *geometry);
113 struct packed_git *pack_geometry_preferred_pack(struct pack_geometry *geometry);
114 void pack_geometry_remove_redundant(struct pack_geometry *geometry,