Skip to content

Commit d278970

Browse files
ttaylorrgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fa0787a commit d278970

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

builtin/repack.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#define RETAIN_PACK 2
3434

3535
static int pack_everything;
36-
static int pack_kept_objects = -1;
3736
static int write_bitmaps = -1;
3837
static int use_delta_islands;
3938
static int run_update_server_info = 1;
@@ -68,7 +67,7 @@ static int repack_config(const char *var, const char *value,
6867
return 0;
6968
}
7069
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);
7271
return 0;
7372
}
7473
if (!strcmp(var, "repack.writebitmaps") ||
@@ -122,8 +121,6 @@ static int write_filtered_pack(const struct write_pack_opts *opts,
122121

123122
strvec_push(&cmd.args, "--stdin-packs");
124123

125-
if (!pack_kept_objects)
126-
strvec_push(&cmd.args, "--honor-pack-keep");
127124
for_each_string_list_item(item, &existing->kept_packs)
128125
strvec_pushf(&cmd.args, "--keep-pack=%s", item->string);
129126

@@ -146,7 +143,7 @@ static int write_filtered_pack(const struct write_pack_opts *opts,
146143
fprintf(in, "%s.pack\n", item->string);
147144
for_each_string_list_item(item, &existing->cruft_packs)
148145
fprintf(in, "%s.pack\n", item->string);
149-
caret = pack_kept_objects ? "" : "^";
146+
caret = opts->po_args->pack_kept_objects ? "" : "^";
150147
for_each_string_list_item(item, &existing->kept_packs)
151148
fprintf(in, "%s%s.pack\n", caret, item->string);
152149
fclose(in);
@@ -208,7 +205,6 @@ static int write_cruft_pack(const struct write_pack_opts *opts,
208205
strvec_pushf(&cmd.args, "--cruft-expiration=%s",
209206
cruft_expiration);
210207

211-
strvec_push(&cmd.args, "--honor-pack-keep");
212208
strvec_push(&cmd.args, "--non-empty");
213209

214210
cmd.in = -1;
@@ -332,7 +328,7 @@ int cmd_repack(int argc,
332328
OPT_UNSIGNED(0, "max-pack-size", &po_args.max_pack_size,
333329
N_("maximum size of each packfile")),
334330
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,
336332
N_("repack objects in packs marked with .keep")),
337333
OPT_STRING_LIST(0, "keep-pack", &keep_pack_list, N_("name"),
338334
N_("do not repack this pack")),
@@ -378,8 +374,8 @@ int cmd_repack(int argc,
378374
(!(pack_everything & ALL_INTO_ONE) || !is_bare_repository()))
379375
write_bitmaps = 0;
380376
}
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;
383379

384380
if (write_bitmaps && !(pack_everything & ALL_INTO_ONE) && !write_midx)
385381
die(_(incremental_bitmap_conflict_error));
@@ -420,8 +416,7 @@ int cmd_repack(int argc,
420416
if (geometry.split_factor) {
421417
if (pack_everything)
422418
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);
425420
pack_geometry_split(&geometry);
426421
}
427422

@@ -430,8 +425,6 @@ int cmd_repack(int argc,
430425
show_progress = !po_args.quiet && isatty(2);
431426

432427
strvec_push(&cmd.args, "--keep-true-parents");
433-
if (!pack_kept_objects)
434-
strvec_push(&cmd.args, "--honor-pack-keep");
435428
for (i = 0; i < keep_pack_list.nr; i++)
436429
strvec_pushf(&cmd.args, "--keep-pack=%s",
437430
keep_pack_list.items[i].string);
@@ -581,6 +574,7 @@ int cmd_repack(int argc,
581574
cruft_po_args.local = po_args.local;
582575
cruft_po_args.quiet = po_args.quiet;
583576
cruft_po_args.delta_base_offset = po_args.delta_base_offset;
577+
cruft_po_args.pack_kept_objects = 0;
584578

585579
ret = write_cruft_pack(&opts, cruft_expiration,
586580
combine_cruft_below_size, &names,

repack-geometry.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ static int pack_geometry_cmp(const void *va, const void *vb)
2727

2828
void pack_geometry_init(struct pack_geometry *geometry,
2929
struct existing_packs *existing,
30-
const struct pack_objects_args *args,
31-
int pack_kept_objects)
30+
const struct pack_objects_args *args)
3231
{
3332
struct packfile_store *packs = existing->repo->objects->packfiles;
3433
struct packed_git *p;
@@ -43,7 +42,7 @@ void pack_geometry_init(struct pack_geometry *geometry,
4342
*/
4443
continue;
4544

46-
if (!pack_kept_objects) {
45+
if (!args->pack_kept_objects) {
4746
/*
4847
* Any pack that has its pack_keep bit set will
4948
* appear in existing->kept_packs below, but

repack.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ void prepare_pack_objects(struct child_process *cmd,
3838
strvec_push(&cmd->args, "--quiet");
3939
if (args->delta_base_offset)
4040
strvec_push(&cmd->args, "--delta-base-offset");
41+
if (!args->pack_kept_objects)
42+
strvec_push(&cmd->args, "--honor-pack-keep");
4143
strvec_push(&cmd->args, out);
4244
cmd->git_cmd = 1;
4345
cmd->out = -1;

repack.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ struct pack_objects_args {
1717
int name_hash_version;
1818
int path_walk;
1919
int delta_base_offset;
20+
int pack_kept_objects;
2021
struct list_objects_filter_options filter_options;
2122
};
2223

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+
}
2428

2529
struct child_process;
2630

@@ -104,8 +108,7 @@ struct pack_geometry {
104108

105109
void pack_geometry_init(struct pack_geometry *geometry,
106110
struct existing_packs *existing,
107-
const struct pack_objects_args *args,
108-
int pack_kept_objects);
111+
const struct pack_objects_args *args);
109112
void pack_geometry_split(struct pack_geometry *geometry);
110113
struct packed_git *pack_geometry_preferred_pack(struct pack_geometry *geometry);
111114
void pack_geometry_remove_redundant(struct pack_geometry *geometry,

0 commit comments

Comments
 (0)