{"thread":{"id":"14111","subject":"[PATCH 3/3] test case for pack resilience against corruptions","startedAt":"2008-06-24T01:24:28Z","lastAt":"2008-06-25T18:35:13Z","messageCount":4,"participants":["Nicolas Pitre","Alex Riesen","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"80799","messageId":"alpine.LFD.1.10.0806232123420.2979@xanadu.home","threadId":"14111","inReplyTo":null,"subject":"[PATCH 3/3] test case for pack resilience against corruptions","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2008-06-24T01:24:28Z","receivedAt":"2008-06-24T01:24:28Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"\nSigned-off-by: Nicolas Pitre <nico@cam.org>\n---\n t/t5303-pack-corruption-resilience.sh |  194 +++++++++++++++++++++++++++++++++\n 1 files changed, 194 insertions(+), 0 deletions(-)\n create mode 100755 t/t5303-pack-corruption-resilience.sh\n\ndiff --git a/t/t5303-pack-corruption-resilience.sh b/t/t5303-pack-corruption-resilience.sh\nnew file mode 100755\nindex 0000000..b0f5693\n--- /dev/null\n+++ b/t/t5303-pack-corruption-resilience.sh\n@@ -0,0 +1,194 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2008 Nicolas Pitre\n+#\n+\n+test_description='resilience to pack corruptions with redundant objects'\n+. ./test-lib.sh\n+\n+# Note: the test objects are created with knowledge of their pack encoding\n+# to ensure good code path coverage, and to facilitate direct alteration\n+# later on.  The assumed characteristics are:\n+#\n+# 1) blob_2 is a delta with blob_1 for base and blob_3 is a delta with blob2\n+#    for base, such that blob_3 delta depth is 2;\n+#\n+# 2) the bulk of object data is uncompressible so the text part remains\n+#    visible;\n+#\n+# 3) object header is always 2 bytes.\n+\n+create_test_files() {\n+    test-genrandom \"foo\" 2000 > file_1 &&\n+    test-genrandom \"foo\" 1800 > file_2 &&\n+    test-genrandom \"foo\" 1800 > file_3 &&\n+    echo \" base \" >> file_1 &&\n+    echo \" delta1 \" >> file_2 &&\n+    echo \" delta delta2 \" >> file_3 &&\n+    test-genrandom \"bar\" 150 >> file_2 &&\n+    test-genrandom \"baz\" 100 >> file_3\n+}\n+\n+create_new_pack() {\n+    rm -rf .git &&\n+    git init &&\n+    blob_1=`git hash-object -t blob -w file_1` &&\n+    blob_2=`git hash-object -t blob -w file_2` &&\n+    blob_3=`git hash-object -t blob -w file_3` &&\n+    pack=`printf \"$blob_1\\n$blob_2\\n$blob_3\\n\" |\n+          git pack-objects $@ .git/objects/pack/pack` &&\n+    pack=\".git/objects/pack/pack-${pack}\" &&\n+    git verify-pack -v ${pack}.pack\n+}\n+\n+do_corrupt_object() {\n+    ofs=`git show-index < ${pack}.idx | grep $1 | cut -f1 -d\" \"` &&\n+    ofs=$(($ofs + $2)) &&\n+    chmod +w ${pack}.pack &&\n+    dd if=/dev/zero of=${pack}.pack count=1 bs=1 conv=notrunc seek=$ofs &&\n+    test_must_fail git verify-pack ${pack}.pack\n+}\n+\n+test_expect_success \\\n+    'initial setup validation' \\\n+    'create_test_files &&\n+     create_new_pack &&\n+     git prune-packed &&\n+     git cat-file blob $blob_1 > /dev/null &&\n+     git cat-file blob $blob_2 > /dev/null &&\n+     git cat-file blob $blob_3 > /dev/null'\n+\n+test_expect_success \\\n+    'create corruption in header of first object' \\\n+    'do_corrupt_object $blob_1 0 &&\n+     test_must_fail git cat-file blob $blob_1 > /dev/null &&\n+     test_must_fail git cat-file blob $blob_2 > /dev/null &&\n+     test_must_fail git cat-file blob $blob_3 > /dev/null'\n+\n+test_expect_success \\\n+    '... but having a loose copy allows for full recovery' \\\n+    'mv ${pack}.idx tmp &&\n+     git hash-object -t blob -w file_1 &&\n+     mv tmp ${pack}.idx &&\n+     git cat-file blob $blob_1 > /dev/null &&\n+     git cat-file blob $blob_2 > /dev/null &&\n+     git cat-file blob $blob_3 > /dev/null'\n+\n+test_expect_success \\\n+    '... and loose copy of first delta allows for partial recovery' \\\n+    'git prune-packed &&\n+     test_must_fail git cat-file blob $blob_2 > /dev/null &&\n+     mv ${pack}.idx tmp &&\n+     git hash-object -t blob -w file_2 &&\n+     mv tmp ${pack}.idx &&\n+     test_must_fail git cat-file blob $blob_1 > /dev/null &&\n+     git cat-file blob $blob_2 > /dev/null &&\n+     git cat-file blob $blob_3 > /dev/null'\n+\n+test_expect_success \\\n+    'create corruption in data of first object' \\\n+    'create_new_pack &&\n+     git prune-packed &&\n+     chmod +w ${pack}.pack &&\n+     perl -i -pe \"s/ base /abcdef/\" ${pack}.pack &&\n+     test_must_fail git cat-file blob $blob_1 > /dev/null &&\n+     test_must_fail git cat-file blob $blob_2 > /dev/null &&\n+     test_must_fail git cat-file blob $blob_3 > /dev/null'\n+\n+test_expect_success \\\n+    '... but having a loose copy allows for full recovery' \\\n+    'mv ${pack}.idx tmp &&\n+     git hash-object -t blob -w file_1 &&\n+     mv tmp ${pack}.idx &&\n+     git cat-file blob $blob_1 > /dev/null &&\n+     git cat-file blob $blob_2 > /dev/null &&\n+     git cat-file blob $blob_3 > /dev/null'\n+\n+test_expect_success \\\n+    '... and loose copy of second object allows for partial recovery' \\\n+    'git prune-packed &&\n+     test_must_fail git cat-file blob $blob_2 > /dev/null &&\n+     mv ${pack}.idx tmp &&\n+     git hash-object -t blob -w file_2 &&\n+     mv tmp ${pack}.idx &&\n+     test_must_fail git cat-file blob $blob_1 > /dev/null &&\n+     git cat-file blob $blob_2 > /dev/null &&\n+     git cat-file blob $blob_3 > /dev/null'\n+\n+test_expect_success \\\n+    'create corruption in header of first delta' \\\n+    'create_new_pack &&\n+     git prune-packed &&\n+     do_corrupt_object $blob_2 0 &&\n+     git cat-file blob $blob_1 > /dev/null &&\n+     test_must_fail git cat-file blob $blob_2 > /dev/null &&\n+     test_must_fail git cat-file blob $blob_3 > /dev/null'\n+\n+test_expect_success \\\n+    '... but having a loose copy allows for full recovery' \\\n+    'mv ${pack}.idx tmp &&\n+     git hash-object -t blob -w file_2 &&\n+     mv tmp ${pack}.idx &&\n+     git cat-file blob $blob_1 > /dev/null &&\n+     git cat-file blob $blob_2 > /dev/null &&\n+     git cat-file blob $blob_3 > /dev/null'\n+\n+test_expect_success \\\n+    'create corruption in data of first delta' \\\n+    'create_new_pack &&\n+     git prune-packed &&\n+     chmod +w ${pack}.pack &&\n+     perl -i -pe \"s/ delta1 /abcdefgh/\" ${pack}.pack &&\n+     git cat-file blob $blob_1 > /dev/null &&\n+     test_must_fail git cat-file blob $blob_2 > /dev/null &&\n+     test_must_fail git cat-file blob $blob_3 > /dev/null'\n+\n+test_expect_success \\\n+    '... but having a loose copy allows for full recovery' \\\n+    'mv ${pack}.idx tmp &&\n+     git hash-object -t blob -w file_2 &&\n+     mv tmp ${pack}.idx &&\n+     git cat-file blob $blob_1 > /dev/null &&\n+     git cat-file blob $blob_2 > /dev/null &&\n+     git cat-file blob $blob_3 > /dev/null'\n+\n+test_expect_success \\\n+    'corruption in delta base reference of first delta (OBJ_REF_DELTA)' \\\n+    'create_new_pack &&\n+     git prune-packed &&\n+     do_corrupt_object $blob_2 2 &&\n+     git cat-file blob $blob_1 > /dev/null &&\n+     test_must_fail git cat-file blob $blob_2 > /dev/null &&\n+     test_must_fail git cat-file blob $blob_3 > /dev/null'\n+\n+test_expect_success \\\n+    '... but having a loose copy allows for full recovery' \\\n+    'mv ${pack}.idx tmp &&\n+     git hash-object -t blob -w file_2 &&\n+     mv tmp ${pack}.idx &&\n+     git cat-file blob $blob_1 > /dev/null &&\n+     git cat-file blob $blob_2 > /dev/null &&\n+     git cat-file blob $blob_3 > /dev/null'\n+\n+test_expect_success \\\n+    'corruption in delta base reference of first delta (OBJ_OFS_DELTA)' \\\n+    'create_new_pack --delta-base-offset &&\n+     git prune-packed &&\n+     do_corrupt_object $blob_2 2 &&\n+     git cat-file blob $blob_1 > /dev/null &&\n+     test_must_fail git cat-file blob $blob_2 > /dev/null &&\n+     test_must_fail git cat-file blob $blob_3 > /dev/null'\n+\n+test_expect_success \\\n+    '... and a redundant pack allows for full recovery too' \\\n+    'mv ${pack}.idx tmp &&\n+     git hash-object -t blob -w file_1 &&\n+     git hash-object -t blob -w file_2 &&\n+     printf \"$blob_1\\n$blob_2\\n\" | git pack-objects .git/objects/pack/pack &&\n+     git prune-packed &&\n+     mv tmp ${pack}.idx &&\n+     git cat-file blob $blob_1 > /dev/null &&\n+     git cat-file blob $blob_2 > /dev/null &&\n+     git cat-file blob $blob_3 > /dev/null'\n+\n+test_done\n-- \n1.5.6.GIT\n"},{"id":"81143","messageId":"20080625164438.GA4039@steel.home","threadId":"14111","inReplyTo":"alpine.LFD.1.10.0806232123420.2979@xanadu.home","subject":"Fix t5303 (the test case for pack corruptions) on Windows","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2008-06-25T16:44:38Z","receivedAt":"2008-06-25T16:44:38Z","isPatch":false,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"The perldiag(1) has following to say about this:\n\n    \"Can't do inplace edit without backup\"\n\n\t(F) You're on a system such as MS-DOS that gets confused if\n\tyou try reading from a deleted (but still opened) file. You\n\thave to say -i.bak, or some such.\n\nSigned-off-by: Alex Riesen <raa.lkml@gmail.com>\n---\n\n t/t5303-pack-corruption-resilience.sh |    4 ++--\n 1 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/t/t5303-pack-corruption-resilience.sh b/t/t5303-pack-corruption-resilience.sh\nindex b0f5693..31b20b2 100755\n--- a/t/t5303-pack-corruption-resilience.sh\n+++ b/t/t5303-pack-corruption-resilience.sh\n@@ -90,7 +90,7 @@ test_expect_success \\\n     'create_new_pack &&\n      git prune-packed &&\n      chmod +w ${pack}.pack &&\n-     perl -i -pe \"s/ base /abcdef/\" ${pack}.pack &&\n+     perl -i.bak -pe \"s/ base /abcdef/\" ${pack}.pack &&\n      test_must_fail git cat-file blob $blob_1 > /dev/null &&\n      test_must_fail git cat-file blob $blob_2 > /dev/null &&\n      test_must_fail git cat-file blob $blob_3 > /dev/null'\n@@ -138,7 +138,7 @@ test_expect_success \\\n     'create_new_pack &&\n      git prune-packed &&\n      chmod +w ${pack}.pack &&\n-     perl -i -pe \"s/ delta1 /abcdefgh/\" ${pack}.pack &&\n+     perl -i.bak -pe \"s/ delta1 /abcdefgh/\" ${pack}.pack &&\n      git cat-file blob $blob_1 > /dev/null &&\n      test_must_fail git cat-file blob $blob_2 > /dev/null &&\n      test_must_fail git cat-file blob $blob_3 > /dev/null'\n-- \n1.5.6.28.g6f71b\n"},{"id":"81147","messageId":"7vskv11keo.fsf@gitster.siamese.dyndns.org","threadId":"14111","inReplyTo":"20080625164438.GA4039@steel.home","subject":"Re: Fix t5303 (the test case for pack corruptions) on Windows","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-06-25T17:42:07Z","receivedAt":"2008-06-25T17:42:07Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alex Riesen <raa.lkml@gmail.com> writes:\n\n> The perldiag(1) has following to say about this:\n>\n>     \"Can't do inplace edit without backup\"\n>\n> \t(F) You're on a system such as MS-DOS that gets confused if\n> \tyou try reading from a deleted (but still opened) file. You\n> \thave to say -i.bak, or some such.\n\nThanks.  By the way, there are others.\n\nt/t9106-git-svn-dcommit-clobber-series.sh:23:\t\tperl -i -p -e \"s/^58$/5588/\" file &&\nt/t9106-git-svn-dcommit-clobber-series.sh:24:\t\tperl -i -p -e \"s/^61$/6611/\" file &&\nt/t9106-git-svn-dcommit-clobber-series.sh:43:\tperl -i -p -e 's/^4\\$/4444/' file &&\nt/t9106-git-svn-dcommit-clobber-series.sh:44:\tperl -i -p -e 's/^7\\$/7777/' file &&\ntemplates/hooks--prepare-commit-msg.sample:25:    perl -i -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' \"$1\" ;;\ntemplates/hooks--prepare-commit-msg.sample:28:#   perl -i -pe '\n"},{"id":"81155","messageId":"20080625183513.GD4039@steel.home","threadId":"14111","inReplyTo":"7vskv11keo.fsf@gitster.siamese.dyndns.org","subject":"[PATCH] Fix t5303 (the test case for pack corruptions) on Windows","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2008-06-25T18:35:13Z","receivedAt":"2008-06-25T18:35:13Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"The perldiag(1) has following to say about this:\n\n    \"Can't do inplace edit without backup\"\n\n\t(F) You're on a system such as MS-DOS that gets confused if\n\tyou try reading from a deleted (but still opened) file. You\n\thave to say -i.bak, or some such.\n\nSigned-off-by: Alex Riesen <raa.lkml@gmail.com>\n---\n\nJunio C Hamano, Wed, Jun 25, 2008 19:42:07 +0200:\n> Alex Riesen <raa.lkml@gmail.com> writes:\n> \n> > The perldiag(1) has following to say about this:\n> >\n> >     \"Can't do inplace edit without backup\"\n> >\n> > \t(F) You're on a system such as MS-DOS that gets confused if\n> > \tyou try reading from a deleted (but still opened) file. You\n> > \thave to say -i.bak, or some such.\n> \n> Thanks.  By the way, there are others.\n> \n> t/t9106-git-svn-dcommit-clobber-series.sh:23:\t\tperl -i -p -e \"s/^58$/5588/\" file &&\n> t/t9106-git-svn-dcommit-clobber-series.sh:24:\t\tperl -i -p -e \"s/^61$/6611/\" file &&\n> t/t9106-git-svn-dcommit-clobber-series.sh:43:\tperl -i -p -e 's/^4\\$/4444/' file &&\n> t/t9106-git-svn-dcommit-clobber-series.sh:44:\tperl -i -p -e 's/^7\\$/7777/' file &&\n> templates/hooks--prepare-commit-msg.sample:25:    perl -i -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' \"$1\" ;;\n> templates/hooks--prepare-commit-msg.sample:28:#   perl -i -pe '\n\nOuch, I have the svn tests disabled, so I couldn't notice.\n\nFWIW, resending with the rest corrected.\n\n t/t5303-pack-corruption-resilience.sh      |    4 ++--\n t/t9106-git-svn-dcommit-clobber-series.sh  |    8 ++++----\n templates/hooks--prepare-commit-msg.sample |    4 ++--\n 3 files changed, 8 insertions(+), 8 deletions(-)\n\ndiff --git a/t/t5303-pack-corruption-resilience.sh b/t/t5303-pack-corruption-resilience.sh\nindex b0f5693..31b20b2 100755\n--- a/t/t5303-pack-corruption-resilience.sh\n+++ b/t/t5303-pack-corruption-resilience.sh\n@@ -90,7 +90,7 @@ test_expect_success \\\n     'create_new_pack &&\n      git prune-packed &&\n      chmod +w ${pack}.pack &&\n-     perl -i -pe \"s/ base /abcdef/\" ${pack}.pack &&\n+     perl -i.bak -pe \"s/ base /abcdef/\" ${pack}.pack &&\n      test_must_fail git cat-file blob $blob_1 > /dev/null &&\n      test_must_fail git cat-file blob $blob_2 > /dev/null &&\n      test_must_fail git cat-file blob $blob_3 > /dev/null'\n@@ -138,7 +138,7 @@ test_expect_success \\\n     'create_new_pack &&\n      git prune-packed &&\n      chmod +w ${pack}.pack &&\n-     perl -i -pe \"s/ delta1 /abcdefgh/\" ${pack}.pack &&\n+     perl -i.bak -pe \"s/ delta1 /abcdefgh/\" ${pack}.pack &&\n      git cat-file blob $blob_1 > /dev/null &&\n      test_must_fail git cat-file blob $blob_2 > /dev/null &&\n      test_must_fail git cat-file blob $blob_3 > /dev/null'\ndiff --git a/t/t9106-git-svn-dcommit-clobber-series.sh b/t/t9106-git-svn-dcommit-clobber-series.sh\nindex a400dc7..f8f4718 100755\n--- a/t/t9106-git-svn-dcommit-clobber-series.sh\n+++ b/t/t9106-git-svn-dcommit-clobber-series.sh\n@@ -20,8 +20,8 @@ test_expect_success '(supposedly) non-conflicting change from SVN' '\n \ttest x\"`sed -n -e 61p < file`\" = x61 &&\n \tsvn co \"$svnrepo\" tmp &&\n \tcd tmp &&\n-\t\tperl -i -p -e \"s/^58$/5588/\" file &&\n-\t\tperl -i -p -e \"s/^61$/6611/\" file &&\n+\t\tperl -i.bak -p -e \"s/^58$/5588/\" file &&\n+\t\tperl -i.bak -p -e \"s/^61$/6611/\" file &&\n \t\tpoke file &&\n \t\ttest x\"`sed -n -e 58p < file`\" = x5588 &&\n \t\ttest x\"`sed -n -e 61p < file`\" = x6611 &&\n@@ -40,8 +40,8 @@ test_expect_success 'some unrelated changes to git' \"\n test_expect_success 'change file but in unrelated area' \"\n \ttest x\\\"\\`sed -n -e 4p < file\\`\\\" = x4 &&\n \ttest x\\\"\\`sed -n -e 7p < file\\`\\\" = x7 &&\n-\tperl -i -p -e 's/^4\\$/4444/' file &&\n-\tperl -i -p -e 's/^7\\$/7777/' file &&\n+\tperl -i.bak -p -e 's/^4\\$/4444/' file &&\n+\tperl -i.bak -p -e 's/^7\\$/7777/' file &&\n \ttest x\\\"\\`sed -n -e 4p < file\\`\\\" = x4444 &&\n \ttest x\\\"\\`sed -n -e 7p < file\\`\\\" = x7777 &&\n \tgit commit -m '4 => 4444, 7 => 7777' file &&\ndiff --git a/templates/hooks--prepare-commit-msg.sample b/templates/hooks--prepare-commit-msg.sample\nindex aa42acf..3652424 100755\n--- a/templates/hooks--prepare-commit-msg.sample\n+++ b/templates/hooks--prepare-commit-msg.sample\n@@ -22,10 +22,10 @@\n \n case \"$2,$3\" in\n   merge,)\n-    perl -i -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' \"$1\" ;;\n+    perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' \"$1\" ;;\n \n # ,|template,)\n-#   perl -i -pe '\n+#   perl -i.bak -pe '\n #      print \"\\n\" . `git diff --cached --name-status -r`\n #\t if /^#/ && $first++ == 0' \"$1\" ;;\n \n-- \n1.5.6.91.geb23\n"}]}