diff options
author | Taylor Blau <me@ttaylorr.com> | 2023-09-13 19:17:49 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-09-13 19:32:47 (GMT) |
commit | 639c4a3992337e15c0faa2fa6d73462cc76ca7b9 (patch) | |
tree | deea15f493107ecad85e36604c79e59df50b9bd5 /builtin/repack.c | |
parent | 054b5e4873d9ef2348f0880d66f1acf73bad7d59 (diff) | |
download | git-639c4a3992337e15c0faa2fa6d73462cc76ca7b9.zip git-639c4a3992337e15c0faa2fa6d73462cc76ca7b9.tar.gz git-639c4a3992337e15c0faa2fa6d73462cc76ca7b9.tar.bz2 |
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 <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/repack.c')
-rw-r--r-- | builtin/repack.c | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/builtin/repack.c b/builtin/repack.c index 7085568..d3e6326 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -540,6 +540,32 @@ static struct packed_git *get_preferred_pack(struct pack_geometry *geometry) return NULL; } +static void geometry_remove_redundant_packs(struct pack_geometry *geometry, + struct string_list *names, + struct existing_packs *existing) +{ + struct strbuf buf = STRBUF_INIT; + uint32_t i; + + for (i = 0; i < geometry->split; i++) { + struct packed_git *p = geometry->pack[i]; + if (string_list_has_string(names, hash_to_hex(p->hash))) + continue; + + strbuf_reset(&buf); + strbuf_addstr(&buf, pack_basename(p)); + strbuf_strip_suffix(&buf, ".pack"); + + if ((p->pack_keep) || + (string_list_has_string(&existing->kept_packs, buf.buf))) + continue; + + remove_redundant_pack(packdir, buf.buf); + } + + strbuf_release(&buf); +} + static void free_pack_geometry(struct pack_geometry *geometry) { if (!geometry) @@ -1201,29 +1227,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix) remove_redundant_pack(packdir, item->string); } - if (geometry.split_factor) { - struct strbuf buf = STRBUF_INIT; - - uint32_t i; - for (i = 0; i < geometry.split; i++) { - struct packed_git *p = geometry.pack[i]; - if (string_list_has_string(&names, - hash_to_hex(p->hash))) - continue; - - strbuf_reset(&buf); - strbuf_addstr(&buf, pack_basename(p)); - strbuf_strip_suffix(&buf, ".pack"); - - if ((p->pack_keep) || - (string_list_has_string(&existing.kept_packs, - buf.buf))) - continue; - - remove_redundant_pack(packdir, buf.buf); - } - strbuf_release(&buf); - } + if (geometry.split_factor) + geometry_remove_redundant_packs(&geometry, &names, + &existing); if (show_progress) opts |= PRUNE_PACKED_VERBOSE; prune_packed_objects(opts); |