{"thread":{"id":"8812","subject":"[PATCH] git-fsck: add --lost-found option","startedAt":"2007-07-02T16:53:43Z","lastAt":"2007-07-04T01:41:15Z","messageCount":7,"participants":["Johannes Schindelin","Junio C Hamano","Jonas Fonseca"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"46255","messageId":"Pine.LNX.4.64.0707021751380.4071@racer.site","threadId":"8812","inReplyTo":null,"subject":"[PATCH] git-fsck: add --lost-found option","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-02T16:53:43Z","receivedAt":"2007-07-02T16:53:43Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nWith this option, dangling objects are not only reported, but also\nwritten to .git/lost-found/commit/ or .git/lost-found/other/.\n\nThis obsoletes git-lost-found.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tEven adding a test script, and changing C code, this removes more \n\tlines than it adds...\n\n\tSomething we might want to do, however, is to add a warning if the \n\tuser said --lost-found without --no-reflogs.\n\n Documentation/cmd-list.perl      |    1 -\n Documentation/git-fsck.txt       |    6 ++-\n Documentation/git-lost-found.txt |   77 --------------------------------------\n Makefile                         |    2 +-\n builtin-fsck.c                   |   20 ++++++++++\n t/t1420-lost-found.sh            |   35 +++++++++++++++++\n 6 files changed, 61 insertions(+), 80 deletions(-)\n delete mode 100644 Documentation/git-lost-found.txt\n create mode 100755 t/t1420-lost-found.sh\n\ndiff --git a/Documentation/cmd-list.perl b/Documentation/cmd-list.perl\nindex f50f613..9cae338 100755\n--- a/Documentation/cmd-list.perl\n+++ b/Documentation/cmd-list.perl\n@@ -123,7 +123,6 @@ git-instaweb                            ancillaryinterrogators\n gitk                                    mainporcelain\n git-local-fetch                         synchingrepositories\n git-log                                 mainporcelain\n-git-lost-found                          ancillarymanipulators\n git-ls-files                            plumbinginterrogators\n git-ls-remote                           plumbinginterrogators\n git-ls-tree                             plumbinginterrogators\ndiff --git a/Documentation/git-fsck.txt b/Documentation/git-fsck.txt\nindex 234c22f..08512e0 100644\n--- a/Documentation/git-fsck.txt\n+++ b/Documentation/git-fsck.txt\n@@ -10,7 +10,7 @@ SYNOPSIS\n --------\n [verse]\n 'git-fsck' [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]\n-\t\t [--full] [--strict] [--verbose] [<object>*]\n+\t [--full] [--strict] [--verbose] [--lost-found] [<object>*]\n \n DESCRIPTION\n -----------\n@@ -64,6 +64,10 @@ index file and all SHA1 references in .git/refs/* as heads.\n --verbose::\n \tBe chatty.\n \n+--lost-found::\n+\tWrite dangling refs into .git/commit/ or .git/other/, depending\n+\ton type.\n+\n It tests SHA1 and general object sanity, and it does full tracking of\n the resulting reachability and everything else. It prints out any\n corruption it finds (missing or bad objects), and if you use the\ndiff --git a/Documentation/git-lost-found.txt b/Documentation/git-lost-found.txt\ndeleted file mode 100644\nindex e48607f..0000000\n--- a/Documentation/git-lost-found.txt\n+++ /dev/null\n@@ -1,77 +0,0 @@\n-git-lost-found(1)\n-=================\n-\n-NAME\n-----\n-git-lost-found - Recover lost refs that luckily have not yet been pruned\n-\n-SYNOPSIS\n---------\n-'git-lost-found'\n-\n-DESCRIPTION\n------------\n-Finds dangling commits and tags from the object database, and\n-creates refs to them in the .git/lost-found/ directory.  Commits and\n-tags that dereference to commits are stored in .git/lost-found/commit,\n-and other objects are stored in .git/lost-found/other.\n-\n-\n-OUTPUT\n-------\n-Prints to standard output the object names and one-line descriptions\n-of any commits or tags found.\n-\n-EXAMPLE\n--------\n-\n-Suppose you run 'git tag -f' and mistype the tag to overwrite.\n-The ref to your tag is overwritten, but until you run 'git\n-prune', the tag itself is still there.\n-\n-------------\n-$ git lost-found\n-[1ef2b196d909eed523d4f3c9bf54b78cdd6843c6] GIT 0.99.9c\n-...\n-------------\n-\n-Also you can use gitk to browse how any tags found relate to each\n-other.\n-\n-------------\n-$ gitk $(cd .git/lost-found/commit && echo ??*)\n-------------\n-\n-After making sure you know which the object is the tag you are looking\n-for, you can reconnect it to your regular .git/refs hierarchy.\n-\n-------------\n-$ git cat-file -t 1ef2b196\n-tag\n-$ git cat-file tag 1ef2b196\n-object fa41bbce8e38c67a218415de6cfa510c7e50032a\n-type commit\n-tag v0.99.9c\n-tagger Junio C Hamano <junkio@cox.net> 1131059594 -0800\n-\n-GIT 0.99.9c\n-\n-This contains the following changes from the \"master\" branch, since\n-...\n-$ git update-ref refs/tags/not-lost-anymore 1ef2b196\n-$ git rev-parse not-lost-anymore\n-1ef2b196d909eed523d4f3c9bf54b78cdd6843c6\n-------------\n-\n-Author\n-------\n-Written by Junio C Hamano 濱野 純 <junkio@cox.net>\n-\n-Documentation\n---------------\n-Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.\n-\n-\n-GIT\n----\n-Part of the gitlink:git[7] suite\ndiff --git a/Makefile b/Makefile\nindex d7f686a..d4633bc 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -215,7 +215,7 @@ SCRIPT_SH = \\\n \tgit-am.sh \\\n \tgit-merge.sh git-merge-stupid.sh git-merge-octopus.sh \\\n \tgit-merge-resolve.sh git-merge-ours.sh \\\n-\tgit-lost-found.sh git-quiltimport.sh git-submodule.sh \\\n+\tgit-quiltimport.sh git-submodule.sh \\\n \tgit-filter-branch.sh \\\n \tgit-stash.sh\n \ndiff --git a/builtin-fsck.c b/builtin-fsck.c\nindex 944a496..a530700 100644\n--- a/builtin-fsck.c\n+++ b/builtin-fsck.c\n@@ -20,6 +20,7 @@ static int check_strict;\n static int keep_cache_objects;\n static unsigned char head_sha1[20];\n static int errors_found;\n+static int write_lost_and_found;\n static int verbose;\n #define ERROR_OBJECT 01\n #define ERROR_REACHABLE 02\n@@ -138,6 +139,21 @@ static void check_unreachable_object(struct object *obj)\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\tfprintf(f, \"%s\\n\", sha1_to_hex(obj->sha1));\n+\t\t\tfclose(f);\n+\t\t}\n \t\treturn;\n \t}\n \n@@ -685,6 +701,10 @@ int cmd_fsck(int argc, char **argv, const char *prefix)\n \t\t\tverbose = 1;\n \t\t\tcontinue;\n \t\t}\n+\t\tif (!strcmp(arg, \"--lost-found\")) {\n+\t\t\twrite_lost_and_found = 1;\n+\t\t\tcontinue;\n+\t\t}\n \t\tif (*arg == '-')\n \t\t\tusage(fsck_usage);\n \t}\ndiff --git a/t/t1420-lost-found.sh b/t/t1420-lost-found.sh\nnew file mode 100755\nindex 0000000..dc9e402\n--- /dev/null\n+++ b/t/t1420-lost-found.sh\n@@ -0,0 +1,35 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2007 Johannes E. Schindelin\n+#\n+\n+test_description='Test fsck --lost-found'\n+. ./test-lib.sh\n+\n+test_expect_success setup '\n+\tgit config core.logAllRefUpdates 0 &&\n+\t: > file1 &&\n+\tgit add file1 &&\n+\ttest_tick &&\n+\tgit commit -m initial &&\n+\techo 1 > file1 &&\n+\techo 2 > file2 &&\n+\tgit add file1 file2 &&\n+\ttest_tick &&\n+\tgit commit -m second &&\n+\techo 3 > file3 &&\n+\tgit add file3\n+'\n+\n+test_expect_success 'lost and found something' '\n+\tgit rev-parse HEAD > lost-commit &&\n+\tgit rev-parse :file3 > lost-other &&\n+\ttest_tick &&\n+\tgit reset --hard HEAD^ &&\n+\tgit fsck --lost-found &&\n+\ttest 2 = $(ls .git/lost-found/*/* | wc -l) &&\n+\ttest -f .git/lost-found/commit/$(cat lost-commit) &&\n+\ttest -f .git/lost-found/other/$(cat lost-other)\n+'\n+\n+test_done\n-- \n1.5.2.2.3295.g8c6d-dirty\n"},{"id":"46293","messageId":"7vabuewgdb.fsf@assigned-by-dhcp.cox.net","threadId":"8812","inReplyTo":"Pine.LNX.4.64.0707021751380.4071@racer.site","subject":"Re: [PATCH] git-fsck: add --lost-found option","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-07-02T23:11:28Z","receivedAt":"2007-07-02T23:11:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> With this option, dangling objects are not only reported, but also\n> written to .git/lost-found/commit/ or .git/lost-found/other/.\n>\n> This obsoletes git-lost-found.\n\nI haven't had chance to look at the code yet; this is only about\nthe design.\n\nI think adding --lost-found to fsck is a wonderful idea.  I also\nthink deprecating lost-found and removing it in the longer term\nis a good idea.\n\nPlease do not do that in a single patch.  This patch is at least\ntalking about three timeframes.\n\n 1. git-fsck learns --lost-found\n    The patch adds that to the code and the documentation.\n    Then it is commented on, perhaps updated, and matures.\n\n 2. git-lost-found is marked as \"deprecated\"\n    This patch adds \"deprecated\" warning to the documentation.\n\n 3. git-lost-found is removed.\n"},{"id":"46301","messageId":"Pine.LNX.4.64.0707030018120.4071@racer.site","threadId":"8812","inReplyTo":"7vabuewgdb.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] git-fsck: add --lost-found option","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-02T23:26:37Z","receivedAt":"2007-07-02T23:26:37Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 2 Jul 2007, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > With this option, dangling objects are not only reported, but also \n> > written to .git/lost-found/commit/ or .git/lost-found/other/.\n> >\n> > This obsoletes git-lost-found.\n> \n> [...]\n> \n> Please do not do that in a single patch.  This patch is at least\n> talking about three timeframes.\n\nRight. My fault.\n\n>  1. git-fsck learns --lost-found\n>     The patch adds that to the code and the documentation.\n>     Then it is commented on, perhaps updated, and matures.\n> \n>  2. git-lost-found is marked as \"deprecated\"\n>     This patch adds \"deprecated\" warning to the documentation.\n\nHow about combining these two, and give a big\n\n\tWARNING: 'git lost-found' is deprecated.\n\tWARNING: Use 'git fsck --lost-found' instead\n\nwhenever lost-found is called?\n\n>  3. git-lost-found is removed.\n\nYes, that can wait.\n\nWhat is more important before doing 1&2 for real is this: lost-found ATM \ncalls 'git-fsck --full --no-reflogs'. The patch does not force these two \noptions when called with '--lost-found'. I would really appreciate \nopinions on this issue, and will gladly re-prepare a patch accordingly.\n\nCiao,\nDscho\n"},{"id":"46304","messageId":"7vps3auz5y.fsf@assigned-by-dhcp.cox.net","threadId":"8812","inReplyTo":"Pine.LNX.4.64.0707030018120.4071@racer.site","subject":"Re: [PATCH] git-fsck: add --lost-found option","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-07-03T00:08:25Z","receivedAt":"2007-07-03T00:08:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> \tWARNING: 'git lost-found' is deprecated.\n> \tWARNING: Use 'git fsck --lost-found' instead\n>\n> whenever lost-found is called?\n\nI agree that would be a sensible second step after the result of\nthe first step matures.\n\n>>  3. git-lost-found is removed.\n>\n> Yes, that can wait.\n>\n> What is more important before doing 1&2 for real is this: lost-found ATM \n> calls 'git-fsck --full --no-reflogs'. The patch does not force these two \n> options when called with '--lost-found'. I would really appreciate \n> opinions on this issue, and will gladly re-prepare a patch accordingly.\n\nI think I am not following you; do you mean --lost-found does\nnot imply these two?  I am not sure if there is any benefit of\nbeing able to do --lost-found without --full nor --no-reflogs.\n"},{"id":"46307","messageId":"Pine.LNX.4.64.0707030133060.4071@racer.site","threadId":"8812","inReplyTo":"7vps3auz5y.fsf@assigned-by-dhcp.cox.net","subject":"[PATCH] git-fsck: add --lost-found option","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-03T00:33:54Z","receivedAt":"2007-07-03T00:33:54Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nWith this option, dangling objects are not only reported, but also\nwritten to .git/lost-found/commit/ or .git/lost-found/other/. This\noption implies '--full' and '--no-reflogs'.\n\n'git fsck --lost-found' is meant as a replacement for git-lost-found.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tStep 1.\n\n Documentation/git-fsck.txt |    6 +++++-\n builtin-fsck.c             |   22 ++++++++++++++++++++++\n t/t1420-lost-found.sh      |   35 +++++++++++++++++++++++++++++++++++\n 3 files changed, 62 insertions(+), 1 deletions(-)\n create mode 100755 t/t1420-lost-found.sh\n\ndiff --git a/Documentation/git-fsck.txt b/Documentation/git-fsck.txt\nindex 234c22f..08512e0 100644\n--- a/Documentation/git-fsck.txt\n+++ b/Documentation/git-fsck.txt\n@@ -10,7 +10,7 @@ SYNOPSIS\n --------\n [verse]\n 'git-fsck' [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]\n-\t\t [--full] [--strict] [--verbose] [<object>*]\n+\t [--full] [--strict] [--verbose] [--lost-found] [<object>*]\n \n DESCRIPTION\n -----------\n@@ -64,6 +64,10 @@ index file and all SHA1 references in .git/refs/* as heads.\n --verbose::\n \tBe chatty.\n \n+--lost-found::\n+\tWrite dangling refs into .git/commit/ or .git/other/, depending\n+\ton type.\n+\n It tests SHA1 and general object sanity, and it does full tracking of\n the resulting reachability and everything else. It prints out any\n corruption it finds (missing or bad objects), and if you use the\ndiff --git a/builtin-fsck.c b/builtin-fsck.c\nindex 944a496..a6ef65e 100644\n--- a/builtin-fsck.c\n+++ b/builtin-fsck.c\n@@ -20,6 +20,7 @@ static int check_strict;\n static int keep_cache_objects;\n static unsigned char head_sha1[20];\n static int errors_found;\n+static int write_lost_and_found;\n static int verbose;\n #define ERROR_OBJECT 01\n #define ERROR_REACHABLE 02\n@@ -138,6 +139,21 @@ static void check_unreachable_object(struct object *obj)\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\tfprintf(f, \"%s\\n\", sha1_to_hex(obj->sha1));\n+\t\t\tfclose(f);\n+\t\t}\n \t\treturn;\n \t}\n \n@@ -685,6 +701,12 @@ int cmd_fsck(int argc, char **argv, const char *prefix)\n \t\t\tverbose = 1;\n \t\t\tcontinue;\n \t\t}\n+\t\tif (!strcmp(arg, \"--lost-found\")) {\n+\t\t\tcheck_full = 1;\n+\t\t\tinclude_reflogs = 0;\n+\t\t\twrite_lost_and_found = 1;\n+\t\t\tcontinue;\n+\t\t}\n \t\tif (*arg == '-')\n \t\t\tusage(fsck_usage);\n \t}\ndiff --git a/t/t1420-lost-found.sh b/t/t1420-lost-found.sh\nnew file mode 100755\nindex 0000000..dc9e402\n--- /dev/null\n+++ b/t/t1420-lost-found.sh\n@@ -0,0 +1,35 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2007 Johannes E. Schindelin\n+#\n+\n+test_description='Test fsck --lost-found'\n+. ./test-lib.sh\n+\n+test_expect_success setup '\n+\tgit config core.logAllRefUpdates 0 &&\n+\t: > file1 &&\n+\tgit add file1 &&\n+\ttest_tick &&\n+\tgit commit -m initial &&\n+\techo 1 > file1 &&\n+\techo 2 > file2 &&\n+\tgit add file1 file2 &&\n+\ttest_tick &&\n+\tgit commit -m second &&\n+\techo 3 > file3 &&\n+\tgit add file3\n+'\n+\n+test_expect_success 'lost and found something' '\n+\tgit rev-parse HEAD > lost-commit &&\n+\tgit rev-parse :file3 > lost-other &&\n+\ttest_tick &&\n+\tgit reset --hard HEAD^ &&\n+\tgit fsck --lost-found &&\n+\ttest 2 = $(ls .git/lost-found/*/* | wc -l) &&\n+\ttest -f .git/lost-found/commit/$(cat lost-commit) &&\n+\ttest -f .git/lost-found/other/$(cat lost-other)\n+'\n+\n+test_done\n-- \n1.5.2.2.3296.g5753c-dirty\n"},{"id":"46428","messageId":"20070704013311.GA32210@diku.dk","threadId":"8812","inReplyTo":"Pine.LNX.4.64.0707030133060.4071@racer.site","subject":"[PATCH] fsck --lost-found writes to subdirectories in .git/lost-found/","fromName":"Jonas Fonseca","fromEmail":"fonseca@diku.dk","sentAt":"2007-07-04T01:33:11Z","receivedAt":"2007-07-04T01:33:11Z","isPatch":true,"sender":{"key":"fonseca@diku.dk","avatar":"https://gravatar.com/avatar/f82f3ad698717c51873b020c750a92438c820a24056dc39fe4d07baa10a92264?d=mp&s=160"},"body":"Signed-off-by: Jonas Fonseca <fonseca@diku.dk>\n---\n Documentation/git-fsck.txt |    4 ++--\n 1 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-fsck.txt b/Documentation/git-fsck.txt\nindex 08512e0..1a432f2 100644\n--- a/Documentation/git-fsck.txt\n+++ b/Documentation/git-fsck.txt\n@@ -65,8 +65,8 @@ index file and all SHA1 references in .git/refs/* as heads.\n \tBe chatty.\n \n --lost-found::\n-\tWrite dangling refs into .git/commit/ or .git/other/, depending\n-\ton type.\n+\tWrite dangling refs into .git/lost-found/commit/ or\n+\t.git/lost-found/other/, depending on type.\n \n It tests SHA1 and general object sanity, and it does full tracking of\n the resulting reachability and everything else. It prints out any\n-- \n1.5.2.2.1451.gb0e5e\n\n-- \nJonas Fonseca\n"},{"id":"46429","messageId":"Pine.LNX.4.64.0707040240320.4071@racer.site","threadId":"8812","inReplyTo":"20070704013311.GA32210@diku.dk","subject":"Re: [PATCH] fsck --lost-found writes to subdirectories in .git/lost-found/","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-04T01:41:15Z","receivedAt":"2007-07-04T01:41:15Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 4 Jul 2007, Jonas Fonseca wrote:\n\n> -\tWrite dangling refs into .git/commit/ or .git/other/, depending\n> -\ton type.\n> +\tWrite dangling refs into .git/lost-found/commit/ or\n> +\t.git/lost-found/other/, depending on type.\n\nOooooops.\n\nThanks,\nDscho\n"}]}