git/builtin
Taylor Blau fd2739b159 pack-bitmap: handle duplicate pack entries during MIDX reuse
A MIDX pseudo-pack assigns one bit position to each selected OID. Its
preferred-pack fast paths handle duplicate OIDs across packs in the
MIDX, where the MIDX chooses one copy, but assume that each individual
pack contains one entry per OID.

Consider a preferred pack ordered [A, B, A, C]. The MIDX retains one
copy of A, leaving three pseudo-pack positions for four physical
entries. This creates two problems:

 - In MIDX-backed single-pack reuse, bitmap_nr came from
   pack->num_objects and therefore counted both copies of A. Read the
   selected count from the root MIDX layer BTMP chunk instead. If that
   layer has no BTMP chunk, skip pack reuse and let the ordinary packing
   path handle the bitmap-selected objects. MIDXs without BTMP lose
   preferred-pack reuse until rewritten, rather than requiring a scan of
   the entire pseudo-pack to retain an optional optimization.

 - Correcting the range length still does not align the two orderings.
   Once one copy of A is omitted, MIDX position N need not name physical
   pack entry N.

That mismatch matters during both selection and output. Whole-word
selection bypasses the per-object check that the exact physical base of
a delta is present. Verbatim reuse copies the first N pack entries for
the first N bits. The per-object writer likewise used each bit as a
physical pack position.

Use the direct mapping only when the range begins at zero and its
selected count equals the physical entry count. Since selected entries
remain in pack-offset order, equal counts mean that none was omitted and
the two positions coincide.

For every other MIDX range, let whole-word selection fall through to
the existing per-bit path, which resolves the selected MIDX offset to a
physical pack position before checking the delta base. Disable verbatim
prefix reuse, and perform the same translation in the per-object writer.

Leave classic single-pack bitmap handling unchanged. The production
writer creates those bitmaps only for the pack it just wrote, which has
one entry per OID. The test helper can target an existing pack, but
rejects duplicate OIDs.

Cover the A, B, A, C case in a MIDX-backed preferred pack. Check reuse
with BTMP, then hide BTMP and check that the optional reuse path is
skipped. Also make B a delta against the omitted copy of A and require
normal packing to handle it.

Signed-off-by: Taylor Blau <ttaylorr@openai.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-07-24 19:05:11 -07:00
..
add.c odb/transaction: introduce ODB transaction flags 2026-07-10 13:21:53 -07:00
am.c hook: mark non-parallelizable hooks 2026-04-10 07:58:53 -07:00
annotate.c
apply.c
archive.c connect: use "service" enum for "name" argument 2026-05-19 15:05:46 +09:00
backfill.c path-walk: add pl_sparse_trees to control tree pruning 2026-05-24 18:41:06 +09:00
bisect.c bisect: ensure non-NULL `head` before using it 2026-07-10 08:13:55 -07:00
blame.c Merge branch 'bc/parse-options-exit-0-on-help' 2026-07-19 10:42:16 -07:00
branch.c branch: suggest <remote>/<branch> on upstream slip 2026-06-27 19:36:43 -07:00
bugreport.c
bundle.c
cat-file.c Merge branch 'ps/odb-drop-whence' 2026-07-15 13:24:18 -07:00
check-attr.c environment: stop using `the_repository` in `is_bare_repository()` 2026-06-11 05:05:54 -07:00
check-ignore.c
check-mailmap.c
check-ref-format.c setup: stop using `the_repository` in `setup_git_directory_gently()` 2026-05-19 19:36:24 +09:00
checkout--worker.c
checkout-index.c setup: stop using `the_repository` in `prefix_path()` 2026-05-19 19:36:24 +09:00
checkout.c refs: move parsing of "core.logAllRefUpdates" back into ref stores 2026-06-26 08:27:19 -07:00
clean.c
clone.c setup: pass worktree to `init_db()` 2026-07-07 10:49:41 -07:00
column.c
commit-graph.c
commit-tree.c
commit.c sequencer: teach autostash apply to take optional conflict marker labels 2026-04-29 21:46:03 +09:00
config.c config: improve diagnostic for "set" with missing value 2026-06-03 08:39:54 +09:00
count-objects.c
credential-cache--daemon.c
credential-cache.c
credential-store.c
credential.c
describe.c Merge branch 'kk/prio-queue-get-put-fusion' 2026-07-13 08:27:27 -07:00
diagnose.c
diff-files.c
diff-index.c setup: stop using `the_repository` in `setup_work_tree()` 2026-05-19 19:36:24 +09:00
diff-pairs.c
diff-tree.c
diff.c diff: handle NULL return from repo_get_commit_tree() 2026-07-10 08:13:54 -07:00
difftool.c odb: use size_t for object_info.sizep and the size APIs 2026-06-15 07:45:41 -07:00
fast-export.c fast-export: standardize usage string and SYNOPSIS 2026-07-13 08:54:29 -07:00
fast-import.c Merge branch 'jk/hash-algo-leak-fixes' 2026-07-16 23:05:47 -07:00
fetch-pack.c connect: use "service" enum for "name" argument 2026-05-19 15:05:46 +09:00
fetch.c Merge branch 'ty/migrate-ignorecase' 2026-07-19 10:42:19 -07:00
fmt-merge-msg.c
for-each-ref.c
for-each-repo.c
fsck.c odb: use size_t for object_info.sizep and the size APIs 2026-06-15 07:45:41 -07:00
fsmonitor--daemon.c fsmonitor: plug token-data leak on early daemon-startup failures 2026-07-05 09:12:10 -07:00
gc.c Merge branch 'ps/setup-drop-global-state' 2026-07-06 15:50:19 -07:00
get-tar-commit-id.c
grep.c Merge branch 'ps/odb-generalize-prepare' 2026-07-13 08:27:28 -07:00
hash-object.c setup: stop using `the_repository` in `setup_git_directory()` 2026-05-19 19:36:25 +09:00
help.c setup: stop using `the_repository` in `setup_git_directory_gently()` 2026-05-19 19:36:24 +09:00
history.c Merge branch 'ps/history-drop' 2026-07-15 13:24:19 -07:00
hook.c hook: allow hook.jobs=-1 to use all available CPU cores 2026-04-10 07:58:55 -07:00
index-pack.c Merge branch 'jk/git-hash-cleanups' 2026-07-16 23:05:48 -07:00
init-db.c setup: pass worktree to `init_db()` 2026-07-07 10:49:41 -07:00
interpret-trailers.c Merge branch 'kh/doc-interpret-trailers-1' 2026-03-27 11:00:02 -07:00
last-modified.c prio-queue: rename .nr to .nr_ and add accessor helpers 2026-06-09 11:11:46 -07:00
log.c Merge branch 'jk/format-patch-leakfix' 2026-07-13 08:27:27 -07:00
ls-files.c Merge branch 'js/objects-larger-than-4gb-on-windows-more' 2026-06-21 16:41:38 -07:00
ls-remote.c
ls-tree.c odb: use size_t for object_info.sizep and the size APIs 2026-06-15 07:45:41 -07:00
mailinfo.c
mailsplit.c mailsplit: move NULL check before first use of file handle 2026-07-10 08:13:54 -07:00
merge-base.c commit-reach: early exit paint_down_to_common for single merge-base 2026-05-12 09:33:43 +09:00
merge-file.c setup: stop using `the_repository` in `setup_git_directory()` 2026-05-19 19:36:25 +09:00
merge-index.c
merge-ours.c
merge-recursive.c
merge-tree.c odb: use size_t for object_info.sizep and the size APIs 2026-06-15 07:45:41 -07:00
merge.c Merge branch 'kk/merge-octopus-optim' 2026-05-27 14:15:44 +09:00
mktag.c odb: use size_t for object_info.sizep and the size APIs 2026-06-15 07:45:41 -07:00
mktree.c builtin/mktree: remove USE_THE_REPOSITORY_VARIABLE 2026-03-12 10:03:23 -07:00
multi-pack-index.c midx: refactor interfaces to work on "packed" source 2026-06-17 05:00:01 -07:00
mv.c Merge branch 'ty/migrate-ignorecase' 2026-07-19 10:42:19 -07:00
name-rev.c Merge branch 'kh/name-rev-custom-format' 2026-05-19 09:57:44 +09:00
notes.c odb: use size_t for object_info.sizep and the size APIs 2026-06-15 07:45:41 -07:00
pack-objects.c pack-bitmap: handle duplicate pack entries during MIDX reuse 2026-07-24 19:05:11 -07:00
pack-redundant.c
pack-refs.c
patch-id.c hash: use git_hash_init() consistently 2026-07-07 21:56:00 -07:00
prune-packed.c
prune.c
pull.c fetch: add --negotiation-include option for negotiation 2026-05-20 11:33:24 +09:00
push.c push: suggest <remote> <branch> for a slash slip 2026-06-27 19:36:43 -07:00
range-diff.c
read-tree.c setup: stop using `the_repository` in `setup_work_tree()` 2026-05-19 19:36:24 +09:00
rebase.c reset: introduce ability to skip updating HEAD 2026-07-03 10:32:33 -07:00
receive-pack.c Merge branch 'jt/receive-pack-use-odb-transactions' 2026-07-22 10:30:53 -07:00
reflog.c
refs.c builtin/refs: add "rename" subcommand 2026-07-06 07:45:57 -07:00
remote-ext.c
remote-fd.c
remote.c odb: rename `odb_has_object()` flags 2026-03-31 20:43:14 -07:00
repack.c Merge branch 'ps/odb-source-packed' 2026-07-06 15:50:21 -07:00
replace.c hex: add and use strbuf_add_oid_hex() 2026-05-14 15:59:25 +09:00
replay.c replay: allow to specify a ref with option --ref 2026-04-01 21:34:25 -07:00
repo.c setup: move prefix into repository 2026-07-07 10:49:40 -07:00
rerere.c
reset.c environment: stop using `the_repository` in `is_bare_repository()` 2026-06-11 05:05:54 -07:00
rev-list.c pack-bitmap: allow aborting iteration of bitmapped objects 2026-07-15 07:19:16 -07:00
rev-parse.c setup: move prefix into repository 2026-07-07 10:49:40 -07:00
revert.c
rm.c setup: stop using `the_repository` in `setup_work_tree()` 2026-05-19 19:36:24 +09:00
send-pack.c connect: use "service" enum for "name" argument 2026-05-19 15:05:46 +09:00
shortlog.c parse-options: exit 0 on -h 2026-07-07 17:48:57 -07:00
show-branch.c prio-queue: fold lazy_queue into prio_queue for automatic get+put fusion 2026-06-09 11:11:46 -07:00
show-index.c
show-ref.c odb: rename `odb_has_object()` flags 2026-03-31 20:43:14 -07:00
sparse-checkout.c Merge branch 'ob/more-repo-config-values' 2026-06-15 07:42:00 -07:00
stash.c Merge branch 'aj/stash-patch-optimize-temporary-index' 2026-06-07 23:58:25 +09:00
stripspace.c setup: stop using `the_repository` in `setup_git_directory_gently()` 2026-05-19 19:36:24 +09:00
submodule--helper.c Merge branch 'dm/submodule-update-i-shorthand' 2026-07-22 10:30:52 -07:00
symbolic-ref.c
tag.c odb: use size_t for object_info.sizep and the size APIs 2026-06-15 07:45:41 -07:00
unpack-file.c odb: use size_t for object_info.sizep and the size APIs 2026-06-15 07:45:41 -07:00
unpack-objects.c Merge branch 'jt/receive-pack-use-odb-transactions' 2026-07-22 10:30:53 -07:00
update-index.c Merge branch 'jt/receive-pack-use-odb-transactions' 2026-07-22 10:30:53 -07:00
update-ref.c update-ref: handle rejections while adding updates 2026-05-05 16:34:08 +09:00
update-server-info.c
upload-archive.c setup: stop using `the_repository` in `enter_repo()` 2026-05-19 19:36:24 +09:00
upload-pack.c setup: stop using `the_repository` in `enter_repo()` 2026-05-19 19:36:24 +09:00
url-parse.c builtin: create url-parse command 2026-05-06 09:48:28 +09:00
var.c
verify-commit.c
verify-pack.c
verify-tag.c
worktree.c worktree: fix resource leaks when branch creation fails 2026-07-05 09:12:10 -07:00
write-tree.c