Skip to content

Commit c3690c9

Browse files
ttaylorrgitster
authored andcommitted
builtin/repack.c: use a string_list for 'midx_pack_names'
When writing a new MIDX, repack must determine whether or not there are any packs in the MIDX it is replacing (if one exists) that are not somehow represented in the new MIDX (e.g., either by preserving the pack verbatim, or rolling it up as part of a geometric repack, etc.). In order to do this, it keeps track of a list of pack names from the MIDX present in the repository at the start of the repack operation. Since we manipulate and close the object store, we cannot rely on the repository's in-core representation of the MIDX, since this is subject to change and/or go away. When this behavior was introduced in 5ee86c2 (repack: exclude cruft pack(s) from the MIDX where possible, 2025-06-23), we maintained an array of character pointers instead of using a convenience API, such as string-list.h. Store the list of MIDX pack names in a string_list, thereby reducing the number of parameters we have to pass to `midx_has_unknown_packs()`. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent e6b0907 commit c3690c9

1 file changed

Lines changed: 17 additions & 23 deletions

File tree

builtin/repack.c

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,17 @@ struct repack_write_midx_opts {
118118
int midx_must_contain_cruft;
119119
};
120120

121-
static int midx_has_unknown_packs(char **midx_pack_names,
122-
size_t midx_pack_names_nr,
121+
static int midx_has_unknown_packs(struct string_list *midx_pack_names,
123122
struct string_list *include,
124123
struct pack_geometry *geometry,
125124
struct existing_packs *existing)
126125
{
127-
size_t i;
126+
struct string_list_item *item;
128127

129128
string_list_sort(include);
130129

131-
for (i = 0; i < midx_pack_names_nr; i++) {
132-
const char *pack_name = midx_pack_names[i];
130+
for_each_string_list_item(item, midx_pack_names) {
131+
const char *pack_name = item->string;
133132

134133
/*
135134
* Determine whether or not each MIDX'd pack from the existing
@@ -191,8 +190,7 @@ static int midx_has_unknown_packs(char **midx_pack_names,
191190

192191
static void midx_included_packs(struct string_list *include,
193192
struct existing_packs *existing,
194-
char **midx_pack_names,
195-
size_t midx_pack_names_nr,
193+
struct string_list *midx_pack_names,
196194
struct string_list *names,
197195
struct pack_geometry *geometry)
198196
{
@@ -247,8 +245,8 @@ static void midx_included_packs(struct string_list *include,
247245
}
248246

249247
if (midx_must_contain_cruft ||
250-
midx_has_unknown_packs(midx_pack_names, midx_pack_names_nr,
251-
include, geometry, existing)) {
248+
midx_has_unknown_packs(midx_pack_names, include, geometry,
249+
existing)) {
252250
/*
253251
* If there are one or more unknown pack(s) present (see
254252
* midx_has_unknown_packs() for what makes a pack
@@ -606,13 +604,12 @@ int cmd_repack(int argc,
606604
struct child_process cmd = CHILD_PROCESS_INIT;
607605
struct string_list_item *item;
608606
struct string_list names = STRING_LIST_INIT_DUP;
607+
struct string_list midx_pack_names = STRING_LIST_INIT_DUP;
609608
struct existing_packs existing = EXISTING_PACKS_INIT;
610609
struct pack_geometry geometry = { 0 };
611610
struct tempfile *refs_snapshot = NULL;
612611
int i, ret;
613612
int show_progress;
614-
char **midx_pack_names = NULL;
615-
size_t midx_pack_names_nr = 0;
616613

617614
/* variables to be filled by option parsing */
618615
struct repack_config_ctx config_ctx;
@@ -985,13 +982,12 @@ int cmd_repack(int argc,
985982
struct multi_pack_index *m =
986983
get_multi_pack_index(repo->objects->sources);
987984

988-
ALLOC_ARRAY(midx_pack_names,
989-
m->num_packs + m->num_packs_in_base);
990-
991-
for (; m; m = m->base_midx)
992-
for (uint32_t i = 0; i < m->num_packs; i++)
993-
midx_pack_names[midx_pack_names_nr++] =
994-
xstrdup(m->pack_names[i]);
985+
for (; m; m = m->base_midx) {
986+
for (uint32_t i = 0; i < m->num_packs; i++) {
987+
string_list_append(&midx_pack_names,
988+
m->pack_names[i]);
989+
}
990+
}
995991
}
996992

997993
close_object_store(repo->objects);
@@ -1019,8 +1015,8 @@ int cmd_repack(int argc,
10191015
.write_bitmaps = write_bitmaps > 0,
10201016
.midx_must_contain_cruft = midx_must_contain_cruft
10211017
};
1022-
midx_included_packs(&include, &existing, midx_pack_names,
1023-
midx_pack_names_nr, &names, &geometry);
1018+
midx_included_packs(&include, &existing, &midx_pack_names,
1019+
&names, &geometry);
10241020

10251021
ret = write_midx_included_packs(&opts);
10261022

@@ -1067,11 +1063,9 @@ int cmd_repack(int argc,
10671063
cleanup:
10681064
string_list_clear(&keep_pack_list, 0);
10691065
string_list_clear(&names, 1);
1066+
string_list_clear(&midx_pack_names, 0);
10701067
existing_packs_release(&existing);
10711068
pack_geometry_release(&geometry);
1072-
for (size_t i = 0; i < midx_pack_names_nr; i++)
1073-
free(midx_pack_names[i]);
1074-
free(midx_pack_names);
10751069
pack_objects_args_release(&po_args);
10761070
pack_objects_args_release(&cruft_po_args);
10771071

0 commit comments

Comments
 (0)