#!/bin/sh # Copyright (c) 2011, Google Inc. global test_description := ''adding and checking out large blobs'' source ./test-lib.sh test_expect_success setup ' # clone does not allow us to pass core.bigfilethreshold to # new repos, so set core.bigfilethreshold globally git config --global core.bigfilethreshold 200k && printf "%2000000s" X >large1 && cp large1 large2 && cp large1 large3 && printf "%2500000s" Y >huge && GIT_ALLOC_LIMIT=1500k && export GIT_ALLOC_LIMIT ' test_expect_success 'add a large file or two' ' git add large1 huge large2 && # make sure we got a single packfile and no loose objects bad= count=0 idx= && for p in .git/objects/pack/pack-*.pack do count=$(( $count + 1 )) if test -f "$p" && idx=${p%.pack}.idx && test -f "$idx" then continue fi bad=t done && test -z "$bad" && test $count = 1 && cnt=$(git show-index <"$idx" | wc -l) && test $cnt = 2 && for l in .git/objects/??/?????????????????????????????????????? do test -f "$l" || continue bad=t done && test -z "$bad" && # attempt to add another copy of the same git add large3 && bad= count=0 && for p in .git/objects/pack/pack-*.pack do count=$(( $count + 1 )) if test -f "$p" && idx=${p%.pack}.idx && test -f "$idx" then continue fi bad=t done && test -z "$bad" && test $count = 1 ' test_expect_success 'checkout a large file' ' large1=$(git rev-parse :large1) && git update-index --add --cacheinfo 100644 $large1 another && git checkout another && test_cmp large1 another ' test_expect_success 'packsize limit' ' test_create_repo mid && ( cd mid && git config core.bigfilethreshold 64k && git config pack.packsizelimit 256k && # mid1 and mid2 will fit within 256k limit but # appending mid3 will bust the limit and will # result in a separate packfile. test-genrandom "a" $(( 66 * 1024 )) >mid1 && test-genrandom "b" $(( 80 * 1024 )) >mid2 && test-genrandom "c" $(( 128 * 1024 )) >mid3 && git add mid1 mid2 mid3 && count=0 for pi in .git/objects/pack/pack-*.idx do test -f "$pi" && count=$(( $count + 1 )) done && test $count = 2 && ( git hash-object --stdin expect && for pi in .git/objects/pack/pack-*.idx do git show-index <"$pi" done | sed -e "s/^[0-9]* \([0-9a-f]*\) .*/\1/" | sort >actual && test_cmp expect actual ) ' test_expect_success 'diff --raw' ' git commit -q -m initial && echo modified >>large1 && git add large1 && git commit -q -m modified && git diff --raw HEAD^ ' test_expect_success 'diff --stat' ' git diff --stat HEAD^ HEAD ' test_expect_success 'diff' ' git diff HEAD^ HEAD >actual && grep "Binary files.*differ" actual ' test_expect_success 'diff --cached' ' git diff --cached HEAD^ >actual && grep "Binary files.*differ" actual ' test_expect_success 'hash-object' ' git hash-object large1 ' test_expect_success 'cat-file a large file' ' git cat-file blob :large1 >/dev/null ' test_expect_success 'cat-file a large file from a tag' ' git tag -m largefile largefiletag :large1 && git cat-file blob largefiletag >/dev/null ' test_expect_success 'git-show a large file' ' git show :large1 >/dev/null ' test_expect_success 'index-pack' ' git clone file://"$(pwd)"/.git foo && GIT_DIR=non-existent git index-pack --strict --verify foo/.git/objects/pack/*.pack ' test_expect_success 'repack' ' git repack -ad ' test_expect_success 'pack-objects with large loose object' ' SHA1=$(git hash-object huge) && test_create_repo loose && echo $SHA1 | git pack-objects --stdout | GIT_ALLOC_LIMIT=0 GIT_DIR=loose/.git git unpack-objects && echo $SHA1 | GIT_DIR=loose/.git git pack-objects pack && test_create_repo packed && mv pack-* packed/.git/objects/pack && GIT_DIR=packed/.git git cat-file blob $SHA1 >actual && test_cmp huge actual ' test_expect_success 'tar achiving' ' git archive --format=tar HEAD >/dev/null ' test_expect_success 'zip achiving, store only' ' git archive --format=zip -0 HEAD >/dev/null ' test_expect_success 'zip achiving, deflate' ' git archive --format=zip HEAD >/dev/null ' test_expect_success 'fsck large blobs' ' git fsck 2>err && test_must_be_empty err ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"adding and checking out large blobs">)} spids: [7] ) ] spids: [7] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(setup)} { (SQ <"\n"> <"\t# clone does not allow us to pass core.bigfilethreshold to\n"> <"\t# new repos, so set core.bigfilethreshold globally\n"> <"\tgit config --global core.bigfilethreshold 200k &&\n"> <"\tprintf \"%2000000s\" X >large1 &&\n"> <"\tcp large1 large2 &&\n"> <"\tcp large1 large3 &&\n"> <"\tprintf \"%2500000s\" Y >huge &&\n"> <"\tGIT_ALLOC_LIMIT=1500k &&\n"> <"\texport GIT_ALLOC_LIMIT\n"> ) } ) (C {(test_expect_success)} {(SQ <"add a large file or two">)} { (SQ <"\n"> <"\tgit add large1 huge large2 &&\n"> <"\t# make sure we got a single packfile and no loose objects\n"> <"\tbad= count=0 idx= &&\n"> <"\tfor p in .git/objects/pack/pack-*.pack\n"> <"\tdo\n"> <"\t\tcount=$(( $count + 1 ))\n"> <"\t\tif test -f \"$p\" && idx=${p%.pack}.idx && test -f \"$idx\"\n"> <"\t\tthen\n"> <"\t\t\tcontinue\n"> <"\t\tfi\n"> <"\t\tbad=t\n"> <"\tdone &&\n"> <"\ttest -z \"$bad\" &&\n"> <"\ttest $count = 1 &&\n"> <"\tcnt=$(git show-index <\"$idx\" | wc -l) &&\n"> <"\ttest $cnt = 2 &&\n"> <"\tfor l in .git/objects/??/??????????????????????????????????????\n"> <"\tdo\n"> <"\t\ttest -f \"$l\" || continue\n"> <"\t\tbad=t\n"> <"\tdone &&\n"> <"\ttest -z \"$bad\" &&\n"> <"\n"> <"\t# attempt to add another copy of the same\n"> <"\tgit add large3 &&\n"> <"\tbad= count=0 &&\n"> <"\tfor p in .git/objects/pack/pack-*.pack\n"> <"\tdo\n"> <"\t\tcount=$(( $count + 1 ))\n"> <"\t\tif test -f \"$p\" && idx=${p%.pack}.idx && test -f \"$idx\"\n"> <"\t\tthen\n"> <"\t\t\tcontinue\n"> <"\t\tfi\n"> <"\t\tbad=t\n"> <"\tdone &&\n"> <"\ttest -z \"$bad\" &&\n"> <"\ttest $count = 1\n"> ) } ) (C {(test_expect_success)} {(SQ <"checkout a large file">)} { (SQ <"\n"> <"\tlarge1=$(git rev-parse :large1) &&\n"> <"\tgit update-index --add --cacheinfo 100644 $large1 another &&\n"> <"\tgit checkout another &&\n"> <"\ttest_cmp large1 another\n"> ) } ) (C {(test_expect_success)} {(SQ <"packsize limit">)} { (SQ <"\n"> <"\ttest_create_repo mid &&\n"> <"\t(\n"> <"\t\tcd mid &&\n"> <"\t\tgit config core.bigfilethreshold 64k &&\n"> <"\t\tgit config pack.packsizelimit 256k &&\n"> <"\n"> <"\t\t# mid1 and mid2 will fit within 256k limit but\n"> <"\t\t# appending mid3 will bust the limit and will\n"> <"\t\t# result in a separate packfile.\n"> <"\t\ttest-genrandom \"a\" $(( 66 * 1024 )) >mid1 &&\n"> <"\t\ttest-genrandom \"b\" $(( 80 * 1024 )) >mid2 &&\n"> <"\t\ttest-genrandom \"c\" $(( 128 * 1024 )) >mid3 &&\n"> <"\t\tgit add mid1 mid2 mid3 &&\n"> <"\n"> <"\t\tcount=0\n"> <"\t\tfor pi in .git/objects/pack/pack-*.idx\n"> <"\t\tdo\n"> <"\t\t\ttest -f \"$pi\" && count=$(( $count + 1 ))\n"> <"\t\tdone &&\n"> <"\t\ttest $count = 2 &&\n"> <"\n"> <"\t\t(\n"> <"\t\t\tgit hash-object --stdin <"\t\t\tgit hash-object --stdin <"\t\t\tgit hash-object --stdin <"\t\t) |\n"> <"\t\tsort >expect &&\n"> <"\n"> <"\t\tfor pi in .git/objects/pack/pack-*.idx\n"> <"\t\tdo\n"> <"\t\t\tgit show-index <\"$pi\"\n"> <"\t\tdone |\n"> <"\t\tsed -e \"s/^[0-9]* \\([0-9a-f]*\\) .*/\\1/\" |\n"> <"\t\tsort >actual &&\n"> <"\n"> <"\t\ttest_cmp expect actual\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"diff --raw">)} { (SQ <"\n"> <"\tgit commit -q -m initial &&\n"> <"\techo modified >>large1 &&\n"> <"\tgit add large1 &&\n"> <"\tgit commit -q -m modified &&\n"> <"\tgit diff --raw HEAD^\n"> ) } ) (C {(test_expect_success)} {(SQ <"diff --stat">)} {(SQ <"\n"> <"\tgit diff --stat HEAD^ HEAD\n">)}) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <"\tgit diff HEAD^ HEAD >actual &&\n"> <"\tgrep \"Binary files.*differ\" actual\n">) } ) (C {(test_expect_success)} {(SQ <"diff --cached">)} { (SQ <"\n"> <"\tgit diff --cached HEAD^ >actual &&\n"> <"\tgrep \"Binary files.*differ\" actual\n"> ) } ) (C {(test_expect_success)} {(SQ )} {(SQ <"\n"> <"\tgit hash-object large1\n">)}) (C {(test_expect_success)} {(SQ <"cat-file a large file">)} {(SQ <"\n"> <"\tgit cat-file blob :large1 >/dev/null\n">)} ) (C {(test_expect_success)} {(SQ <"cat-file a large file from a tag">)} { (SQ <"\n"> <"\tgit tag -m largefile largefiletag :large1 &&\n"> <"\tgit cat-file blob largefiletag >/dev/null\n"> ) } ) (C {(test_expect_success)} {(SQ <"git-show a large file">)} {(SQ <"\n"> <"\tgit show :large1 >/dev/null\n"> <"\n">)} ) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <"\tgit clone file://\"$(pwd)\"/.git foo &&\n"> < "\tGIT_DIR=non-existent git index-pack --strict --verify foo/.git/objects/pack/*.pack\n" > ) } ) (C {(test_expect_success)} {(SQ )} {(SQ <"\n"> <"\tgit repack -ad\n">)}) (C {(test_expect_success)} {(SQ <"pack-objects with large loose object">)} { (SQ <"\n"> <"\tSHA1=$(git hash-object huge) &&\n"> <"\ttest_create_repo loose &&\n"> <"\techo $SHA1 | git pack-objects --stdout |\n"> <"\t\tGIT_ALLOC_LIMIT=0 GIT_DIR=loose/.git git unpack-objects &&\n"> <"\techo $SHA1 | GIT_DIR=loose/.git git pack-objects pack &&\n"> <"\ttest_create_repo packed &&\n"> <"\tmv pack-* packed/.git/objects/pack &&\n"> <"\tGIT_DIR=packed/.git git cat-file blob $SHA1 >actual &&\n"> <"\ttest_cmp huge actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"tar achiving">)} {(SQ <"\n"> <"\tgit archive --format=tar HEAD >/dev/null\n">)} ) (C {(test_expect_success)} {(SQ <"zip achiving, store only">)} {(SQ <"\n"> <"\tgit archive --format=zip -0 HEAD >/dev/null\n">)} ) (C {(test_expect_success)} {(SQ <"zip achiving, deflate">)} {(SQ <"\n"> <"\tgit archive --format=zip HEAD >/dev/null\n">)} ) (C {(test_expect_success)} {(SQ <"fsck large blobs">)} {(SQ <"\n"> <"\tgit fsck 2>err &&\n"> <"\ttest_must_be_empty err\n">)} ) (C {(test_done)}) ] )