[PATCH 36/49] builtin/repack.c: inline `remove_redundant_bitmaps()`

Taylor Blau
2025-09-28T22:09:34Z

After writing a new MIDX, the repack command removes any bitmaps
belonging to packs which were written into the MIDX.

This is currently done in a separate function outside of
`write_midx_included_packs()`, which forces the caller to keep track of
the set of packs written into the MIDX.

Prepare to no longer require the caller to keep track of such
information by inlining the clean-up into `write_midx_included_packs()`.
Future commits will make the caller oblivious to the set of packs
included in the MIDX altogether.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
builtin/repack.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/builtin/repack.c b/builtin/repack.c
index 957a9b5f9e..b55c8934e8 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -331,10 +331,10 @@ static int write_midx_included_packs(struct repack_write_midx_opts *opts)
struct string_list_item *item;
struct packed_git *preferred = pack_geometry_preferred_pack(opts->geometry);
FILE *in;
- int ret;
+ int ret = 0;

if (!opts->include->nr)
- return 0;
+ goto done;

cmd.in = -1;
cmd.git_cmd = 1;
@@ -392,14 +392,18 @@ static int write_midx_included_packs(struct repack_write_midx_opts *opts)

ret = start_command(&cmd);
if (ret)
- return ret;
+ goto done;

in = xfdopen(cmd.in, "w");
for_each_string_list_item(item, opts->include)
fprintf(in, "%s\n", item->string);
fclose(in);

- return finish_command(&cmd);
+ ret = finish_command(&cmd);
+done:
+ if (!ret && opts->write_bitmaps)
+ remove_redundant_bitmaps(opts->include, opts->packdir);
+ return ret;
}

static int finish_pack_objects_cmd(const struct git_hash_algo *algop,
@@ -1003,9 +1007,6 @@ int cmd_repack(int argc,

ret = write_midx_included_packs(&opts);

- if (!ret && write_bitmaps)
- remove_redundant_bitmaps(&include, opts.packdir);
-
string_list_clear(&include, 0);

if (ret)
--
2.51.0.243.g16eca91f2c0