{"thread":{"id":"4667","subject":"git-repack -a -d produces unusable packs with 1.4.0","startedAt":"2006-06-25T11:35:22Z","lastAt":"2006-06-25T12:23:52Z","messageCount":2,"participants":["Thomas Glanzmann","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"22548","messageId":"20060625113522.GC19210@cip.informatik.uni-erlangen.de","threadId":"4667","inReplyTo":null,"subject":"git-repack -a -d produces unusable packs with 1.4.0","fromName":"Thomas Glanzmann","fromEmail":"sithglan@stud.uni-erlangen.de","sentAt":"2006-06-25T11:35:22Z","receivedAt":"2006-06-25T11:35:22Z","isPatch":false,"sender":{"key":"sithglan@stud.uni-erlangen.de","avatar":null},"body":"Hello everyone,\nwhat on earth is going wrong here (this is with 1.4.0):\n\n        (node01) [~] git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git\n        Checking files out...)\n        100% (19830/19830) done\n        (node01) [~] cd linux-2.6/\n        (node01) [~/linux-2.6] git repack -a -d\n        Generating pack...\n        Done counting 263175 objects.\n        Deltifying 263175 objects.\n        100% (263175/263175) done\n        Writing 263175 objects.\n        100% (263175/263175) done\n        Total 263175, written 263175 (delta 206825), reused 262943 (delta 206593)\n        Pack pack-ce49d2efd5af06ed6093049050b5ba41da8b683f created.\n        mv: overwrite `.git/objects/pack/pack-ce49d2efd5af06ed6093049050b5ba41da8b683f.pack', overriding mode 0444? y\n        mv: overwrite `.git/objects/pack/pack-ce49d2efd5af06ed6093049050b5ba41da8b683f.idx', overriding mode 0444? y\n        fatal: packfile .git/objects/pack/pack-ce49d2efd5af06ed6093049050b5ba41da8b683f.pack does not match index.\n        (node01) [~/linux-2.6] git repack -a -d\n        Generating pack...\n        fatal: expected sha1, got garbage:\n        fatal: packfile .git/objects/pack/pack-ce49d2efd5af06ed6093049050b5ba41da8b683f.pack does not match index.\n\nOh and are there localized git mirrors like for example\ngit.de.kernel.org or is the git protocoll only available from the\nprimary site?\n\n        Thomas\n"},{"id":"22552","messageId":"7vbqshtodj.fsf@assigned-by-dhcp.cox.net","threadId":"4667","inReplyTo":"20060625113522.GC19210@cip.informatik.uni-erlangen.de","subject":"Re: git-repack -a -d produces unusable packs with 1.4.0","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-06-25T12:23:52Z","receivedAt":"2006-06-25T12:23:52Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thomas Glanzmann <sithglan@stud.uni-erlangen.de> writes:\n\n>         Pack pack-ce49d2efd5af06ed6093049050b5ba41da8b683f created.\n>         mv: overwrite `.git/objects/pack/pack-ce49d2efd5af06ed6093049050b5ba41da8b683f.pack', overriding mode 0444? y\n>         mv: overwrite `.git/objects/pack/pack-ce49d2efd5af06ed6093049050b5ba41da8b683f.idx', overriding mode 0444? y\n>         fatal: packfile .git/objects/pack/pack-ce49d2efd5af06ed6093049050b5ba41da8b683f.pack does not match index.\n\nI would understand if you answer 'y' to one but 'n' to the other\nit would result in a situation with unmatching .pack and .idx\nand you would see something like the above (by the way, the\n\"fatal\" is coming from update-server-info that tries to read\nfrom freshly moved packfiles); but the above is different, so it\ndoes not explain the symptom.  I am worried and curious as to\nwhat happened, since you are answering 'y' to both of them.\nThis would trigger immediately after a clone which creates pack\nand idx unwritable; repack leaves the results writable unless\nyour umask is 0222, so \"mv\" would not even ask the silly\nquestions.\n\nDid you happen to have .tmp-pack-ce49d2ef... at the project root\nlevel after this failure?  If so which one (either .pack or .idx)?\n\nIf you had .tmp-pack-*.pack then .git/objects/pack/pack-ce49...pack\nis from the old round and .git/objects/pack/pack-ce49...idx is\nfrom the new one.  Moving .tmp-pack-* to .git/objects/pack/pack-*\nwould hopefully solve this problem.\n\nNevertheless, this _is_ a dangerous and grave bug, and thanks\nfor reporting it.\n\nMaybe we would want to do something like this:\n\n-- >8 --\ngit-repack: Be careful when updating the same pack as existing one.\n\nAfter clone, packfiles are read-only by default and \"mv\" went\ninteractive asking if the user wants to replace it with a\nrepacked copy.  If one is successfully moved and the other is\nnot, the pack and its idx would become out-of-sync and corrupts\nthe repository.\n\nRecovering is straightforward -- it is just the matter of\nfinding the remaining .tmp-pack-* and make sure they are both\nmoved -- but we should be extra careful not to do something so\nalarming to the users.\n\n---\ndiff --git a/git-repack.sh b/git-repack.sh\nindex eb75c8c..b58cf91 100755\n--- a/git-repack.sh\n+++ b/git-repack.sh\n@@ -54,9 +54,21 @@ else\n \tfi\n \tmkdir -p \"$PACKDIR\" || exit\n \n-\tmv .tmp-pack-$name.pack \"$PACKDIR/pack-$name.pack\" &&\n-\tmv .tmp-pack-$name.idx  \"$PACKDIR/pack-$name.idx\" ||\n-\texit\n+\tfor sfx in pack idx\n+\tdo\n+\t\tif test -f \"$PACKDIR/pack-$name.$sfx\"\n+\t\tthen\n+\t\t\tmv -f \"$PACKDIR/pack-$name.$sfx\" \"$PACKDIR/old-pack-$name.$sfx\"\n+\t\tfi\n+\tdone\n+\tmv -f .tmp-pack-$name.pack \"$PACKDIR/pack-$name.pack\" &&\n+\tmv -f .tmp-pack-$name.idx  \"$PACKDIR/pack-$name.idx\" || {\n+\t\techo >&2 \"Couldn't replace the existing pack with updated one.\"\n+\t\techo >&2 \"The original set of packs have been saved as\"\n+\t\techo >&2 \"old-pack-$name.{pack,idx} in $PACKDIR.\"\n+\t\texit 1\n+\t}\n+\trm -f \"$PACKDIR/old-pack-$name.pack\" \"$PACKDIR/old-pack-$name.idx\" \n fi\n \n if test \"$remove_redundant\" = t\n"}]}