{"thread":{"id":"12872","subject":"[PATCH] fsck --lost-found: show found commits human readably","startedAt":"2008-03-26T06:45:47Z","lastAt":"2008-03-28T14:08:26Z","messageCount":4,"participants":["Junio C Hamano","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"73120","messageId":"7vbq52gezo.fsf@gitster.siamese.dyndns.org","threadId":"12872","inReplyTo":null,"subject":"[PATCH] fsck --lost-found: show found commits human readably","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-03-26T06:45:47Z","receivedAt":"2008-03-26T06:45:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"An earlier commit fc8b5f0 (Deprecate git-lost-found, 2007-11-08) declared\n\"lost-found\" deprecated, because \"fsck\" learned \"--lost-found\" option that\ndrops the found objects in $GIT_DIR/lost-found.\n\nBut the output from the lost-found program has been much more informative\nthan the plain vanilla \"git fsck\" (or \"git fsck --lost-found\") output.  In\nthat sense, forcing users to use \"fsck --lost-found\" when they want to use\n\"lost-found\" is a regression.\n\nThis patch slightly enhances the output from \"fsck --lost-found\" to add\noneline description at the end of the usual \"dangling <type> <sha-1>\"\nmessage for commit objects it found.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * Is it just me, or were we very sloppy during 1.5.4 cycle that we are\n   getting hit by regressions left and right today from that period?\n\n   This looks bigger than it really is because most of it is about\n   moving a deeply nested part of another function into a separate\n   function.\n\n   This is _not_ a 1.5.5 material, as we are not removing git-lost-found\n   yet.  We might however want to revert fc8b5f0, though, until an\n   enhancement along this line is in the mainline.\n\n builtin-fsck.c |   94 ++++++++++++++++++++++++++++++++++++++------------------\n 1 files changed, 64 insertions(+), 30 deletions(-)\n\ndiff --git a/builtin-fsck.c b/builtin-fsck.c\nindex 78a6e1f..b57cc78 100644\n--- a/builtin-fsck.c\n+++ b/builtin-fsck.c\n@@ -145,6 +145,68 @@ static void check_reachable_object(struct object *obj)\n \t}\n }\n \n+static void dangling_object(struct object *obj)\n+{\n+\tchar *filename;\n+\tFILE *f;\n+\tenum object_type type;\n+\tunsigned long size;\n+\tchar *buf = NULL;\n+\n+\tif (!write_lost_and_found)\n+\t\tgoto report_and_exit;\n+\n+\tfilename = git_path(\"lost-found/%s/%s\",\n+\t\t\t    obj->type == OBJ_COMMIT ? \"commit\" : \"other\",\n+\t\t\t    sha1_to_hex(obj->sha1));\n+\n+\tif (safe_create_leading_directories(filename)) {\n+\t\terror(\"Could not create lost-found\");\n+\t\treturn;\n+\t}\n+\tif (!(f = fopen(filename, \"w\")))\n+\t\tdie(\"Could not open %s\", filename);\n+\tif (obj->type == OBJ_BLOB || obj->type == OBJ_COMMIT)\n+\t\tbuf = read_sha1_file(obj->sha1, &type, &size);\n+\n+\tif (obj->type == OBJ_BLOB) {\n+\t\tif (buf) {\n+\t\t\tfwrite(buf, size, 1, f);\n+\t\t\tfree(buf);\n+\t\t}\n+\t} else\n+\t\tfprintf(f, \"%s\\n\", sha1_to_hex(obj->sha1));\n+\tfclose(f);\n+\n+\tif (obj->type == OBJ_COMMIT) {\n+\t\tstruct strbuf sb = STRBUF_INIT;\n+\t\tstruct commit *commit = lookup_commit(obj->sha1);\n+\t\tint reported = 0;\n+\n+\t\tif (!commit->buffer)\n+\t\t\tcommit->buffer = buf;\n+\t\tif (commit->buffer) {\n+\t\t\tparse_commit(commit);\n+\t\t\tpretty_print_commit(CMIT_FMT_ONELINE, commit, &sb,\n+\t\t\t\t\t    0, NULL, NULL, 0, 0);\n+\t\t\tprintf(\"dangling commit %s (%s)\\n\",\n+\t\t\t       sha1_to_hex(obj->sha1), sb.buf);\n+\t\t\treported = 1;\n+\t\t}\n+\t\tstrbuf_release(&sb);\n+\t\tfree(commit->buffer);\n+\t\tif (buf && commit->buffer != buf)\n+\t\t\tfree(buf);\n+\t\tcommit->buffer = NULL;\n+\t\tif (reported)\n+\t\t\treturn;\n+\t}\n+\n+ report_and_exit:\n+\tprintf(\"dangling %s %s\\n\", typename(obj->type),\n+\t       sha1_to_hex(obj->sha1));\n+}\n+\n /*\n  * Check a single unreachable object\n  */\n@@ -180,36 +242,8 @@ static void check_unreachable_object(struct object *obj)\n \t * deleted a branch by mistake, this is a prime candidate to\n \t * start looking at, for example.\n \t */\n-\tif (!obj->used) {\n-\t\tprintf(\"dangling %s %s\\n\", typename(obj->type),\n-\t\t       sha1_to_hex(obj->sha1));\n-\t\tif (write_lost_and_found) {\n-\t\t\tchar *filename = git_path(\"lost-found/%s/%s\",\n-\t\t\t\tobj->type == OBJ_COMMIT ? \"commit\" : \"other\",\n-\t\t\t\tsha1_to_hex(obj->sha1));\n-\t\t\tFILE *f;\n-\n-\t\t\tif (safe_create_leading_directories(filename)) {\n-\t\t\t\terror(\"Could not create lost-found\");\n-\t\t\t\treturn;\n-\t\t\t}\n-\t\t\tif (!(f = fopen(filename, \"w\")))\n-\t\t\t\tdie(\"Could not open %s\", filename);\n-\t\t\tif (obj->type == OBJ_BLOB) {\n-\t\t\t\tenum object_type type;\n-\t\t\t\tunsigned long size;\n-\t\t\t\tchar *buf = read_sha1_file(obj->sha1,\n-\t\t\t\t\t\t&type, &size);\n-\t\t\t\tif (buf) {\n-\t\t\t\t\tfwrite(buf, size, 1, f);\n-\t\t\t\t\tfree(buf);\n-\t\t\t\t}\n-\t\t\t} else\n-\t\t\t\tfprintf(f, \"%s\\n\", sha1_to_hex(obj->sha1));\n-\t\t\tfclose(f);\n-\t\t}\n-\t\treturn;\n-\t}\n+\tif (!obj->used)\n+\t\tdangling_object(obj);\n \n \t/*\n \t * Otherwise? It's there, it's unreachable, and some other unreachable\n"},{"id":"73263","messageId":"alpine.LSU.1.00.0803281504591.18259@racer.site","threadId":"12872","inReplyTo":"7vbq52gezo.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] fsck --lost-found: show found commits human readably","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-28T14:05:23Z","receivedAt":"2008-03-28T14:05:23Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nI split your patch into two logical entities.  Will send as a reply.\n\nCiao,\nDscho\n"},{"id":"73264","messageId":"alpine.LSU.1.00.0803281505330.18259@racer.site","threadId":"12872","inReplyTo":"alpine.LSU.1.00.0803281504591.18259@racer.site","subject":"[PATCH 1/2] fsck --lost-found: refactor handling of dangling objects","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-28T14:05:46Z","receivedAt":"2008-03-28T14:05:46Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nFrom: Junio C Hamano <gitster@pobox.com>\n\nThis moves a deeply nested part of the function\ncheck_unreachable_object() into a separate function.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n builtin-fsck.c |   65 ++++++++++++++++++++++++++++++-------------------------\n 1 files changed, 35 insertions(+), 30 deletions(-)\n\ndiff --git a/builtin-fsck.c b/builtin-fsck.c\nindex 78a6e1f..f01263a 100644\n--- a/builtin-fsck.c\n+++ b/builtin-fsck.c\n@@ -145,6 +145,39 @@ static void check_reachable_object(struct object *obj)\n \t}\n }\n \n+static void dangling_object(struct object *obj)\n+{\n+\tchar *filename;\n+\tFILE *f;\n+\tprintf(\"dangling %s %s\\n\", typename(obj->type),\n+\t\t\tsha1_to_hex(obj->sha1));\n+\tif (!write_lost_and_found)\n+\t\treturn;\n+\n+\tfilename = git_path(\"lost-found/%s/%s\",\n+\t\t\t    obj->type == OBJ_COMMIT ? \"commit\" : \"other\",\n+\t\t\t    sha1_to_hex(obj->sha1));\n+\n+\tif (safe_create_leading_directories(filename)) {\n+\t\terror(\"Could not create lost-found\");\n+\t\treturn;\n+\t}\n+\tif (!(f = fopen(filename, \"w\")))\n+\t\tdie(\"Could not open %s\", filename);\n+\tif (obj->type == OBJ_BLOB) {\n+\t\tenum object_type type;\n+\t\tunsigned long size;\n+\t\tchar *buf = read_sha1_file(obj->sha1,\n+\t\t\t\t&type, &size);\n+\t\tif (buf) {\n+\t\t\tfwrite(buf, size, 1, f);\n+\t\t\tfree(buf);\n+\t\t}\n+\t} else\n+\t\tfprintf(f, \"%s\\n\", sha1_to_hex(obj->sha1));\n+\tfclose(f);\n+}\n+\n /*\n  * Check a single unreachable object\n  */\n@@ -180,36 +213,8 @@ static void check_unreachable_object(struct object *obj)\n \t * deleted a branch by mistake, this is a prime candidate to\n \t * start looking at, for example.\n \t */\n-\tif (!obj->used) {\n-\t\tprintf(\"dangling %s %s\\n\", typename(obj->type),\n-\t\t       sha1_to_hex(obj->sha1));\n-\t\tif (write_lost_and_found) {\n-\t\t\tchar *filename = git_path(\"lost-found/%s/%s\",\n-\t\t\t\tobj->type == OBJ_COMMIT ? \"commit\" : \"other\",\n-\t\t\t\tsha1_to_hex(obj->sha1));\n-\t\t\tFILE *f;\n-\n-\t\t\tif (safe_create_leading_directories(filename)) {\n-\t\t\t\terror(\"Could not create lost-found\");\n-\t\t\t\treturn;\n-\t\t\t}\n-\t\t\tif (!(f = fopen(filename, \"w\")))\n-\t\t\t\tdie(\"Could not open %s\", filename);\n-\t\t\tif (obj->type == OBJ_BLOB) {\n-\t\t\t\tenum object_type type;\n-\t\t\t\tunsigned long size;\n-\t\t\t\tchar *buf = read_sha1_file(obj->sha1,\n-\t\t\t\t\t\t&type, &size);\n-\t\t\t\tif (buf) {\n-\t\t\t\t\tfwrite(buf, size, 1, f);\n-\t\t\t\t\tfree(buf);\n-\t\t\t\t}\n-\t\t\t} else\n-\t\t\t\tfprintf(f, \"%s\\n\", sha1_to_hex(obj->sha1));\n-\t\t\tfclose(f);\n-\t\t}\n-\t\treturn;\n-\t}\n+\tif (!obj->used)\n+\t\tdangling_object(obj);\n \n \t/*\n \t * Otherwise? It's there, it's unreachable, and some other unreachable\n-- \n1.5.5.rc2.186.gbac51\n"},{"id":"73265","messageId":"alpine.LSU.1.00.0803281505510.18259@racer.site","threadId":"12872","inReplyTo":"alpine.LSU.1.00.0803281504591.18259@racer.site","subject":"[PATCH 2/2] fsck --lost-found: show found commits human readably","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-28T14:08:26Z","receivedAt":"2008-03-28T14:08:26Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Junio C Hamano <gitster@pobox.com>\n\nAn earlier commit fc8b5f0 (Deprecate git-lost-found, 2007-11-08) declared\n\"lost-found\" deprecated, because \"fsck\" learned \"--lost-found\" option that\ndrops the found objects in $GIT_DIR/lost-found.\n\nBut the output from the lost-found program has been much more informative\nthan the plain vanilla \"git fsck\" (or \"git fsck --lost-found\") output.  In\nthat sense, forcing users to use \"fsck --lost-found\" when they want to use\n\"lost-found\" is a regression.\n\nThis patch slightly enhances the output from \"fsck --lost-found\" to add\noneline description at the end of the usual \"dangling <type> <sha-1>\"\nmessage for commit objects it found.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tAs for the deprecation of lost-found, I think it is correct, and \n\tshould not be reverted.  We _do_ have way too many commands, and \n\tlost-found logically _belongs_ into fsck.  The proper fix is to \n\tfix fsck --lost-found.\n\n\tNow, I did not yet look closely at the output of \n\tgit-lost-found.sh, as I already switched to \"master\" in the hope \n\tthat 1.5.5-rc2 will be almost identical to 1.5.5, and I fully \n\tintend to push for a quick release (after the pending \"fetch\" \n\tresolutions).\n\n\tAfter 1.5.5, I will tend to lost-found.\n\n builtin-fsck.c |   43 ++++++++++++++++++++++++++++++++++++-------\n 1 files changed, 36 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin-fsck.c b/builtin-fsck.c\nindex f01263a..b57cc78 100644\n--- a/builtin-fsck.c\n+++ b/builtin-fsck.c\n@@ -149,10 +149,12 @@ static void dangling_object(struct object *obj)\n {\n \tchar *filename;\n \tFILE *f;\n-\tprintf(\"dangling %s %s\\n\", typename(obj->type),\n-\t\t\tsha1_to_hex(obj->sha1));\n+\tenum object_type type;\n+\tunsigned long size;\n+\tchar *buf = NULL;\n+\n \tif (!write_lost_and_found)\n-\t\treturn;\n+\t\tgoto report_and_exit;\n \n \tfilename = git_path(\"lost-found/%s/%s\",\n \t\t\t    obj->type == OBJ_COMMIT ? \"commit\" : \"other\",\n@@ -164,11 +166,10 @@ static void dangling_object(struct object *obj)\n \t}\n \tif (!(f = fopen(filename, \"w\")))\n \t\tdie(\"Could not open %s\", filename);\n+\tif (obj->type == OBJ_BLOB || obj->type == OBJ_COMMIT)\n+\t\tbuf = read_sha1_file(obj->sha1, &type, &size);\n+\n \tif (obj->type == OBJ_BLOB) {\n-\t\tenum object_type type;\n-\t\tunsigned long size;\n-\t\tchar *buf = read_sha1_file(obj->sha1,\n-\t\t\t\t&type, &size);\n \t\tif (buf) {\n \t\t\tfwrite(buf, size, 1, f);\n \t\t\tfree(buf);\n@@ -176,6 +177,34 @@ static void dangling_object(struct object *obj)\n \t} else\n \t\tfprintf(f, \"%s\\n\", sha1_to_hex(obj->sha1));\n \tfclose(f);\n+\n+\tif (obj->type == OBJ_COMMIT) {\n+\t\tstruct strbuf sb = STRBUF_INIT;\n+\t\tstruct commit *commit = lookup_commit(obj->sha1);\n+\t\tint reported = 0;\n+\n+\t\tif (!commit->buffer)\n+\t\t\tcommit->buffer = buf;\n+\t\tif (commit->buffer) {\n+\t\t\tparse_commit(commit);\n+\t\t\tpretty_print_commit(CMIT_FMT_ONELINE, commit, &sb,\n+\t\t\t\t\t    0, NULL, NULL, 0, 0);\n+\t\t\tprintf(\"dangling commit %s (%s)\\n\",\n+\t\t\t       sha1_to_hex(obj->sha1), sb.buf);\n+\t\t\treported = 1;\n+\t\t}\n+\t\tstrbuf_release(&sb);\n+\t\tfree(commit->buffer);\n+\t\tif (buf && commit->buffer != buf)\n+\t\t\tfree(buf);\n+\t\tcommit->buffer = NULL;\n+\t\tif (reported)\n+\t\t\treturn;\n+\t}\n+\n+ report_and_exit:\n+\tprintf(\"dangling %s %s\\n\", typename(obj->type),\n+\t       sha1_to_hex(obj->sha1));\n }\n \n /*\n-- \n1.5.5.rc2.186.gbac51\n"}]}