#!/bin/sh global test_description := ''handling of duplicate objects in incoming packfiles'' source ./test-lib.sh source "$TEST_DIRECTORY"/lib-pack.sh # The sha1s we have in our pack. It's important that these have the same # starting byte, so that they end up in the same fanout section of the index. # That lets us make sure we are exercising the binary search with both sets. global LO_SHA1 := 'e68fe8129b546b101aee9510c5328e7f21ca1d18' global HI_SHA1 := 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391' # And here's a "missing sha1" which will produce failed lookups. It must also # be in the same fanout section, and should be between the two (so that during # our binary search, we are sure to end up looking at one or the other of the # duplicate runs). global MISSING_SHA1 := ''e69d000000000000000000000000000000000000'' # git will never intentionally create packfiles with # duplicate objects, so we have to construct them by hand. # # $1 is the name of the packfile to create # # $2 is the number of times to duplicate each object proc create_pack { pack_header "$(2 * $2)" >$1 && for i in [$[test_seq 1 $2]] { pack_obj $LO_SHA1 && pack_obj $HI_SHA1 } >>"$1" && pack_trailer $1 } # double-check that create_pack actually works test_expect_success 'pack with no duplicates' ' create_pack no-dups.pack 1 && git index-pack --stdin input <<-EOF && $LO_SHA1 $HI_SHA1 $MISSING_SHA1 EOF cat >expect <<-EOF $LO_SHA1 blob 2 $HI_SHA1 blob 0 $MISSING_SHA1 missing EOF ' test_expect_success 'lookup in duplicated pack (binary search)' ' git cat-file --batch-check actual && test_cmp expect actual ' test_expect_success 'lookup in duplicated pack (GIT_USE_LOOKUP)' ' ( GIT_USE_LOOKUP=1 && export GIT_USE_LOOKUP && git cat-file --batch-check actual ) && test_cmp expect actual ' test_expect_success 'index-pack can reject packs with duplicates' ' clear_packs && create_pack dups.pack 2 && test_must_fail git index-pack --strict --stdin )} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(.)} {(DQ ($ VSub_Name "$TEST_DIRECTORY")) (/lib-pack.sh)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:LO_SHA1) op: Equal rhs: {(e68fe8129b546b101aee9510c5328e7f21ca1d18)} spids: [30] ) ] spids: [30] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:HI_SHA1) op: Equal rhs: {(e69de29bb2d1d6434b8b29ae775ad8c2e48c5391)} spids: [33] ) ] spids: [33] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:MISSING_SHA1) op: Equal rhs: {(SQ )} spids: [49] ) ] spids: [49] ) (FuncDef name: create_pack body: (BraceGroup children: [ (AndOr children: [ (SimpleCommand words: [ {(pack_header)} { (DQ (ArithSubPart anode: (ArithBinary op_id: Arith_Star left: (ArithWord w:{(Lit_Digits 2)}) right: (ArithWord w:{($ VSub_Number "$2")}) ) spids: [84 91] ) ) } ] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(DQ ($ VSub_Number "$1"))} spids: [94] ) ] ) (AndOr children: [ (ForEach iter_name: i iter_words: [ { (CommandSubPart command_list: (CommandList children: [(C {(test_seq)} {(1)} {(DQ ($ VSub_Number "$2"))})] ) left_token: spids: [108 116] ) } ] do_arg_iter: False body: (DoGroup children: [ (AndOr children: [ (C {(pack_obj)} {($ VSub_Name "$LO_SHA1")}) (C {(pack_obj)} {($ VSub_Name "$HI_SHA1")}) ] op_id: Op_DAmp ) ] spids: [119 134] ) redirects: [ (Redir op_id: Redir_DGreat fd: -1 arg_word: {(DQ ($ VSub_Number "$1"))} spids: [136] ) ] spids: [107 117] ) (C {(pack_trailer)} {(DQ ($ VSub_Number "$1"))}) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [78] ) spids: [73 77] ) (C {(test_expect_success)} {(SQ <"pack with no duplicates">)} { (SQ <"\n"> <"\tcreate_pack no-dups.pack 1 &&\n"> <"\tgit index-pack --stdin ) } ) (C {(test_expect_success)} {(SQ <"index-pack will allow duplicate objects by default">)} { (SQ <"\n"> <"\tclear_packs &&\n"> <"\tcreate_pack dups.pack 100 &&\n"> <"\tgit index-pack --stdin ) } ) (C {(test_expect_success)} {(SQ <"create batch-check test vectors">)} { (SQ <"\n"> <"\tcat >input <<-EOF &&\n"> <"\t$LO_SHA1\n"> <"\t$HI_SHA1\n"> <"\t$MISSING_SHA1\n"> <"\tEOF\n"> <"\tcat >expect <<-EOF\n"> <"\t$LO_SHA1 blob 2\n"> <"\t$HI_SHA1 blob 0\n"> <"\t$MISSING_SHA1 missing\n"> <"\tEOF\n"> ) } ) (C {(test_expect_success)} {(SQ <"lookup in duplicated pack (binary search)">)} { (SQ <"\n"> <"\tgit cat-file --batch-check actual &&\n"> <"\ttest_cmp expect actual\n">) } ) (C {(test_expect_success)} {(SQ <"lookup in duplicated pack (GIT_USE_LOOKUP)">)} { (SQ <"\n"> <"\t(\n"> <"\t\tGIT_USE_LOOKUP=1 &&\n"> <"\t\texport GIT_USE_LOOKUP &&\n"> <"\t\tgit cat-file --batch-check actual\n"> <"\t) &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"index-pack can reject packs with duplicates">)} { (SQ <"\n"> <"\tclear_packs &&\n"> <"\tcreate_pack dups.pack 2 &&\n"> <"\ttest_must_fail git index-pack --strict --stdin <"\ttest_expect_code 1 git cat-file -e $LO_SHA1\n"> ) } ) (C {(test_done)}) ] )