Skip to content

Commit 639c4a3

Browse files
ttaylorrgitster
authored andcommitted
builtin/repack.c: extract redundant pack cleanup for --geometric
To reduce the complexity of the already quite-long `cmd_repack()` implementation, extract out the parts responsible for deleting redundant packs from a geometric repack out into its own sub-routine. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 054b5e4 commit 639c4a3

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

builtin/repack.c

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,32 @@ static struct packed_git *get_preferred_pack(struct pack_geometry *geometry)
540540
return NULL;
541541
}
542542

543+
static void geometry_remove_redundant_packs(struct pack_geometry *geometry,
544+
struct string_list *names,
545+
struct existing_packs *existing)
546+
{
547+
struct strbuf buf = STRBUF_INIT;
548+
uint32_t i;
549+
550+
for (i = 0; i < geometry->split; i++) {
551+
struct packed_git *p = geometry->pack[i];
552+
if (string_list_has_string(names, hash_to_hex(p->hash)))
553+
continue;
554+
555+
strbuf_reset(&buf);
556+
strbuf_addstr(&buf, pack_basename(p));
557+
strbuf_strip_suffix(&buf, ".pack");
558+
559+
if ((p->pack_keep) ||
560+
(string_list_has_string(&existing->kept_packs, buf.buf)))
561+
continue;
562+
563+
remove_redundant_pack(packdir, buf.buf);
564+
}
565+
566+
strbuf_release(&buf);
567+
}
568+
543569
static void free_pack_geometry(struct pack_geometry *geometry)
544570
{
545571
if (!geometry)
@@ -1201,29 +1227,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
12011227
remove_redundant_pack(packdir, item->string);
12021228
}
12031229

1204-
if (geometry.split_factor) {
1205-
struct strbuf buf = STRBUF_INIT;
1206-
1207-
uint32_t i;
1208-
for (i = 0; i < geometry.split; i++) {
1209-
struct packed_git *p = geometry.pack[i];
1210-
if (string_list_has_string(&names,
1211-
hash_to_hex(p->hash)))
1212-
continue;
1213-
1214-
strbuf_reset(&buf);
1215-
strbuf_addstr(&buf, pack_basename(p));
1216-
strbuf_strip_suffix(&buf, ".pack");
1217-
1218-
if ((p->pack_keep) ||
1219-
(string_list_has_string(&existing.kept_packs,
1220-
buf.buf)))
1221-
continue;
1222-
1223-
remove_redundant_pack(packdir, buf.buf);
1224-
}
1225-
strbuf_release(&buf);
1226-
}
1230+
if (geometry.split_factor)
1231+
geometry_remove_redundant_packs(&geometry, &names,
1232+
&existing);
12271233
if (show_progress)
12281234
opts |= PRUNE_PACKED_VERBOSE;
12291235
prune_packed_objects(opts);

0 commit comments

Comments
 (0)