{"thread":{"id":"10592","subject":"Bring parse_options to the shell","startedAt":"2007-11-02T15:09:18Z","lastAt":"2007-11-02T18:48:23Z","messageCount":8,"participants":["Pierre Habouzit","Linus Torvalds","Johannes Schindelin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"57991","messageId":"1194016162-23599-1-git-send-email-madcoder@debian.org","threadId":"10592","inReplyTo":null,"subject":"Bring parse_options to the shell","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-11-02T15:09:18Z","receivedAt":"2007-11-02T15:09:18Z","isPatch":false,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"This is also something that itches me, so here is a proposal for a\ngit-parseopt helper that can be used in shell scripts as an option\nnormalizer like getopt(1) does.\n\nI migrated the discussed git-clean.sh to use it as a proof of concept.\n\nCheers,\n-- \nÂ·OÂ·  Pierre Habouzit\nÂ·Â·O                                                madcoder@debian.org\nOOO                                                http://www.madism.org\n"},{"id":"298996","messageId":"1194016162-23599-2-git-send-email-madcoder@debian.org","threadId":"10592","inReplyTo":"1194016162-23599-1-git-send-email-madcoder@debian.org","subject":"[PATCH] Add git-parseopt(1) to bring parse-options to shell scripts.","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-11-02T15:09:19Z","receivedAt":"2007-11-02T15:09:19Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"---\n .gitignore                     |    1 +\n Documentation/cmd-list.perl    |    1 +\n Documentation/git-parseopt.txt |   91 +++++++++++++++++++++++++++++\n Makefile                       |    1 +\n builtin-parseopt.c             |  123 ++++++++++++++++++++++++++++++++++++++++\n builtin.h                      |    1 +\n git.c                          |    1 +\n 7 files changed, 219 insertions(+), 0 deletions(-)\n create mode 100644 Documentation/git-parseopt.txt\n create mode 100644 builtin-parseopt.c\n\ndiff --git a/.gitignore b/.gitignore\nindex c8c13f5..521155c 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -86,6 +86,7 @@ git-pack-redundant\n git-pack-objects\n git-pack-refs\n git-parse-remote\n+git-parseopt\n git-patch-id\n git-peek-remote\n git-prune\ndiff --git a/Documentation/cmd-list.perl b/Documentation/cmd-list.perl\nindex 8d21d42..c491964 100755\n--- a/Documentation/cmd-list.perl\n+++ b/Documentation/cmd-list.perl\n@@ -147,6 +147,7 @@ git-pack-objects                        plumbingmanipulators\n git-pack-redundant                      plumbinginterrogators\n git-pack-refs                           ancillarymanipulators\n git-parse-remote                        synchelpers\n+git-parseopt                            plumbingmanipulators\n git-patch-id                            purehelpers\n git-peek-remote                         purehelpers\n git-prune                               ancillarymanipulators\ndiff --git a/Documentation/git-parseopt.txt b/Documentation/git-parseopt.txt\nnew file mode 100644\nindex 0000000..77f5a10\n--- /dev/null\n+++ b/Documentation/git-parseopt.txt\n@@ -0,0 +1,91 @@\n+git-parseopt(1)\n+============\n+\n+NAME\n+----\n+git-parseopt - Git shell script helper similar to getopt(1)\n+\n+\n+SYNOPSIS\n+--------\n+'git-parseopt' [-u] [--keep-dashdash] -- [<args>...]\n+\n+DESCRIPTION\n+-----------\n+\n+This is a helper for scripts to behave the same as git C commands. It merely\n+breaks and normalize options so that the option parsing becomes shorter and\n+easier to read. It takes the specifications of the options to undersand on its\n+standard input.\n+\n+In case of error, it ouputs usage on the standard error stream, and exits with\n+code 129. Else its ouput is suitable for evaluation with \"eval\" to replace\n+the script arguments with the normalized form.\n+\n+OPTIONS\n+-------\n+\n+--keep-dash-dash::\n+\tKeep the `--` in `<args>...`.\n+\n+\\--::\n+\tFollowing arguments are the options to parse. This isn't optional.\n+\n+<args>...::\n+\tOptions to parse and deal with\n+\n+INPUT FORMAT\n+------------\n+\n+`git-parseopt` input format is fully text based. It has two parts, separated\n+by a line that contains only `--`. The lines before (should be more than one)\n+is used for the usage. The lines after describe the options.\n+\n+Each line of options has this format:\n+\n+------------\n+<opt_spec><arg_spec>? SP+ help LF\n+------------\n+\n+`<opt_spec>`::\n+\tits format is the short option character, then the long option name\n+        separated by a comma. Both parts are not required, though at least one\n+        is necessary. `h,help`, `dry-run` and `f` are all three correct\n+        `<opt_spec>`.\n+\n+`<arg_spec>`::\n+\tan `<arg_spec>` tells the option parser if the option has an argument\n+        (`=`), an optionnal one (`?` though its use is discouraged) or none\n+        (no `<arg_spec>` in that case).\n+\n+The rest of the line after as many spaces up to the ending line feed is used\n+as the help associated to the option.\n+\n+EXAMPLE\n+-------\n+\n+------------\n+OPTS_SPEC=\"\\\n+some-command [options] <args>...\n+\n+some-command does foo and bar !\n+--\n+h,help    show the help\n+foo       some nifty option --foo\n+bar=      some cool option --bar with an argument\n+C?        option C with an optionnal argument\"\n+\n+eval `echo \"$OPTS_SPEC\" | git-parseopt -- \"$@\" || echo exit $?`\n+------------\n+\n+Author\n+------\n+Written by Pierre Habouzit <madcoder@debian.org>\n+\n+Documentation\n+--------------\n+Documentation by Pierre Habouzit.\n+\n+GIT\n+---\n+Part of the gitlink:git[7] suite\ndiff --git a/Makefile b/Makefile\nindex 042f79e..7c5df55 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -352,6 +352,7 @@ BUILTIN_OBJS = \\\n \tbuiltin-mv.o \\\n \tbuiltin-name-rev.o \\\n \tbuiltin-pack-objects.o \\\n+\tbuiltin-parseopt.o \\\n \tbuiltin-prune.o \\\n \tbuiltin-prune-packed.o \\\n \tbuiltin-push.o \\\ndiff --git a/builtin-parseopt.c b/builtin-parseopt.c\nnew file mode 100644\nindex 0000000..c032f5a\n--- /dev/null\n+++ b/builtin-parseopt.c\n@@ -0,0 +1,123 @@\n+/*\n+ * Copyright © 2007 Pierre Habouzit <madcoder@debian.org>\n+ */\n+#include \"git-compat-util.h\"\n+#include \"cache.h\"\n+#include \"quote.h\"\n+#include \"parse-options.h\"\n+\n+static int keep_dashdash = 0;\n+static struct strbuf parsed = STRBUF_INIT;\n+\n+static struct option parseopt_opts[] = {\n+\tOPT_BOOLEAN(0, \"keep-dashdash\", &keep_dashdash,\n+\t\t\t\t\"keep the `--` passed as an arg\"),\n+\tOPT_END(),\n+};\n+\n+static char const * const parseopt_usage[] = {\n+\t\"git-parseopt [options] -- [<args>...]\",\n+\tNULL\n+};\n+\n+static int parseopt_dump(const struct option *o, const char *arg, int unset)\n+{\n+\tif (unset)\n+\t\tstrbuf_addf(&parsed, \" --no-%s\", o->long_name);\n+\telse if (o->short_name)\n+\t\tstrbuf_addf(&parsed, \" -%c\", o->short_name);\n+\telse\n+\t\tstrbuf_addf(&parsed, \" --%s\", o->long_name);\n+\tif (arg) {\n+\t\tstrbuf_addch(&parsed, ' ');\n+\t\tsq_quote_buf(&parsed, arg);\n+\t}\n+\treturn 0;\n+}\n+\n+static const char *skipspaces(const char *s)\n+{\n+\twhile (isspace(*s))\n+\t\ts++;\n+\treturn s;\n+}\n+\n+int cmd_parseopt(int argc, const char **argv, const char *prefix)\n+{\n+\tstruct strbuf sb;\n+\tconst char **usage = NULL;\n+\tstruct option *opts = NULL;\n+\tint onb = 0, osz = 0, unb = 0, usz = 0;\n+\n+\tstrbuf_addstr(&parsed, \"set --\");\n+\targc = parse_options(argc, argv, parseopt_opts, parseopt_usage,\n+\t                     PARSE_OPT_KEEP_DASHDASH);\n+\tif (argc < 1 || strcmp(argv[0], \"--\"))\n+\t\tusage_with_options(parseopt_usage, parseopt_opts);\n+\n+\tstrbuf_init(&sb, 0);\n+\t/* get the usage up to the first line with a -- on it */\n+\tfor (;;) {\n+\t\tif (strbuf_getline(&sb, stdin, '\\n') == EOF)\n+\t\t\tdie(\"premature end of input\");\n+\t\tALLOC_GROW(usage, unb + 1, usz);\n+\t\tif (!strcmp(\"--\", sb.buf)) {\n+\t\t\tif (unb < 1)\n+\t\t\t\tdie(\"no usage string given before the `--' separator\");\n+\t\t\tusage[unb] = NULL;\n+\t\t\tbreak;\n+\t\t}\n+\t\tusage[unb++] = strbuf_detach(&sb, NULL);\n+\t}\n+\n+\t/* parse: (<short>|<short>,<long>|<long>)[=?]? SP+ <help> */\n+\twhile (strbuf_getline(&sb, stdin, '\\n') != EOF) {\n+\t\tconst char *s;\n+\t\tstruct option *o;\n+\n+\t\tALLOC_GROW(opts, onb + 1, osz);\n+\t\tmemset(opts + onb, 0, sizeof(opts[onb]));\n+\n+\t\to = &opts[onb++];\n+\t\ts = strchr(sb.buf, ' ');\n+\t\tif (!s || *sb.buf == ' ')\n+\t\t\tdie(\"invalid option spec\");\n+\n+\t\to->type = OPTION_CALLBACK;\n+\t\to->help = xstrdup(skipspaces(s));\n+\t\to->callback = &parseopt_dump;\n+\t\tswitch (s[-1]) {\n+\t\tcase '=':\n+\t\t\ts--;\n+\t\t\tbreak;\n+\t\tcase '?':\n+\t\t\to->flags = PARSE_OPT_OPTARG;\n+\t\t\ts--;\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\to->flags = PARSE_OPT_NOARG;\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (s - sb.buf == 1) /* short option only */\n+\t\t\to->short_name = *sb.buf;\n+\t\telse if (sb.buf[1] != ',') /* long option only */\n+\t\t\to->long_name = xmemdupz(sb.buf, s - sb.buf);\n+\t\telse {\n+\t\t\to->short_name = *sb.buf;\n+\t\t\to->long_name = xmemdupz(sb.buf + 2, s - sb.buf - 2);\n+\t\t}\n+\t}\n+\tstrbuf_release(&sb);\n+\n+\t/* put an OPT_END() */\n+\tALLOC_GROW(opts, onb + 1, osz);\n+\tmemset(opts + onb, 0, sizeof(opts[onb]));\n+\targc = parse_options(argc, argv, opts, usage,\n+\t                     keep_dashdash ? PARSE_OPT_KEEP_DASHDASH : 0);\n+\n+\tstrbuf_addf(&parsed, \" --\");\n+\tsq_quote_argv(&parsed, argv, argc, 0);\n+\tputs(parsed.buf);\n+\treturn 0;\n+}\ndiff --git a/builtin.h b/builtin.h\nindex 9a6213a..b2ef7b6 100644\n--- a/builtin.h\n+++ b/builtin.h\n@@ -55,6 +55,7 @@ extern int cmd_merge_file(int argc, const char **argv, const char *prefix);\n extern int cmd_mv(int argc, const char **argv, const char *prefix);\n extern int cmd_name_rev(int argc, const char **argv, const char *prefix);\n extern int cmd_pack_objects(int argc, const char **argv, const char *prefix);\n+extern int cmd_parseopt(int argc, const char **argv, const char *prefix);\n extern int cmd_pickaxe(int argc, const char **argv, const char *prefix);\n extern int cmd_prune(int argc, const char **argv, const char *prefix);\n extern int cmd_prune_packed(int argc, const char **argv, const char *prefix);\ndiff --git a/git.c b/git.c\nindex 4e10581..89524dd 100644\n--- a/git.c\n+++ b/git.c\n@@ -333,6 +333,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"mv\", cmd_mv, RUN_SETUP | NEED_WORK_TREE },\n \t\t{ \"name-rev\", cmd_name_rev, RUN_SETUP },\n \t\t{ \"pack-objects\", cmd_pack_objects, RUN_SETUP },\n+\t\t{ \"parseopt\", cmd_parseopt },\n \t\t{ \"pickaxe\", cmd_blame, RUN_SETUP },\n \t\t{ \"prune\", cmd_prune, RUN_SETUP },\n \t\t{ \"prune-packed\", cmd_prune_packed, RUN_SETUP },\n-- \n1.5.3.5.1458.g2aa13-dirty\n\n"},{"id":"298997","messageId":"1194016162-23599-3-git-send-email-madcoder@debian.org","threadId":"10592","inReplyTo":"1194016162-23599-2-git-send-email-madcoder@debian.org","subject":"[PATCH] Update git-sh-setup(1) to allow transparent use of git-parseopt(1)","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-11-02T15:09:20Z","receivedAt":"2007-11-02T15:09:20Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"If you set OPTIONS_SPEC, git-sh-setups uses git-parseopt automatically.\nIt also diverts usage to re-exec $0 with the -h option as parse-options.c\nwill catch that.\n\nPARSEOPT_OPTS can also be used to pass options git git-parseopt(1) (like\n--keep-dashdash).\n---\n git-sh-setup.sh |   44 ++++++++++++++++++++++++++------------------\n 1 files changed, 26 insertions(+), 18 deletions(-)\n\ndiff --git a/git-sh-setup.sh b/git-sh-setup.sh\nindex 86d7d4c..d7b13e0 100755\n--- a/git-sh-setup.sh\n+++ b/git-sh-setup.sh\n@@ -16,9 +16,32 @@ die() {\n \texit 1\n }\n \n-usage() {\n-\tdie \"Usage: $0 $USAGE\"\n-}\n+if test -n \"$OPTIONS_SPEC\"; then\n+\tusage() {\n+\t\texec \"$0\" -h\n+\t}\n+\n+\teval `echo \"$OPTIONS_SPEC\" | git parseopt $PARSEOPT_OPTS -- \"$@\" || echo exit $?`\n+else\n+\tusage() {\n+\t\tdie \"Usage: $0 $USAGE\"\n+\t}\n+\n+\tif [ -z \"$LONG_USAGE\" ]\n+\tthen\n+\t\tLONG_USAGE=\"Usage: $0 $USAGE\"\n+\telse\n+\t\tLONG_USAGE=\"Usage: $0 $USAGE\n+\n+$LONG_USAGE\"\n+\tfi\n+\n+\tcase \"$1\" in\n+\t\t-h|--h|--he|--hel|--help)\n+\t\techo \"$LONG_USAGE\"\n+\t\texit\n+\tesac\n+fi\n \n set_reflog_action() {\n \tif [ -z \"${GIT_REFLOG_ACTION:+set}\" ]\n@@ -91,21 +114,6 @@ get_author_ident_from_commit () {\n \tLANG=C LC_ALL=C sed -ne \"$pick_author_script\"\n }\n \n-if [ -z \"$LONG_USAGE\" ]\n-then\n-\tLONG_USAGE=\"Usage: $0 $USAGE\"\n-else\n-\tLONG_USAGE=\"Usage: $0 $USAGE\n-\n-$LONG_USAGE\"\n-fi\n-\n-case \"$1\" in\n-\t-h|--h|--he|--hel|--help)\n-\techo \"$LONG_USAGE\"\n-\texit\n-esac\n-\n # Make sure we are in a valid repository of a vintage we understand.\n if [ -z \"$SUBDIRECTORY_OK\" ]\n then\n-- \n1.5.3.5.1458.g2aa13-dirty\n\n"},{"id":"57993","messageId":"20071102151453.GB27505@artemis.corp","threadId":"10592","inReplyTo":"1194016162-23599-1-git-send-email-madcoder@debian.org","subject":"Re: Bring parse_options to the shell","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-11-02T15:14:53Z","receivedAt":"2007-11-02T15:14:53Z","isPatch":false,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"On Fri, Nov 02, 2007 at 03:09:18PM +0000, Pierre Habouzit wrote:\n> This is also something that itches me, so here is a proposal for a\n> git-parseopt helper that can be used in shell scripts as an option\n> normalizer like getopt(1) does.\n> \n> I migrated the discussed git-clean.sh to use it as a proof of concept.\n\n  Needless to say, this is fetchable from\ngit://git.madism.org/git.git#ph/parseopt\n\n-- \n·O·  Pierre Habouzit\n··O                                                madcoder@debian.org\nOOO                                                http://www.madism.org\n"},{"id":"58003","messageId":"alpine.LFD.0.999.0711020844310.3342@woody.linux-foundation.org","threadId":"10592","inReplyTo":"20071102151453.GB27505@artemis.corp","subject":"Re: Bring parse_options to the shell","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2007-11-02T15:51:13Z","receivedAt":"2007-11-02T15:51:13Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Fri, 2 Nov 2007, Pierre Habouzit wrote:\n\n> On Fri, Nov 02, 2007 at 03:09:18PM +0000, Pierre Habouzit wrote:\n> > This is also something that itches me, so here is a proposal for a\n> > git-parseopt helper that can be used in shell scripts as an option\n> > normalizer like getopt(1) does.\n> > \n> > I migrated the discussed git-clean.sh to use it as a proof of concept.\n> \n>   Needless to say, this is fetchable from\n> git://git.madism.org/git.git#ph/parseopt\n\nHmm. Any reason why you didn't just extend on \"git rev-parse\"?\n\nThat command was written exactly to parse a command line. This is really \ncheesy, and doesn't really work right (it splits up numbers too), but you \nget the idea..\n\n\t\tLinus\n\n---\n builtin-rev-parse.c |   11 +++++++++++\n 1 files changed, 11 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-rev-parse.c b/builtin-rev-parse.c\nindex 8d78b69..10b62f7 100644\n--- a/builtin-rev-parse.c\n+++ b/builtin-rev-parse.c\n@@ -116,6 +116,17 @@ static int show_flag(const char *arg)\n \tif (!(filter & DO_FLAGS))\n \t\treturn 0;\n \tif (filter & (is_rev_argument(arg) ? DO_REVS : DO_NOREV)) {\n+\t\tif (arg[0] == '-' && arg[1] != '-') {\n+\t\t\tchar split[3];\n+\t\t\tsplit[0] = '-';\n+\t\t\tsplit[2] = 0;\n+\t\t\twhile (arg[1]) {\n+\t\t\t\tsplit[1] = arg[1];\n+\t\t\t\targ++;\n+\t\t\t\tshow(split);\n+\t\t\t}\n+\t\t\treturn 1;\n+\t\t}\n \t\tshow(arg);\n \t\treturn 1;\n \t}\n"},{"id":"58005","messageId":"20071102160925.GC27505@artemis.corp","threadId":"10592","inReplyTo":"alpine.LFD.0.999.0711020844310.3342@woody.linux-foundation.org","subject":"Re: Bring parse_options to the shell","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-11-02T16:09:25Z","receivedAt":"2007-11-02T16:09:25Z","isPatch":false,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"On Fri, Nov 02, 2007 at 03:51:13PM +0000, Linus Torvalds wrote:\n> \n> \n> On Fri, 2 Nov 2007, Pierre Habouzit wrote:\n> \n> > On Fri, Nov 02, 2007 at 03:09:18PM +0000, Pierre Habouzit wrote:\n> > > This is also something that itches me, so here is a proposal for a\n> > > git-parseopt helper that can be used in shell scripts as an option\n> > > normalizer like getopt(1) does.\n> > > \n> > > I migrated the discussed git-clean.sh to use it as a proof of concept.\n> > \n> >   Needless to say, this is fetchable from\n> > git://git.madism.org/git.git#ph/parseopt\n> \n> Hmm. Any reason why you didn't just extend on \"git rev-parse\"?\n\nBecause I wasn't aware of the fact it was used to massage arguments of a\nfunction :) Though looking at the code git-rev-parse looks quite\ncomplicated and does not works the proper way:\n\nIt show()s the arguments along the way, whereas you definitely need to\nparse them first if you end up spitting out the usage. I could of course\nplumb it as a new \"mode\" of git-rev-parse, but it sounds awkward.\n\n> That command was written exactly to parse a command line. This is really \n> cheesy, and doesn't really work right (it splits up numbers too), but you \n> get the idea..\n\n  I get the idea, though parse-options is not incremental at all, this\ncould probably be done, but would complicate the API (we would need to\nallocate a state object e.g.). And parseoptions checks that options\ngetting an argument have one, checks that options exists and so on. It\nlooks like to me that it's not easy to plumb into rev-parse without\nbeing a brand new independant mode.\n\n  We can do that, if we don't want yet-another-git-builtin/command, but\nin the spirit it'll remain a brand new \"thing\".\n\n  Though I'd be glad to hear about what others think about it.\n\n-- \n·O·  Pierre Habouzit\n··O                                                madcoder@debian.org\nOOO                                                http://www.madism.org\n"},{"id":"58014","messageId":"Pine.LNX.4.64.0711021818480.4362@racer.site","threadId":"10592","inReplyTo":"20071102160925.GC27505@artemis.corp","subject":"Re: Bring parse_options to the shell","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-11-02T18:21:17Z","receivedAt":"2007-11-02T18:21:17Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 2 Nov 2007, Pierre Habouzit wrote:\n\n> On Fri, Nov 02, 2007 at 03:51:13PM +0000, Linus Torvalds wrote:\n> \n> > That command [rev-parse] was written exactly to parse a command line. \n> > This is really cheesy, and doesn't really work right (it splits up \n> > numbers too), but you get the idea..\n> \n>   I get the idea, though parse-options is not incremental at all, this \n> could probably be done, but would complicate the API (we would need to \n> allocate a state object e.g.). And parseoptions checks that options \n> getting an argument have one, checks that options exists and so on. It \n> looks like to me that it's not easy to plumb into rev-parse without \n> being a brand new independant mode.\n> \n>   We can do that, if we don't want yet-another-git-builtin/command, but \n> in the spirit it'll remain a brand new \"thing\".\n> \n>   Though I'd be glad to hear about what others think about it.\n\nYeah, rev-parse's only purpose in life is to help scripts.  (Even if it is \nused sometimes -- even by myself -- to turn symbolic names into SHA-1s.)\n\nIMHO it makes tons of sense to put the functionality into that command, \neven if it is not incremental.\n\nCiao,\nDscho\n"},{"id":"58017","messageId":"20071102184823.GE27505@artemis.corp","threadId":"10592","inReplyTo":"Pine.LNX.4.64.0711021818480.4362@racer.site","subject":"Re: Bring parse_options to the shell","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-11-02T18:48:23Z","receivedAt":"2007-11-02T18:48:23Z","isPatch":false,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"On Fri, Nov 02, 2007 at 06:21:17PM +0000, Johannes Schindelin wrote:\n> Hi,\n> \n> On Fri, 2 Nov 2007, Pierre Habouzit wrote:\n> \n> > On Fri, Nov 02, 2007 at 03:51:13PM +0000, Linus Torvalds wrote:\n> > \n> > > That command [rev-parse] was written exactly to parse a command line. \n> > > This is really cheesy, and doesn't really work right (it splits up \n> > > numbers too), but you get the idea..\n> > \n> >   I get the idea, though parse-options is not incremental at all, this \n> > could probably be done, but would complicate the API (we would need to \n> > allocate a state object e.g.). And parseoptions checks that options \n> > getting an argument have one, checks that options exists and so on. It \n> > looks like to me that it's not easy to plumb into rev-parse without \n> > being a brand new independant mode.\n> > \n> >   We can do that, if we don't want yet-another-git-builtin/command, but \n> > in the spirit it'll remain a brand new \"thing\".\n> > \n> >   Though I'd be glad to hear about what others think about it.\n> \n> Yeah, rev-parse's only purpose in life is to help scripts.  (Even if it is \n> used sometimes -- even by myself -- to turn symbolic names into SHA-1s.)\n> \n> IMHO it makes tons of sense to put the functionality into that command, \n> even if it is not incremental.\n\n  Okay so what do I do ? I create a new mode for git-rev-parse that does\nwhat I do in git-parseopt ? I can do that, I don't like it a lot, but if\npeople it's better to work this way... It's also kind of counter\nintuitive to have git *rev-parse* doing that but oh well, after all it's\nplumbing\n\n-- \n·O·  Pierre Habouzit\n··O                                                madcoder@debian.org\nOOO                                                http://www.madism.org\n"}]}