From: Patrick Steinhardt Date: Wed, 10 Dec 2025 12:52:17 GMT Subject: [PATCH v2 0/3] builtin/repack: avoid rewriting up-to-date MIDX Message-ID: <20251210-pks-skip-noop-rewrite-v2-0-f813a9e44f28@pks.im> In-Reply-To: <20251208-pks-skip-noop-rewrite-v1-0-430d52dba9f0@pks.im> Hi, this small patch series introduces logic to avoid rewriting the multi-pack index in case it's up-to-date already. This is especially relevant in the context of geometric repacking, where we may decide to not write any new packfiles, but we'd still rewrite the multi-pack index. This is a follow-up for the discussion that happened at [1]. Changes in v2: - Move the logic to skip writing updates into `write_midx_internal()`. We already had some logic there to skip no-op rewrites, so we only extend that logic now to handle the "--stdin-packs" option. This also has the added benefit that we know to strip bitmaps in case the write is a no-op. - I don't handle the case anymore where the preferred pack is changing. We didn't do so in the preexisting checks either, so I decided to drop this for now. This _can_ be considered as a bug, and if anyone thinks it is then I'll extend these checks. - Adapt the tests to use git-multi-pack-index(1) directly. - Link to v1: https://lore.kernel.org/r/20251208-pks-skip-noop-rewrite-v1-0-430d52dba9f0@pks.im Thanks! Patrick [1]: <20251025191550.GA279793@coredump.intra.peff.net> --- Patrick Steinhardt (3): midx: fix `BUG()` when getting preferred pack without a reverse index midx-write: extract function to test whether MIDX needs updating midx-write: skip rewriting MIDX with `--stdin-packs` unless needed midx-write.c | 113 ++++++++++++++++++++++++++++++++++++-------- midx.c | 2 +- pack-revindex.h | 3 +- t/t5319-multi-pack-index.sh | 64 +++++++++++++++++++++++++ t/t7703-repack-geometric.sh | 35 ++++++++++++++ 5 files changed, 195 insertions(+), 22 deletions(-) Range-diff versus v1: 1: 11258a799b ! 1: 88ba93d3a5 midx: fix `BUG()` when getting preferred pack without a reverse index @@ Commit message The function `midx_preferred_pack()` returns the preferred pack for a given multi-pack index. To compute the preferred pack we: - 1. Look up the position of the first object indexed by the multi-pack - index. + 1. Take the first position indexed by the MIDX in pseudo-pack order. - 2. Convert this position from pseudo-pack order into MIDX order. + 2. Convert this pseudo-pack position into the MIDX position. - 3. We then look up pack that corresponds to this MIDX index. + 3. We then look up the pack that corresponds to this MIDX position. This reliably returns the preferred pack given that all of its contained objects will be up front in pseudo-pack order. 2: baf307b521 < -: ---------- builtin/repack: don't regenerate MIDX unless needed -: ---------- > 2: 9bd320b2cf midx-write: extract function to test whether MIDX needs updating -: ---------- > 3: f594865c12 midx-write: skip rewriting MIDX with `--stdin-packs` unless needed --- base-commit: bdc5341ff65278a3cc80b2e8a02a2f02aa1fac06 change-id: 20251208-pks-skip-noop-rewrite-38d7f01c79c5