{"thread":{"id":"682","subject":"[RFC] git-fsck-cache argument processing","startedAt":"2005-05-21T03:38:52Z","lastAt":"2005-05-21T23:53:48Z","messageCount":18,"participants":["Sean","Jeff Garzik","Junio C Hamano","Olivier Galibert","Linus Torvalds","Joel Becker"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"3674","messageId":"4870.10.10.10.24.1116646732.squirrel@linux1","threadId":"682","inReplyTo":null,"subject":"[RFC] git-fsck-cache argument processing","fromName":"Sean","fromEmail":"seanlkml@sympatico.ca","sentAt":"2005-05-21T03:38:52Z","receivedAt":"2005-05-21T03:38:52Z","isPatch":false,"sender":{"key":"seanlkml@sympatico.ca","avatar":"https://gravatar.com/avatar/f92923f54fc08c401fc59b71829d4b89e9b8087fbba45ff87c82e6a83aee02ae?d=mp&s=160"},"body":"\nHere is a first crack at using argp as suggested by Jeff Garzik to\nimplement argument processing as requested by Junio and Linus.  Each of\nthe long arguments have been given a single character equivalent as well.\n\nThis patch only converts fsck-cache to use argp in case anyone has\nobjections to the basic format or style.  The patch includes a version\nnumber inside of fsck-cache.c; this should really be in a separate include\nfile so you can run any command with --version and get the same answer.\n\nWith this change you have:\n\n$ git-fsck-cache -?\nUsage: git-fsck-cache [OPTION...] [HEAD-SHA1...]\ngit-fsck-cache - repository consistency check\n\n -c, --cache            Mark all objects referenced by cache as reachable\n -d, --delta-depth      Show the maximum length of delta chains\n -r, --root             Show root objects, ie. those without parents\n -t, --tags             Show revision tags\n -u, --unreachable      Show missing objects or deltas\n -?, --help             Give this help list\n     --usage            Give a short usage message\n -V, --version          Print program version\n\nAnd the following should work as expected:\n\n$ git-fsck-cache -crudt\n\n\nfsck-cache.c |   64\n+++++++++++++++++++++++++++++++++++------------------------\n1 files changed, 39 insertions(+), 25 deletions(-)\n\nSean\n\n\nfsck-cache.c: needs update\nIndex: fsck-cache.c\n===================================================================\n--- 58741c69570705801db4b785681790d636475695/fsck-cache.c  (mode:100644)\n+++ uncommitted/fsck-cache.c  (mode:100644)\n@@ -1,5 +1,7 @@\n #include <sys/types.h>\n #include <dirent.h>\n+#include <argp.h>\n+const char *argp_program_version = \"git 1.0\";\n \n #include \"cache.h\"\n #include \"commit.h\"\n@@ -407,36 +409,48 @@\n \tfind_file_objects(git_dir, \"refs\");\n }\n \n+#define O_UNREACH 'u'\n+#define O_TAGS 't'\n+#define O_ROOT 'r'\n+#define O_DELTA 'd'\n+#define O_CACHE 'c'\n+\n+static const char doc[] = \"Perform repository consistency check\";\n+\n+static struct argp_option options[] = {\n+ {\"unreachable\", O_UNREACH, 0, 0, \"Show missing objects or deltas\"},\n+ {\"tags\", O_TAGS, 0, 0, \"Show revision tags\"},\n+ {\"root\", O_ROOT, 0, 0, \"Show root objects, ie. those without parents\"},\n+ {\"delta-depth\", O_DELTA, 0, 0, \"Show the maximum length of delta chains\"},\n+ {\"cache\", O_CACHE, 0, 0, \"Mark all objects referenced by cache as reachable\"},\n+ { }\n+};\n+\n+static error_t parse_opt (int key, char *arg, struct argp_state *state)\n+{\n+\tswitch (key) {\n+\tcase O_UNREACH:\t\tshow_unreachable = 1; break;\n+\tcase O_TAGS:\t\tshow_tags = 1; break;\n+\tcase O_ROOT:\t\tshow_root = 1; break;\n+\tcase O_DELTA:\t\tshow_max_delta_depth = 1; break;\n+\tcase O_CACHE:\t\tkeep_cache_objects = 1; break;\n+\tcase ARGP_KEY_ARG:\tstate->next = state->argc; break;\n+\tdefault:\t\treturn ARGP_ERR_UNKNOWN;\n+\t}\n+\treturn 0;\n+}\n+\n+static const struct argp argp = { options, parse_opt, \"[HEAD-SHA1...]\", doc };\n+\n int main(int argc, char **argv)\n {\n \tint i, heads;\n \tchar *sha1_dir;\n \n-\tfor (i = 1; i < argc; i++) {\n-\t\tconst char *arg = argv[i];\n-\n-\t\tif (!strcmp(arg, \"--unreachable\")) {\n-\t\t\tshow_unreachable = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--tags\")) {\n-\t\t\tshow_tags = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--root\")) {\n-\t\t\tshow_root = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--delta-depth\")) {\n-\t\t\tshow_max_delta_depth = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--cache\")) {\n-\t\t\tkeep_cache_objects = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (*arg == '-')\n-\t\t\tusage(\"git-fsck-cache [--tags] [[--unreachable] [--cache] <head-sha1>*]\");\n+\terror_t rc = argp_parse(&argp, argc, argv, 0, NULL, NULL);\n+\tif (rc) {\n+\t\tfprintf(stderr, \"argument failed: %s\\n\", strerror(rc));\n+\t\treturn 1;\n \t}\n \n \tsha1_dir = get_object_directory();\n"},{"id":"3676","messageId":"428EB444.7010200@pobox.com","threadId":"682","inReplyTo":"4870.10.10.10.24.1116646732.squirrel@linux1","subject":"Re: [RFC] git-fsck-cache argument processing","fromName":"Jeff Garzik","fromEmail":"jgarzik@pobox.com","sentAt":"2005-05-21T04:08:36Z","receivedAt":"2005-05-21T04:08:36Z","isPatch":false,"sender":{"key":"jgarzik@pobox.com","avatar":null},"body":"Sean wrote:\n> Here is a first crack at using argp as suggested by Jeff Garzik to\n> implement argument processing as requested by Junio and Linus.  Each of\n> the long arguments have been given a single character equivalent as well.\n> \n> This patch only converts fsck-cache to use argp in case anyone has\n> objections to the basic format or style.  The patch includes a version\n> number inside of fsck-cache.c; this should really be in a separate include\n> file so you can run any command with --version and get the same answer.\n\nPretty good.  You'll probably want some additional changes:\n\n\n1) eliminate\n+       case ARGP_KEY_ARG:      state->next = state->argc; break;\n\nThis will cause option processing to stop at the first unknown argument.\n\n\n2) Pass-by-reference a variable to argp_parse(), which will store the \nindex of the argument where processing stopped.  This is the first \nhash/file/etc. non-option argument.\n\n(example code from posixutils)\n\nint parse_cmdline(struct cmdline_walker *cw)\n{\n       error_t rc_argp;\n       int idx = 0;\n\n       rc_argp = argp_parse(cw->argp, cw->argc, cw->argv, 0, &idx, NULL);\n       if (rc_argp) {\n               fprintf(stderr, \"argp_parse: %s\\n\", strerror(rc_argp));\n               return -rc_argp;\n       }\n\n       return idx;\n}\n\n'idx' in this case is the first non-option argument, which can be passed \ndirectly to argv[].  From there, you perform standard iteration over the \narguments provided on the command line, starting at argv[idx].\n\nIf you have a fixed number of arguments following the options, then your \nparse_opt function can easily parse those args as well:\n\nstatic error_t parse_opt (int key, char *arg, struct argp_state *state)\n{\n         switch (key) {\n         case '1':\n                 outmask |= OPT_FILE1;\n                 break;\n         case '2':\n                 outmask |= OPT_FILE2;\n                 break;\n         case '3':\n                 outmask |= OPT_DUP;\n                 break;\n\n         case ARGP_KEY_ARG:\n           switch(state->arg_num) {\n           case 0:         file1 = arg; break; /* 1st non-opt arg */\n           case 1:         file2 = arg; break; /* 2nd non-opt arg */\n           default:        argp_usage (state); break; /* too many args */\n           }\n           break;\n\n         case ARGP_KEY_END:\n                 if (state->arg_num < 2)         /* not enough args */\n                         argp_usage (state);\n                 break;\n\n         default:\n                 return ARGP_ERR_UNKNOWN;\n         }\n\n         return 0;\n}\n\n"},{"id":"3677","messageId":"4966.10.10.10.24.1116650175.squirrel@linux1","threadId":"682","inReplyTo":"428EB444.7010200@pobox.com","subject":"Re: [RFC] git-fsck-cache argument processing","fromName":"Sean","fromEmail":"seanlkml@sympatico.ca","sentAt":"2005-05-21T04:36:15Z","receivedAt":"2005-05-21T04:36:15Z","isPatch":false,"sender":{"key":"seanlkml@sympatico.ca","avatar":"https://gravatar.com/avatar/f92923f54fc08c401fc59b71829d4b89e9b8087fbba45ff87c82e6a83aee02ae?d=mp&s=160"},"body":"On Sat, May 21, 2005 12:08 am, Jeff Garzik said:\n\n> Pretty good.  You'll probably want some additional changes:\n>\n> 1) eliminate\n> +       case ARGP_KEY_ARG:      state->next = state->argc; break;\n>\n> This will cause option processing to stop at the first unknown argument.\n>\n> 2) Pass-by-reference a variable to argp_parse(), which will store the\n> index of the argument where processing stopped.  This is the first\n> hash/file/etc. non-option argument.\n>\n\nThanks Jeff, that's pretty cool.  Here's an updated patch.\n\nWith this updated patch, options following or even intermingled with the\nSHA1 list also are picked up, for example:\n\n$ git-fsck-cache 804c64ea864d0a8ee13f3de0b74158a3e9c3166d -crudt\n\n\nfsck-cache.c |   66\n+++++++++++++++++++++++++++++++++++------------------------\n1 files changed, 40 insertions(+), 26 deletions(-)\n\nSean\n\n\nfsck-cache.c: needs update\nIndex: fsck-cache.c\n===================================================================\n--- 58741c69570705801db4b785681790d636475695/fsck-cache.c  (mode:100644)\n+++ uncommitted/fsck-cache.c  (mode:100644)\n@@ -1,5 +1,7 @@\n #include <sys/types.h>\n #include <dirent.h>\n+#include <argp.h>\n+const char *argp_program_version = \"git 1.0\";\n \n #include \"cache.h\"\n #include \"commit.h\"\n@@ -407,36 +409,48 @@\n \tfind_file_objects(git_dir, \"refs\");\n }\n \n+#define O_UNREACH 'u'\n+#define O_TAGS 't'\n+#define O_ROOT 'r'\n+#define O_DELTA 'd'\n+#define O_CACHE 'c'\n+\n+static const char doc[] = \"Perform repository consistency check\";\n+\n+static struct argp_option options[] = {\n+ {\"unreachable\", O_UNREACH, 0, 0, \"Show missing objects or deltas\"},\n+ {\"tags\", O_TAGS, 0, 0, \"Show revision tags\"},\n+ {\"root\", O_ROOT, 0, 0, \"Show root objects, ie. those without parents\"},\n+ {\"delta-depth\", O_DELTA, 0, 0, \"Show the maximum length of delta chains\"},\n+ {\"cache\", O_CACHE, 0, 0, \"Mark all objects referenced by cache as reachable\"},\n+ { }\n+};\n+\n+static error_t parse_opt (int key, char *arg, struct argp_state *state)\n+{\n+        switch (key) {\n+        case O_UNREACH:\t\tshow_unreachable = 1; break;\n+        case O_TAGS:\t\tshow_tags = 1; break;\n+        case O_ROOT:\t\tshow_root = 1; break;\n+        case O_DELTA:\t\tshow_max_delta_depth = 1; break;\n+        case O_CACHE:\t\tkeep_cache_objects = 1; break;\n+        default:\t\treturn ARGP_ERR_UNKNOWN;\n+        }\n+        return 0;\n+}\n+\n+static const struct argp argp = { options, parse_opt, \"[HEAD-SHA1...]\", doc };\n+\n int main(int argc, char **argv)\n {\n \tint i, heads;\n \tchar *sha1_dir;\n+\tint idx;\n \n-\tfor (i = 1; i < argc; i++) {\n-\t\tconst char *arg = argv[i];\n-\n-\t\tif (!strcmp(arg, \"--unreachable\")) {\n-\t\t\tshow_unreachable = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--tags\")) {\n-\t\t\tshow_tags = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--root\")) {\n-\t\t\tshow_root = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--delta-depth\")) {\n-\t\t\tshow_max_delta_depth = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--cache\")) {\n-\t\t\tkeep_cache_objects = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (*arg == '-')\n-\t\t\tusage(\"git-fsck-cache [--tags] [[--unreachable] [--cache] <head-sha1>*]\");\n+\terror_t rc = argp_parse(&argp, argc, argv, 0, &idx, NULL);\n+\tif (rc) {\n+\t\tfprintf(stderr, \"argument failed: %s\\n\", strerror(rc));\n+\t\treturn 1;\n \t}\n \n \tsha1_dir = get_object_directory();\n@@ -450,7 +464,7 @@\n \texpand_deltas();\n \n \theads = 0;\n-\tfor (i = 1; i < argc; i++) {\n+\tfor (i = idx; i < argc; i++) {\n \t\tconst char *arg = argv[i]; \n \n \t\tif (*arg == '-')\n"},{"id":"3679","messageId":"7voeb5np30.fsf@assigned-by-dhcp.cox.net","threadId":"682","inReplyTo":"4870.10.10.10.24.1116646732.squirrel@linux1","subject":"Re: [RFC] git-fsck-cache argument processing","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-21T05:08:19Z","receivedAt":"2005-05-21T05:08:19Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The patch looks good.  Before you proceed to convert the rest,\ncould I ask you to first let us see the list of new set of\noptions and semantics changes, if any (\"checkout-cache -f -a\" vs\n\"checkout-cache -a -f\" immediately comes to mind)?\n\nPresumably you would be doing the Documentation updates as well,\nso starting from the documentaiton updates before writing the\nactual code may be a good way for us to understand and ack on\nwhat is going to happen.\n\n"},{"id":"3680","messageId":"428EC2A0.7030407@pobox.com","threadId":"682","inReplyTo":"4966.10.10.10.24.1116650175.squirrel@linux1","subject":"Re: [RFC] git-fsck-cache argument processing","fromName":"Jeff Garzik","fromEmail":"jgarzik@pobox.com","sentAt":"2005-05-21T05:09:52Z","receivedAt":"2005-05-21T05:09:52Z","isPatch":false,"sender":{"key":"jgarzik@pobox.com","avatar":null},"body":"Patch looks good to me...\n\n"},{"id":"3681","messageId":"20050521051536.GA9387@havoc.gtf.org","threadId":"682","inReplyTo":"7voeb5np30.fsf@assigned-by-dhcp.cox.net","subject":"Re: [RFC] git-fsck-cache argument processing","fromName":"Jeff Garzik","fromEmail":"jgarzik@pobox.com","sentAt":"2005-05-21T05:15:36Z","receivedAt":"2005-05-21T05:15:36Z","isPatch":false,"sender":{"key":"jgarzik@pobox.com","avatar":null},"body":"On Fri, May 20, 2005 at 10:08:19PM -0700, Junio C Hamano wrote:\n> The patch looks good.  Before you proceed to convert the rest,\n> could I ask you to first let us see the list of new set of\n> options and semantics changes, if any (\"checkout-cache -f -a\" vs\n> \"checkout-cache -a -f\" immediately comes to mind)?\n\nTypical implementation is agnostic on the ordering of options,\nbut with a few lines of code in parse_opt() that need not always be the\ncase.\n\nFWIW most users (including me!) would expect that order of options is\n-not- significant.\n\n\tJeff\n\n\n\n"},{"id":"3682","messageId":"7vekc1nmq4.fsf@assigned-by-dhcp.cox.net","threadId":"682","inReplyTo":"20050521051536.GA9387@havoc.gtf.org","subject":"Re: [RFC] git-fsck-cache argument processing","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-21T05:59:15Z","receivedAt":"2005-05-21T05:59:15Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":">>>>> \"JG\" == Jeff Garzik <jgarzik@pobox.com> writes:\n\nJG> On Fri, May 20, 2005 at 10:08:19PM -0700, Junio C Hamano wrote:\n\n>> The patch looks good.  Before you proceed to convert the rest,\n>> could I ask you to first let us see the list of new set of\n>> options and semantics changes, if any (\"checkout-cache -f -a\" vs\n>> \"checkout-cache -a -f\" immediately comes to mind)?\n\nJG> FWIW most users (including me!) would expect that order of\nJG> options is -not- significant.\n\nThat set of users includes me.  I was hoping that this round\nwould not just change things to use argp, but at the same time\nattempt to \"fix\" the problems around argument parsing.  \n\nJG> Typical implementation is agnostic on the ordering of\nJG> options, but with a few lines of code in parse_opt() that\nJG> need not always be the case.\n\nI think you are responding to my \"semantic changes\" question,\nbut I did not mean to say that exactly emulating the current\nbehaviour is the requirement, nor I meant to ask if doing so is\nimpossible using argp().  I just wanted to see \"the set of\nplanned fixes\" while we are at it.\n\n"},{"id":"3696","messageId":"20050521150926.GA96606@dspnet.fr.eu.org","threadId":"682","inReplyTo":"4870.10.10.10.24.1116646732.squirrel@linux1","subject":"Re: [RFC] git-fsck-cache argument processing","fromName":"Olivier Galibert","fromEmail":"galibert@pobox.com","sentAt":"2005-05-21T15:09:26Z","receivedAt":"2005-05-21T15:09:26Z","isPatch":false,"sender":{"key":"galibert@pobox.com","avatar":null},"body":"On Fri, May 20, 2005 at 11:38:52PM -0400, Sean wrote:\n>  -?, --help             Give this help list\n\nCould you make that '-h' please ?\n\n\n>  -V, --version          Print program version\n\nAnd that '-v'.  -V traditionally means verbose, -v version.  Yes, I\nknow there are counter-examples, but statistically...\n\n  OG.\n"},{"id":"3697","messageId":"428F554E.7060406@pobox.com","threadId":"682","inReplyTo":"20050521150926.GA96606@dspnet.fr.eu.org","subject":"Re: [RFC] git-fsck-cache argument processing","fromName":"Jeff Garzik","fromEmail":"jgarzik@pobox.com","sentAt":"2005-05-21T15:35:42Z","receivedAt":"2005-05-21T15:35:42Z","isPatch":false,"sender":{"key":"jgarzik@pobox.com","avatar":null},"body":"Olivier Galibert wrote:\n> And that '-v'.  -V traditionally means verbose, -v version.  Yes, I\n> know there are counter-examples, but statistically...\n\nIn my experience, lowercase 'v' means verbose :)\n\n\tJeff\n\n\n"},{"id":"3700","messageId":"2015.10.10.10.24.1116696150.squirrel@linux1","threadId":"682","inReplyTo":"20050521150926.GA96606@dspnet.fr.eu.org","subject":"Re: [RFC] git-fsck-cache argument processing","fromName":"Sean","fromEmail":"seanlkml@sympatico.ca","sentAt":"2005-05-21T17:22:30Z","receivedAt":"2005-05-21T17:22:30Z","isPatch":false,"sender":{"key":"seanlkml@sympatico.ca","avatar":"https://gravatar.com/avatar/f92923f54fc08c401fc59b71829d4b89e9b8087fbba45ff87c82e6a83aee02ae?d=mp&s=160"},"body":"On Sat, May 21, 2005 11:09 am, Olivier Galibert said:\n> On Fri, May 20, 2005 at 11:38:52PM -0400, Sean wrote:\n>>  -?, --help             Give this help list\n>\n> Could you make that '-h' please ?\n>\n>>  -V, --version          Print program version\n>\n> And that '-v'.  -V traditionally means verbose, -v version.  Yes, I\n> know there are counter-examples, but statistically...\n>\n\nHey Olivier,\n\nBoth of these options are generated automatically by argp.  I'm sure there\nis a way to override them, but i'd rather just leave them as given by\nargp.  For the first case, if you try '-h' on the command line you get:\n\n$ git-fsck-cache -h\ngit-fsck-cache: invalid option -- h\nTry `git-fsck-cache --help' or `git-fsck-cache --usage' for more information.\n\nSo it leads to the proper help message.\n\nSean\n\n\n"},{"id":"3710","messageId":"20050521184909.GA1729@dspnet.fr.eu.org","threadId":"682","inReplyTo":"2015.10.10.10.24.1116696150.squirrel@linux1","subject":"Re: [RFC] git-fsck-cache argument processing","fromName":"Olivier Galibert","fromEmail":"galibert@pobox.com","sentAt":"2005-05-21T18:49:09Z","receivedAt":"2005-05-21T18:49:09Z","isPatch":false,"sender":{"key":"galibert@pobox.com","avatar":null},"body":"On Sat, May 21, 2005 at 01:22:30PM -0400, Sean wrote:\n> Both of these options are generated automatically by argp.\n\nI see.  Then I'll guess I'll have to put argp in the \"crap\" pile next\nto libtool and automake.\n\n\n> I'm sure there\n> is a way to override them, but i'd rather just leave them as given by\n> argp.  For the first case, if you try '-h' on the command line you get:\n> \n> $ git-fsck-cache -h\n> git-fsck-cache: invalid option -- h\n> Try `git-fsck-cache --help' or `git-fsck-cache --usage' for more information.\n> \n> So it leads to the proper help message.\n\nHow neat.  Of course using the right option under (t)csh gives:\n\ngalibert@m62:~ #201 >git-fsck-cache -?\ngit-fsck-cache: No match.\n\nImporting this windowism is beyond stupid.\n\n  OG.\n"},{"id":"3711","messageId":"2329.10.10.10.24.1116702037.squirrel@linux1","threadId":"682","inReplyTo":"20050521184909.GA1729@dspnet.fr.eu.org","subject":"Re: [RFC] git-fsck-cache argument processing","fromName":"Sean","fromEmail":"seanlkml@sympatico.ca","sentAt":"2005-05-21T19:00:37Z","receivedAt":"2005-05-21T19:00:37Z","isPatch":false,"sender":{"key":"seanlkml@sympatico.ca","avatar":"https://gravatar.com/avatar/f92923f54fc08c401fc59b71829d4b89e9b8087fbba45ff87c82e6a83aee02ae?d=mp&s=160"},"body":"On Sat, May 21, 2005 2:49 pm, Olivier Galibert said:\n> On Sat, May 21, 2005 at 01:22:30PM -0400, Sean wrote:\n>> Both of these options are generated automatically by argp.\n>\n> I see.  Then I'll guess I'll have to put argp in the \"crap\" pile next\n> to libtool and automake.\n\nOkay now don't go saying things you can't take back <g>.\n\n> How neat.  Of course using the right option under (t)csh gives:\n>\n> galibert@m62:~ #201 >git-fsck-cache -?\n> git-fsck-cache: No match.\n>\n> Importing this windowism is beyond stupid.\n\nHmmm, that kinda sucks, but the --help should still work fine.  I suppose\nwe could figure out how to use -h instead.\n\nSean\n\n\n"},{"id":"3712","messageId":"Pine.LNX.4.58.0505211245580.2206@ppc970.osdl.org","threadId":"682","inReplyTo":"4870.10.10.10.24.1116646732.squirrel@linux1","subject":"Re: [RFC] git-fsck-cache argument processing","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-05-21T19:47:55Z","receivedAt":"2005-05-21T19:47:55Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Fri, 20 May 2005, Sean wrote:\n>\n>  -u, --unreachable      Show missing objects or deltas\n\nThat's the wrong description.\n\nfsck always shows missing objects, but \"--unreachable\" makes it also show\nobjects that cannot be reached from any of the references (either passed\nin on the command line, or the implicit references we take if no explicit\nreference is given).\n\nSo in many ways, \"--unreachable\" is about the _reverse_ of showing missing \nobjects: it's about showing _extraneous_ objects that aren't needed by the \nref that was passed in.\n\n\t\tLinus\n"},{"id":"3713","messageId":"Pine.LNX.4.58.0505211248110.2206@ppc970.osdl.org","threadId":"682","inReplyTo":"4870.10.10.10.24.1116646732.squirrel@linux1","subject":"Re: [RFC] git-fsck-cache argument processing","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-05-21T19:49:51Z","receivedAt":"2005-05-21T19:49:51Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOh, and please fix your mailer. Your attachments show up for me as \nunreadable:\n\n    [ Part 2, Application/OCTET-STREAM (Name: \"fsck-cache-argp-v1.patch\")  3.2KB. ]\n    [ Cannot display this part. Press \"V\" then \"S\" to save in a file. ]\n\nie I'd have to save them to a file to look at them, which is just silly. \nSo either just add patches in-line (and make sure your mailer doesn't crap \nall over whitespace), or add them as text attachments so that people see \nthe things in their mail readers.\n\n\t\tLinus\n"},{"id":"3717","messageId":"2475.10.10.10.24.1116708368.squirrel@linux1","threadId":"682","inReplyTo":"Pine.LNX.4.58.0505211245580.2206@ppc970.osdl.org","subject":"Re: [RFC] git-fsck-cache argument processing","fromName":"Sean","fromEmail":"seanlkml@sympatico.ca","sentAt":"2005-05-21T20:46:08Z","receivedAt":"2005-05-21T20:46:08Z","isPatch":false,"sender":{"key":"seanlkml@sympatico.ca","avatar":"https://gravatar.com/avatar/f92923f54fc08c401fc59b71829d4b89e9b8087fbba45ff87c82e6a83aee02ae?d=mp&s=160"},"body":"On Sat, May 21, 2005 3:47 pm, Linus Torvalds said:\n> On Fri, 20 May 2005, Sean wrote:\n>>\n>>  -u, --unreachable      Show missing objects or deltas\n>\n> That's the wrong description.\n>\n> fsck always shows missing objects, but \"--unreachable\" makes it also show\n> objects that cannot be reached from any of the references (either passed\n> in on the command line, or the implicit references we take if no explicit\n> reference is given).\n>\n> So in many ways, \"--unreachable\" is about the _reverse_ of showing missing\n> objects: it's about showing _extraneous_ objects that aren't needed by the\n> ref that was passed in.\n\nRight, fixed up in attached patch which basically punts with a description\nof   \"Show unreachable objects\", and leaves it to the documentation to do\nbetter.\n\nSean\n"},{"id":"3718","messageId":"2572.10.10.10.24.1116709742.squirrel@linux1","threadId":"682","inReplyTo":"2475.10.10.10.24.1116708368.squirrel@linux1","subject":"Re: [RFC] git-fsck-cache argument processing","fromName":"Sean","fromEmail":"seanlkml@sympatico.ca","sentAt":"2005-05-21T21:09:02Z","receivedAt":"2005-05-21T21:09:02Z","isPatch":false,"sender":{"key":"seanlkml@sympatico.ca","avatar":"https://gravatar.com/avatar/f92923f54fc08c401fc59b71829d4b89e9b8087fbba45ff87c82e6a83aee02ae?d=mp&s=160"},"body":"On Sat, May 21, 2005 4:46 pm, Sean said:\n\n> Right, fixed up in attached patch which basically punts with a\n> description of   \"Show unreachable objects\", and leaves it to the\n> documentation to do better.\nLinus,\n\nTry 2 at that attachment thingy, hopefully this one will make your mailer\nhappy.\n\nSean\n\n\n\nIndex: Documentation/git-fsck-cache.txt\n===================================================================\n--- 85ec256656a7839ca7a2067792b828c9b63c8711/Documentation/git-fsck-cache.txt  (mode:100644)\n+++ uncommitted/Documentation/git-fsck-cache.txt  (mode:100644)\n@@ -9,7 +9,8 @@\n \n SYNOPSIS\n --------\n-'git-fsck-cache' [--tags] [--root] [[--unreachable] [--cache] <object>\\*]\n+'git-fsck-cache' [--tags] [--root] [--delta-depth] \n+\t\t\t[[--unreachable] [--cache] <object>\\*]\n \n DESCRIPTION\n -----------\n@@ -34,6 +35,9 @@\n \tConsider any object recorded in the cache also as a head node for\n \tan unreachability trace.\n \n+--delta-depth::\n+\tShow length of longest delta chain.\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\nIndex: fsck-cache.c\n===================================================================\n--- 85ec256656a7839ca7a2067792b828c9b63c8711/fsck-cache.c  (mode:100644)\n+++ uncommitted/fsck-cache.c  (mode:100644)\n@@ -1,5 +1,7 @@\n #include <sys/types.h>\n #include <dirent.h>\n+#include <argp.h>\n+const char *argp_program_version = VERSION;\n \n #include \"cache.h\"\n #include \"commit.h\"\n@@ -407,36 +409,42 @@\n \tfind_file_objects(git_dir, \"refs\");\n }\n \n+static const char doc[] = \"Perform repository consistency check\";\n+\n+static struct argp_option options[] = {\n+ {\"unreachable\", 'u', 0, 0, \"Show unreachable objects\"},\n+ {\"tags\", 't', 0, 0, \"Show revision tags\"},\n+ {\"root\", 'r', 0, 0, \"Show root objects, ie. those without parents\"},\n+ {\"delta-depth\", 'd', 0, 0, \"Show length of longest delta chain\"},\n+ {\"cache\", 'c', 0, 0, \"Mark all objects referenced by cache as reachable\"},\n+ { }\n+};\n+\n+static error_t parse_opt (int key, char *arg, struct argp_state *state)\n+{\n+        switch (key) {\n+        case 'u':\t\tshow_unreachable = 1; break;\n+        case 't':\t\tshow_tags = 1; break;\n+        case 'r':\t\tshow_root = 1; break;\n+        case 'd':\t\tshow_max_delta_depth = 1; break;\n+        case 'c':\t\tkeep_cache_objects = 1; break;\n+        default:\t\treturn ARGP_ERR_UNKNOWN;\n+        }\n+        return 0;\n+}\n+\n+static const struct argp argp = { options, parse_opt, \"[HEAD-SHA1...]\", doc };\n+\n int main(int argc, char **argv)\n {\n \tint i, heads;\n \tchar *sha1_dir;\n+\tint idx;\n \n-\tfor (i = 1; i < argc; i++) {\n-\t\tconst char *arg = argv[i];\n-\n-\t\tif (!strcmp(arg, \"--unreachable\")) {\n-\t\t\tshow_unreachable = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--tags\")) {\n-\t\t\tshow_tags = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--root\")) {\n-\t\t\tshow_root = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--delta-depth\")) {\n-\t\t\tshow_max_delta_depth = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--cache\")) {\n-\t\t\tkeep_cache_objects = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (*arg == '-')\n-\t\t\tusage(\"git-fsck-cache [--tags] [[--unreachable] [--cache] <head-sha1>*]\");\n+\terror_t rc = argp_parse(&argp, argc, argv, 0, &idx, NULL);\n+\tif (rc) {\n+\t\tfprintf(stderr, \"argument failed: %s\\n\", strerror(rc));\n+\t\treturn 1;\n \t}\n \n \tsha1_dir = get_object_directory();\n@@ -450,7 +458,7 @@\n \texpand_deltas();\n \n \theads = 0;\n-\tfor (i = 1; i < argc; i++) {\n+\tfor (i = idx; i < argc; i++) {\n \t\tconst char *arg = argv[i]; \n \n \t\tif (*arg == '-')"},{"id":"3726","messageId":"20050521221401.GR22946@ca-server1.us.oracle.com","threadId":"682","inReplyTo":"20050521150926.GA96606@dspnet.fr.eu.org","subject":"Re: [RFC] git-fsck-cache argument processing","fromName":"Joel Becker","fromEmail":"joel.becker@oracle.com","sentAt":"2005-05-21T22:14:01Z","receivedAt":"2005-05-21T22:14:01Z","isPatch":false,"sender":{"key":"joel.becker@oracle.com","avatar":null},"body":"On Sat, May 21, 2005 at 05:09:26PM +0200, Olivier Galibert wrote:\n> On Fri, May 20, 2005 at 11:38:52PM -0400, Sean wrote:\n> >  -?, --help             Give this help list\n> \n> Could you make that '-h' please ?\n\n\tI generally think supporting -? and -h is the usual thing.  SysV\nloves -?, most real folks like -h.\n\n> >  -V, --version          Print program version\n> \n> And that '-v'.  -V traditionally means verbose, -v version.  Yes, I\n> know there are counter-examples, but statistically...\n\n\tI've never seen -V mean verbose.  I just queried all of\ncoreutils, and as most folks expect, -v means verbose.  Statistically,\nI'd be interested in seeing statistics.  I've never used a program where\n-V meant verbose.  I've never used a program that had '--verbose' where\n'-v' didn't mean verbose.  tar(1), rsync(1), chgrp(1), chown(1), cp(1),\nmkdir(1), all use '-v' for verbose.\n\nJoel\n\n-- \n\n\"The nearest approach to immortality on Earth is a government\n bureau.\"\n\t- James F. Byrnes\n\nJoel Becker\nSenior Member of Technical Staff\nOracle\nE-mail: joel.becker@oracle.com\nPhone: (650) 506-8127\n"},{"id":"3734","messageId":"428FCA0C.1080704@pobox.com","threadId":"682","inReplyTo":"20050521184909.GA1729@dspnet.fr.eu.org","subject":"Re: [RFC] git-fsck-cache argument processing","fromName":"Jeff Garzik","fromEmail":"jgarzik@pobox.com","sentAt":"2005-05-21T23:53:48Z","receivedAt":"2005-05-21T23:53:48Z","isPatch":false,"sender":{"key":"jgarzik@pobox.com","avatar":null},"body":"Olivier Galibert wrote:\n> On Sat, May 21, 2005 at 01:22:30PM -0400, Sean wrote:\n> \n>>Both of these options are generated automatically by argp.\n> \n> \n> I see.  Then I'll guess I'll have to put argp in the \"crap\" pile next\n> to libtool and automake.\n\nIt's called \"consistency with most other Linux apps.\"\n\nConsistency and predictability are good things.\n\n\tJeff\n\n\n"}]}