Skip to content

Commit 2fee63a

Browse files
ttaylorrgitster
authored andcommitted
repack: keep track of MIDX pack names using existing_packs
Instead of storing the list of MIDX pack names separately, let's inline it into the existing_packs struct, further reducing the number of parameters we have to pass around. This amounts to adding a new string_list to the existing_packs struct, and populating it via `existing_packs_collect()`. This is fairly straightforward to do, since we are already looping over all packs, all we need to do is: if (p->multi_pack_index) string_list_append(&existing->midx_packs, pack_basename(p)); Note, however, that this check *must* come before other conditions where we discard and do not keep track of a pack, including the condition "if (!p->pack_local)" immediately below. This is because the existing routine which collects MIDX pack names does so blindly, and does not discard, for example, non-local packs. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent c3690c9 commit 2fee63a

File tree

3 files changed

+10
-22
lines changed

3 files changed

+10
-22
lines changed

builtin/repack.c

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,15 @@ struct repack_write_midx_opts {
118118
int midx_must_contain_cruft;
119119
};
120120

121-
static int midx_has_unknown_packs(struct string_list *midx_pack_names,
122-
struct string_list *include,
121+
static int midx_has_unknown_packs(struct string_list *include,
123122
struct pack_geometry *geometry,
124123
struct existing_packs *existing)
125124
{
126125
struct string_list_item *item;
127126

128127
string_list_sort(include);
129128

130-
for_each_string_list_item(item, midx_pack_names) {
129+
for_each_string_list_item(item, &existing->midx_packs) {
131130
const char *pack_name = item->string;
132131

133132
/*
@@ -190,7 +189,6 @@ static int midx_has_unknown_packs(struct string_list *midx_pack_names,
190189

191190
static void midx_included_packs(struct string_list *include,
192191
struct existing_packs *existing,
193-
struct string_list *midx_pack_names,
194192
struct string_list *names,
195193
struct pack_geometry *geometry)
196194
{
@@ -245,8 +243,7 @@ static void midx_included_packs(struct string_list *include,
245243
}
246244

247245
if (midx_must_contain_cruft ||
248-
midx_has_unknown_packs(midx_pack_names, include, geometry,
249-
existing)) {
246+
midx_has_unknown_packs(include, geometry, existing)) {
250247
/*
251248
* If there are one or more unknown pack(s) present (see
252249
* midx_has_unknown_packs() for what makes a pack
@@ -604,7 +601,6 @@ int cmd_repack(int argc,
604601
struct child_process cmd = CHILD_PROCESS_INIT;
605602
struct string_list_item *item;
606603
struct string_list names = STRING_LIST_INIT_DUP;
607-
struct string_list midx_pack_names = STRING_LIST_INIT_DUP;
608604
struct existing_packs existing = EXISTING_PACKS_INIT;
609605
struct pack_geometry geometry = { 0 };
610606
struct tempfile *refs_snapshot = NULL;
@@ -978,18 +974,6 @@ int cmd_repack(int argc,
978974

979975
string_list_sort(&names);
980976

981-
if (get_multi_pack_index(repo->objects->sources)) {
982-
struct multi_pack_index *m =
983-
get_multi_pack_index(repo->objects->sources);
984-
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-
}
991-
}
992-
993977
close_object_store(repo->objects);
994978

995979
/*
@@ -1015,8 +999,7 @@ int cmd_repack(int argc,
1015999
.write_bitmaps = write_bitmaps > 0,
10161000
.midx_must_contain_cruft = midx_must_contain_cruft
10171001
};
1018-
midx_included_packs(&include, &existing, &midx_pack_names,
1019-
&names, &geometry);
1002+
midx_included_packs(&include, &existing, &names, &geometry);
10201003

10211004
ret = write_midx_included_packs(&opts);
10221005

@@ -1063,7 +1046,6 @@ int cmd_repack(int argc,
10631046
cleanup:
10641047
string_list_clear(&keep_pack_list, 0);
10651048
string_list_clear(&names, 1);
1066-
string_list_clear(&midx_pack_names, 0);
10671049
existing_packs_release(&existing);
10681050
pack_geometry_release(&geometry);
10691051
pack_objects_args_release(&po_args);

repack.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ void existing_packs_collect(struct existing_packs *existing,
8080
size_t i;
8181
const char *base;
8282

83+
if (p->multi_pack_index)
84+
string_list_append(&existing->midx_packs,
85+
pack_basename(p));
8386
if (!p->pack_local)
8487
continue;
8588

@@ -104,6 +107,7 @@ void existing_packs_collect(struct existing_packs *existing,
104107
string_list_sort(&existing->kept_packs);
105108
string_list_sort(&existing->non_kept_packs);
106109
string_list_sort(&existing->cruft_packs);
110+
string_list_sort(&existing->midx_packs);
107111
strbuf_release(&buf);
108112
}
109113

@@ -220,6 +224,7 @@ void existing_packs_release(struct existing_packs *existing)
220224
string_list_clear(&existing->kept_packs, 0);
221225
string_list_clear(&existing->non_kept_packs, 0);
222226
string_list_clear(&existing->cruft_packs, 0);
227+
string_list_clear(&existing->midx_packs, 0);
223228
}
224229

225230
static struct {

repack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct existing_packs {
4040
struct string_list kept_packs;
4141
struct string_list non_kept_packs;
4242
struct string_list cruft_packs;
43+
struct string_list midx_packs;
4344
};
4445

4546
#define EXISTING_PACKS_INIT { \

0 commit comments

Comments
 (0)