xdiff: add recs_match helper function
[git/git-svn.git] / t / t5308-pack-detect-duplicates.sh
blob9c5a8766ab0af40382b83cf3340b13a32f7f0c8e
1 #!/bin/sh
3 test_description='handling of duplicate objects in incoming packfiles'
4 . ./test-lib.sh
5 . "$TEST_DIRECTORY"/lib-pack.sh
7 # The sha1s we have in our pack. It's important that these have the same
8 # starting byte, so that they end up in the same fanout section of the index.
9 # That lets us make sure we are exercising the binary search with both sets.
10 LO_SHA1=e68fe8129b546b101aee9510c5328e7f21ca1d18
11 HI_SHA1=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
13 # And here's a "missing sha1" which will produce failed lookups. It must also
14 # be in the same fanout section, and should be between the two (so that during
15 # our binary search, we are sure to end up looking at one or the other of the
16 # duplicate runs).
17 MISSING_SHA1='e69d000000000000000000000000000000000000'
19 # git will never intentionally create packfiles with
20 # duplicate objects, so we have to construct them by hand.
22 # $1 is the name of the packfile to create
24 # $2 is the number of times to duplicate each object
25 create_pack () {
26 pack_header "$((2 * $2))" >"$1" &&
27 for i in $(test_seq 1 "$2"); do
28 pack_obj $LO_SHA1 &&
29 pack_obj $HI_SHA1
30 done >>"$1" &&
31 pack_trailer "$1"
34 # double-check that create_pack actually works
35 test_expect_success 'pack with no duplicates' '
36 create_pack no-dups.pack 1 &&
37 git index-pack --stdin <no-dups.pack
40 test_expect_success 'index-pack will allow duplicate objects by default' '
41 clear_packs &&
42 create_pack dups.pack 100 &&
43 git index-pack --stdin <dups.pack
46 test_expect_success 'create batch-check test vectors' '
47 cat >input <<-EOF &&
48 $LO_SHA1
49 $HI_SHA1
50 $MISSING_SHA1
51 EOF
52 cat >expect <<-EOF
53 $LO_SHA1 blob 2
54 $HI_SHA1 blob 0
55 $MISSING_SHA1 missing
56 EOF
59 test_expect_success 'lookup in duplicated pack (binary search)' '
60 git cat-file --batch-check <input >actual &&
61 test_cmp expect actual
64 test_expect_success 'lookup in duplicated pack (GIT_USE_LOOKUP)' '
66 GIT_USE_LOOKUP=1 &&
67 export GIT_USE_LOOKUP &&
68 git cat-file --batch-check <input >actual
69 ) &&
70 test_cmp expect actual
73 test_expect_success 'index-pack can reject packs with duplicates' '
74 clear_packs &&
75 create_pack dups.pack 2 &&
76 test_must_fail git index-pack --strict --stdin <dups.pack &&
77 test_expect_code 1 git cat-file -e $LO_SHA1
80 test_done