diff --git a/builtin/mktree.c b/builtin/mktree.c index dc2d293c3d..45ae2af3b5 100644 --- a/builtin/mktree.c +++ b/builtin/mktree.c @@ -125,7 +125,6 @@ static void mktree_line(struct repository *repo, char *buf, int nul_term_line, i oi.typep = &obj_type; if (odb_read_object_info_extended(repo->objects, &oid, &oi, OBJECT_INFO_LOOKUP_REPLACE | - OBJECT_INFO_QUICK | OBJECT_INFO_SKIP_FETCH_OBJECT) < 0) obj_type = -1; diff --git a/t/t1010-mktree.sh b/t/t1010-mktree.sh index 312fe6717a..cecba55d45 100755 --- a/t/t1010-mktree.sh +++ b/t/t1010-mktree.sh @@ -69,4 +69,52 @@ test_expect_success 'mktree refuses to read ls-tree -r output (2)' ' test_must_fail git mktree pack-a && + echo "$b" | git pack-objects .git/objects/pack/pack >pack-b && + + # Drop the loose copies so the blobs resolve only through the + # packs the multi-pack-index names. + git prune-packed && + git multi-pack-index write && + printf "100644 blob %s\ta\n" "$a" >tree-a && + printf "100644 blob %s\tb\n" "$b" >tree-b && + + victim=".git/objects/pack/pack-$(cat pack-b)" && + mkfifo in out && + + # mktree --batch stays resident, so its pack view predates the + # repack below; feed it one tree at a time over a fifo. The + # subshell exit closes the fifos, letting mktree see EOF and quit. + (git mktree --batch out 2>err &) && + exec 9>in && + exec 8&9 && echo >&9 && read tree_a <&8 && + + # Mimic a concurrent repack: a replacement pack holds every + # object, and the pack for b loses its .idx (its .pack lingers), + # matching the order in which unlink_pack_path() removes files. + git cat-file --batch-all-objects --batch-check="%(objectname)" >oids && + git pack-objects .git/objects/pack/pack /dev/null && + rm -f "$victim.idx" && + + # Resolving b used to fail, as its QUICK lookup accepted the + # miss; without QUICK the reader repreps and finds b in the + # replacement pack. + cat tree-b >&9 && echo >&9 && read tree_b <&8 && + exec 9>&- && + + test -n "$tree_b" + ) +' + test_done