From: Jeff King Date: Thu, 16 Apr 2026 20:06:59 +0000 (-0400) Subject: MIDX: revert the default version to v1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a12382f99488b8cea82f59a310084e43ff84e99b;p=thirdparty%2Fgit.git MIDX: revert the default version to v1 We introduced midx version 2 in b2ec8e90c2 (midx: do not require packs to be sorted in lexicographic order, 2026-02-24) and now write it by default. The rationale was that older versions should ignore the v2 midx and fall back to using the packs (just like we do for other midx errors). Unfortunately this is not the case, as we have a hard die() when we see an unknown midx version. As a result, writing a midx with Git 2.54-rc2 puts the repository into a state that is unusable with Git 2.53. And this midx write may happen behind the scenes as part of normal operations, like fetch. Let's switch back to writing v1 by default to avoid regressing the case where multiple versions of Git are used on the same repository. There is one gotcha, though: the v2 format is required for some new features, like midx compaction, and running "git multi-pack-index compact" will complain when asked to write a v1 index. The user must set midx.version to "2" to make the feature work. So instead of always using v1, we'll base the default on whether the requested feature requires v2. That does mean that running midx compaction will create a repository that can't be read by older versions of Git. But we never do that by default; only people experimenting with the new feature will be affected. We have to adjust the test expectation in t5319, since it will now generate v1 files. And our "auto-select v2" is covered by the tests in t5335, which continue to check that compaction works without having to set midx.version manually (and also explicitly check that asking for v1 with compaction reports the problem). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff --git a/Documentation/git-multi-pack-index.adoc b/Documentation/git-multi-pack-index.adoc index 6125683014..3a5aa22778 100644 --- a/Documentation/git-multi-pack-index.adoc +++ b/Documentation/git-multi-pack-index.adoc @@ -98,6 +98,9 @@ compact:: --[no-]bitmap:: Control whether or not a multi-pack bitmap is written. -- ++ +Note that the compact command requires writing a version-2 midx that +cannot be read by versions of Git prior to v2.54. verify:: Verify the contents of the MIDX file. diff --git a/midx-write.c b/midx-write.c index 0ff2e45aa7..a25cab75ab 100644 --- a/midx-write.c +++ b/midx-write.c @@ -1259,7 +1259,6 @@ static int write_midx_internal(struct write_midx_opts *opts) struct tempfile *incr; struct write_midx_context ctx = { .preferred_pack_idx = NO_PREFERRED_PACK, - .version = MIDX_VERSION_V2, }; struct multi_pack_index *midx_to_free = NULL; int bitmapped_packs_concat_len = 0; @@ -1275,6 +1274,9 @@ static int write_midx_internal(struct write_midx_opts *opts) ctx.repo = r; ctx.source = opts->source; + ctx.version = ((opts->flags & MIDX_WRITE_COMPACT) + ? MIDX_VERSION_V2 + : MIDX_VERSION_V1); repo_config_get_int(ctx.repo, "midx.version", &ctx.version); if (ctx.version != MIDX_VERSION_V1 && ctx.version != MIDX_VERSION_V2) die(_("unknown MIDX version: %d"), ctx.version); diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh index 58e0b685b1..fa0d4046f7 100755 --- a/t/t5319-multi-pack-index.sh +++ b/t/t5319-multi-pack-index.sh @@ -21,7 +21,7 @@ midx_read_expect () { EXTRA_CHUNKS="$5" { cat <<-EOF && - header: 4d494458 2 $HASH_LEN $NUM_CHUNKS $NUM_PACKS + header: 4d494458 1 $HASH_LEN $NUM_CHUNKS $NUM_PACKS chunks: pack-names oid-fanout oid-lookup object-offsets$EXTRA_CHUNKS num_objects: $NUM_OBJECTS packs: