{"thread":{"id":"2256","subject":"Be marginally more careful about removing objects","startedAt":"2005-10-28T16:45:53Z","lastAt":"2005-10-28T16:45:53Z","messageCount":1,"participants":["Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"10760","messageId":"Pine.LNX.4.64.0510280935130.4664@g5.osdl.org","threadId":"2256","inReplyTo":null,"subject":"Be marginally more careful about removing objects","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-10-28T16:45:53Z","receivedAt":"2005-10-28T16:45:53Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nThe git philosophy when it comes to disk accesses is \"Laugh in the face of \ndanger\".\n\nNotably, since we never modify an existing object, we don't really care \nthat deeply about flushing things to disk, since even if the machine \ncrashes in the middle of a git operation, you can never really have lost \nany old work. At most, you'd need to figure out the proper heads (which \ngit-fsck-objects can do for you) and re-do the operation.\n\nHowever, there's two exceptions to this: pruning and repacking. Those \noperations will actually _delete_ old objects that they know about in \nother ways (ie that they just repacked, or that they have found in other \nplaces).\n\nHowever, since they actually modify old state, we should thus be a bit \nmore careful about them. If the machine crashes and the duplicate new \nobjects haven't been flushed to disk, you can actually be in trouble.\n\nThis is trivially stupid about it by calling \"sync\" before removing the \nobjects. Not very smart, but we're talking about special operations than \nare usually done once a week if that.\n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n---\ndiff --git a/git-prune.sh b/git-prune.sh\nindex b28630c..ef31bd2 100755\n--- a/git-prune.sh\n+++ b/git-prune.sh\n@@ -15,6 +15,7 @@ do\n     shift;\n done\n \n+sync\n git-fsck-objects --full --cache --unreachable \"$@\" |\n sed -ne '/unreachable /{\n     s/unreachable [^ ][^ ]* //\ndiff --git a/git-repack.sh b/git-repack.sh\nindex 49547a7..d341966 100755\n--- a/git-repack.sh\n+++ b/git-repack.sh\n@@ -62,6 +62,7 @@ then\n \t# all-into-one is used.\n \tif test \"$all_into_one\" != '' && test \"$existing\" != ''\n \tthen\n+\t\tsync\n \t\t( cd \"$PACKDIR\" &&\n \t\t  for e in $existing\n \t\t  do\ndiff --git a/prune-packed.c b/prune-packed.c\nindex 16685d1..26123f7 100644\n--- a/prune-packed.c\n+++ b/prune-packed.c\n@@ -71,6 +71,7 @@ int main(int argc, char **argv)\n \t\t/* Handle arguments here .. */\n \t\tusage(prune_packed_usage);\n \t}\n+\tsync();\n \tprune_packed_objects();\n \treturn 0;\n }\n"}]}