{"thread":{"id":"1842","subject":"Fix archive-destroying \"git repack -a -d\" bug","startedAt":"2005-09-18T01:46:40Z","lastAt":"2005-09-18T17:26:30Z","messageCount":4,"participants":["Linus Torvalds","Dave Jones","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"8767","messageId":"Pine.LNX.4.58.0509171839590.26803@g5.osdl.org","threadId":"1842","inReplyTo":null,"subject":"Fix archive-destroying \"git repack -a -d\" bug","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-09-18T01:46:40Z","receivedAt":"2005-09-18T01:46:40Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nUsing \"git repack -a -d\" can destroy your git archive if you use it twice \nin succession.\n\nWhy? Because the new pack will be called the same as the old pack. And we \ndelete the old packs _after_ we've moved the new pack to the .git/objects/ \ndirectory, which means that we'll delete the new pack too!\n\nThis is a totally untested patch that may or may not fix this.\n\nSigned-off-by: Linus \"testing is for suckers\" Torvalds <torvalds@osdl.org>\n---\ndiff --git a/git-repack.sh b/git-repack.sh\n--- a/git-repack.sh\n+++ b/git-repack.sh\n@@ -31,10 +31,6 @@ case \",$all_into_one,\" in\n \trev_list=\n \trev_parse='--all'\n \tpack_objects=\n-\t# This part is a stop-gap until we have proper pack redundancy\n-\t# checker.\n-\texisting=`cd \"$PACKDIR\" && \\\n-\t    find . -type f \\( -name '*.pack' -o -name '*.idx' \\) -print`\n \t;;\n esac\n name=$(git-rev-list --objects $rev_list $(git-rev-parse $rev_parse) |\n@@ -54,8 +50,13 @@ exit\n \n if test \"$remove_redandant\" = t\n then\n+\t# This part is a stop-gap until we have proper pack redundancy\n+\t# checker.\n \t# We know $existing are all redandant only when\n \t# all-into-one is used.\n+\texisting=`cd \"$PACKDIR\" && \\\n+\t    find . -type f \\( -name '*.pack' -o -name '*.idx' \\) -print |\n+\t    grep -v $name`\n \tif test \"$all_into_one\" != '' && test \"$existing\" != ''\n \tthen\n \t\t( cd \"$PACKDIR\" && rm -f $existing )\n"},{"id":"8771","messageId":"20050918031837.GB23405@redhat.com","threadId":"1842","inReplyTo":"Pine.LNX.4.58.0509171839590.26803@g5.osdl.org","subject":"Re: Fix archive-destroying \"git repack -a -d\" bug","fromName":"Dave Jones","fromEmail":"davej@redhat.com","sentAt":"2005-09-18T03:18:37Z","receivedAt":"2005-09-18T03:18:37Z","isPatch":false,"sender":{"key":"davej@redhat.com","avatar":null},"body":"On Sat, Sep 17, 2005 at 06:46:40PM -0700, Linus Torvalds wrote:\n > \n > Using \"git repack -a -d\" can destroy your git archive if you use it twice \n > in succession.\n > \n > Why? Because the new pack will be called the same as the old pack. And we \n > delete the old packs _after_ we've moved the new pack to the .git/objects/ \n > directory, which means that we'll delete the new pack too!\n\nHmm, I'm sure I've done this several times in my x86info git repo\n(http://www.codemonkey.org.uk/projects/x86info/x86info.git)\n\nIt seems to look ok to git-fsck-cache though. Would that pick up\nany breakage if present ?\n\nRunning git-whatchanged, the history seems to go all the way\nback to the beginning of its cvs doppelganger.\n\n\t\tDave\n"},{"id":"8782","messageId":"Pine.LNX.4.58.0509180958310.26803@g5.osdl.org","threadId":"1842","inReplyTo":"20050918031837.GB23405@redhat.com","subject":"Re: Fix archive-destroying \"git repack -a -d\" bug","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-09-18T17:00:28Z","receivedAt":"2005-09-18T17:00:28Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Sat, 17 Sep 2005, Dave Jones wrote:\n> \n> Hmm, I'm sure I've done this several times in my x86info git repo\n> (http://www.codemonkey.org.uk/projects/x86info/x86info.git)\n> \n> It seems to look ok to git-fsck-cache though. Would that pick up\n> any breakage if present ?\n\nIt will literally remove every single object in the system, so yes, there \nwould be major breakage. Even \"git log\" won't work.\n\nNote: this only happens if you haven't done _anything_ in between repacks. \nIf you commit anything or do anything else to cause the list of objects to \nchange, \"git repack\" is fine.\n\n\t\t\tLinus\n"},{"id":"8786","messageId":"7v4q8i5ltl.fsf@assigned-by-dhcp.cox.net","threadId":"1842","inReplyTo":"20050918031837.GB23405@redhat.com","subject":"Re: Fix archive-destroying \"git repack -a -d\" bug","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-09-18T17:26:30Z","receivedAt":"2005-09-18T17:26:30Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Dave Jones <davej@redhat.com> writes:\n\n> Hmm, I'm sure I've done this several times in my x86info git repo\n> (http://www.codemonkey.org.uk/projects/x86info/x86info.git)\n>\n> It seems to look ok to git-fsck-cache though. Would that pick up\n> any breakage if present ?\n\nYes.  This is a real bug and I owe Linus big for spotting it\nbefore 0.99.7.\n"}]}