{"thread":{"id":"5430","subject":"git-fsck-objects: lacking default references should not be fatal","startedAt":"2006-08-29T18:47:30Z","lastAt":"2006-08-29T18:47:30Z","messageCount":1,"participants":["Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"26099","messageId":"Pine.LNX.4.64.0608291141140.27779@g5.osdl.org","threadId":"5430","inReplyTo":null,"subject":"git-fsck-objects: lacking default references should not be fatal","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-08-29T18:47:30Z","receivedAt":"2006-08-29T18:47:30Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nThe comment added says it all: if we have lost all references in a git \narchive, git-fsck-objects should still work, so instead of dying it should \njust notify the user about that condition.\n\nThis change was triggered by me just doing a \"git-init-db\" and then \npopulating that empty git archive with a pack/index file to look at it. \nHaving git-fsck-objects not work just because I didn't have any references \nhandy was rather irritating, since part of the reason for running \ngit-fsck-objects in the first place was to _find_ the missing references.\n\nHowever, \"--unreachable\" really doesn't make sense in that situation, and \nwe want to turn it off to protect anybody who uses the old \"git prune\" \nshell-script (rather than the modern built-in). The old pruning script \nused to remove all objects that were reported as unreachable, and without \nany refs, that obviously means everything - not worth it.\n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n---\n\ndiff --git a/fsck-objects.c b/fsck-objects.c\nindex ae0ec8d..24286de 100644\n--- a/fsck-objects.c\n+++ b/fsck-objects.c\n@@ -425,8 +425,23 @@ static int fsck_handle_ref(const char *r\n static void get_default_heads(void)\n {\n \tfor_each_ref(fsck_handle_ref);\n-\tif (!default_refs)\n-\t\tdie(\"No default references\");\n+\n+\t/*\n+\t * Not having any default heads isn't really fatal, but\n+\t * it does mean that \"--unreachable\" no longer makes any\n+\t * sense (since in this case everything will obviously\n+\t * be unreachable by definition.\n+\t *\n+\t * Showing dangling objects is valid, though (as those\n+\t * dangling objects are likely lost heads).\n+\t *\n+\t * So we just print a warning about it, and clear the\n+\t * \"show_unreachable\" flag.\n+\t */\n+\tif (!default_refs) {\n+\t\terror(\"No default references\");\n+\t\tshow_unreachable = 0;\n+\t}\n }\n \n static void fsck_object_dir(const char *path)\n"}]}