midx: support custom `--base` for incremental MIDX writes
Both `compact` and `write --incremental` fix the base of the resulting
MIDX layer: `compact` always places the compacted result on top of
"from's" immediate parent in the chain, and `write --incremental` always
appends a new layer to the existing tip. In both cases the base is not
configurable.
Future callers need additional flexibility. For instance, the incremental
MIDX-based repacking code may wish to write a layer based on some
intermediate ancestor rather than the current tip, or produce a root
layer when replacing the bottommost entries in the chain.
Introduce a new `--base` option for both subcommands to specify the
checksum of the MIDX layer to use as the base. The given checksum must
refer to a valid layer in the MIDX chain that is an ancestor of the
topmost layer being written or compacted.
The special value "none" is accepted to produce a root layer with no
parent. This will be needed when the incremental repacking machinery
determines that the bottommost layers of the chain should be replaced.
If no `--base` is given, behavior is unchanged: `compact` uses "from's"
immediate parent in the chain, and `write` appends to the existing tip.
For the `write` subcommand, `--base` requires `--no-write-chain-file`. A plain
`write --incremental` appends a new layer to the live chain tip with no
mechanism to atomically replace it; overriding the base would produce a
layer that does not extend the tip, breaking chain invariants. With
`--no-write-chain-file` the chain is left unmodified and the caller is
responsible for assembling a valid chain.
For `compact`, no such restriction applies. The compaction operation
atomically replaces the compacted range in the chain file, so writing
the result on top of any valid ancestor preserves chain invariants.
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Taylor Blau committedMay 19, 2026 at 11:57 UTC0cd2255e64b4775520a6acbbb1868437fc26662d
6 files changed+178-9
Documentation/git-multi-pack-index.adoc
+16-1
index c26196815e..c6d23aeeb9 100644--- a/Documentation/git-multi-pack-index.adoc+++ b/Documentation/git-multi-pack-index.adoc@@ -12,8 +12,10 @@ SYNOPSIS 'git multi-pack-index' [<options>] write [--preferred-pack=<pack>] [--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs] [--refs-snapshot=<path>] [--[no-]write-chain-file]+ [--base=<checksum>] 'git multi-pack-index' [<options>] compact [--[no-]incremental]- [--[no-]bitmap] [--[no-]write-chain-file] <from> <to>+ [--[no-]bitmap] [--base=<checksum>] [--[no-]write-chain-file]+ <from> <to> 'git multi-pack-index' [<options>] verify 'git multi-pack-index' [<options>] expire 'git multi-pack-index' [<options>] repack [--batch-size=<size>]@@ -90,6 +92,13 @@ marker). The checksum of the new layer is printed to standard output, allowing the caller to assemble and write the chain itself. Requires `--incremental`.++ --base=<checksum>::+ Specify the checksum of an existing MIDX layer to use+ as the base when writing a new incremental layer.+ The special value `none` indicates that the new layer+ should have no base (i.e., it becomes a root layer).+ Requires `--no-write-chain-file`. -- compact::@@ -110,6 +119,12 @@ compact:: MIDX layer but do not update the multi-pack-index-chain file. The checksum of the new layer is printed to standard output. Requires `--incremental`.++ --base=<checksum>::+ Specify the checksum of an existing MIDX layer to use+ as the base for the compacted result, instead of using+ the immediate parent of `<from>`. The special value+ `none` indicates that the result should have no base. -- + Note that the compact command requires writing a version-2 midx that