{"thread":{"id":"448","subject":"[PATCH] Git-prune-script loses blobs referenced from an uncommitted cache.","startedAt":"2005-05-03T00:37:16Z","lastAt":"2005-05-03T02:56:11Z","messageCount":2,"participants":["Junio C Hamano","Linus Torvalds"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"2424","messageId":"7vis21no03.fsf@assigned-by-dhcp.cox.net","threadId":"448","inReplyTo":null,"subject":"[PATCH] Git-prune-script loses blobs referenced from an uncommitted cache.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-03T00:37:16Z","receivedAt":"2005-05-03T00:37:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"When a new blob is registered with update-cache, and before the cache\nis written as a tree and committed, git-fsck-cache will find the blob\nunreachable.  This patch fixes git-prune-script to keep such blob objects\nreferenced from the cache.\n\nWithout this fix, \"diff-cache -p --cached\" after git-prune-script has\npruned the blob object will fail mysteriously and git-write-tree would\nalso fail.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\ngit-prune-script |   32 +++++++++++++++++++++++++++++++-\n1 files changed, 31 insertions(+), 1 deletion(-)\n\n--- a/git-prune-script\n+++ b/git-prune-script\n@@ -1,2 +1,32 @@\n #!/bin/sh\n-git-fsck-cache --unreachable $(cat .git/HEAD ) | grep unreachable | cut -d' ' -f3 | sed 's:^\\(..\\):.git/objects/\\1/:' | xargs rm\n+\n+tmp=.git-prune-script-$$\n+trap \"rm -f $tmp-*\" 0 1 2 3 15 \n+\n+# Defaulting to include .git/refs/*/* may be debatable from the\n+# purist POV but power users can always give explicit parameters\n+# to the script anyway.\n+case \"$#\" in\n+0) set x $(cat .git/HEAD .git/refs/*/*); shift ;;\n+esac\n+\n+git-fsck-cache --unreachable \"$@\" |\n+sed -ne 's/unreachable [^ ][^ ]* //p' |\n+sort >$tmp-unreachable\n+\n+# This makes extra objects to be kept if the cache has an entry\n+# with an unusual name like \"this\\n0 0123...abcdef 0 file\", but\n+# we are trying not to discard information and keeping extra in\n+# an unusual situation would be OK.\n+git-ls-files --stage |\n+sed -ne 's|^[0-7][0-7]* \\([0-9a-f][0-9a-f]*\\) [0-3] .*|\\1|p' |\n+sort >$tmp-keep\n+\n+comm -23 $tmp-unreachable $tmp-keep |\n+sed -e 's|\\(..\\)|\\1/|' | {\n+\tcase \"$SHA1_FILE_DIRECTORY\" in\n+\t'') cd .git/objects/ ;;\n+\t*) cd \"$SHA1_FILE_DIRECTORY\" ;;\n+\tesac || exit\n+\txargs -r echo rm -f\n+}\n\n"},{"id":"2435","messageId":"Pine.LNX.4.58.0505021953160.3594@ppc970.osdl.org","threadId":"448","inReplyTo":"7vis21no03.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Git-prune-script loses blobs referenced from an uncommitted cache.","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-05-03T02:56:11Z","receivedAt":"2005-05-03T02:56:11Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Mon, 2 May 2005, Junio C Hamano wrote:\n>\n> When a new blob is registered with update-cache, and before the cache\n> is written as a tree and committed, git-fsck-cache will find the blob\n> unreachable.  This patch fixes git-prune-script to keep such blob objects\n> referenced from the cache.\n\nActually, I'd almost rather just have git-fsck-cache actually do a\n\"read_cache()\" and walk through that and marking the sha1's as \"needed\".\n\nThat's useful for another reason: not only does it mean that we don't drop \nobjects that may be in the current index, but it _also_ means that we \ncheck that the current index actually has everything that it needs. I had \nthat situation a few times after I did a \"convert-cache\" - where I had an \nold index file that pointed to the old objects _before_ the conversion.\n\nI noticed it the hard way, and happily it's easily fixed by just doing a \n\"git-read-cache <new-head>\", but it was actually very confusing when it \nhappened, and it would have been good to have fsck-cache warn about it.\n\n\t\tLinus\n"}]}