{"thread":{"id":"15695","subject":"small warm-up: easy parse-opt migrations.","startedAt":"2008-09-28T09:45:36Z","lastAt":"2008-10-02T12:59:20Z","messageCount":19,"participants":["Pierre Habouzit","Sverre Rabbelier","Shawn O. Pearce"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"91779","messageId":"1222595139-32087-1-git-send-email-madcoder@debian.org","threadId":"15695","inReplyTo":null,"subject":"small warm-up: easy parse-opt migrations.","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2008-09-28T09:45:36Z","receivedAt":"2008-09-28T09:45:36Z","isPatch":false,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"There's not a lot to tell, those are just three migration to\nparse-options.\n"},{"id":"91781","messageId":"1222595139-32087-2-git-send-email-madcoder@debian.org","threadId":"15695","inReplyTo":"1222595139-32087-1-git-send-email-madcoder@debian.org","subject":"[PATCH] parse-opt: migrate fmt-merge-msg.","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2008-09-28T09:45:37Z","receivedAt":"2008-09-28T09:45:37Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"Also fix an inefficient printf(\"%s\", ...) where we can use write_in_full.\n\nSigned-off-by: Pierre Habouzit <madcoder@debian.org>\n---\n builtin-fmt-merge-msg.c |   50 +++++++++++++++++++++-------------------------\n 1 files changed, 23 insertions(+), 27 deletions(-)\n\ndiff --git a/builtin-fmt-merge-msg.c b/builtin-fmt-merge-msg.c\nindex a1879f1..654d996 100644\n--- a/builtin-fmt-merge-msg.c\n+++ b/builtin-fmt-merge-msg.c\n@@ -5,8 +5,10 @@\n #include \"revision.h\"\n #include \"tag.h\"\n \n-static const char *fmt_merge_msg_usage =\n-\t\"git fmt-merge-msg [--log] [--no-log] [--file <file>]\";\n+static const char * const fmt_merge_msg_usage[] = {\n+\t\"git fmt-merge-msg [--log|--no-log] [--file <file>]\",\n+\tNULL\n+};\n \n static int merge_log;\n \n@@ -342,37 +344,31 @@ int fmt_merge_msg(int merge_log, struct strbuf *in, struct strbuf *out) {\n \n int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)\n {\n+\tconst char *inpath = NULL;\n+\tstruct option options[] = {\n+\t\tOPT_BOOLEAN(0, \"log\", &merge_log, \"populate log with the shortlog\"),\n+\t\tOPT_STRING('F', \"file\", &inpath, \"file\", \"file to read from\"),\n+\t\tOPT_END()\n+\t};\n+\n \tFILE *in = stdin;\n \tstruct strbuf input, output;\n \tint ret;\n \n \tgit_config(fmt_merge_msg_config, NULL);\n-\n-\twhile (argc > 1) {\n-\t\tif (!strcmp(argv[1], \"--log\"))\n-\t\t\tmerge_log = 1;\n-\t\telse if (!strcmp(argv[1], \"--no-log\"))\n-\t\t\tmerge_log = 0;\n-\t\telse if (!strcmp(argv[1], \"-F\") || !strcmp(argv[1], \"--file\")) {\n-\t\t\tif (argc < 3)\n-\t\t\t\tdie (\"Which file?\");\n-\t\t\tif (!strcmp(argv[2], \"-\"))\n-\t\t\t\tin = stdin;\n-\t\t\telse {\n-\t\t\t\tfclose(in);\n-\t\t\t\tin = fopen(argv[2], \"r\");\n-\t\t\t\tif (!in)\n-\t\t\t\t\tdie(\"cannot open %s\", argv[2]);\n-\t\t\t}\n-\t\t\targc--; argv++;\n-\t\t} else\n-\t\t\tbreak;\n-\t\targc--; argv++;\n+\targc = parse_options(argc, argv, options, fmt_merge_msg_usage, 0);\n+\tif (argc > 0)\n+\t\tusage_with_options(fmt_merge_msg_usage, options);\n+\n+\tif (!inpath || strcmp(inpath, \"-\"))\n+\t\tin = stdin;\n+\telse {\n+\t\tfclose(in);\n+\t\tin = fopen(argv[2], \"r\");\n+\t\tif (!in)\n+\t\t\tdie(\"cannot open %s\", argv[2]);\n \t}\n \n-\tif (argc > 1)\n-\t\tusage(fmt_merge_msg_usage);\n-\n \tstrbuf_init(&input, 0);\n \tif (strbuf_read(&input, fileno(in), 0) < 0)\n \t\tdie(\"could not read input file %s\", strerror(errno));\n@@ -381,6 +377,6 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)\n \tret = fmt_merge_msg(merge_log, &input, &output);\n \tif (ret)\n \t\treturn ret;\n-\tprintf(\"%s\", output.buf);\n+\twrite_in_full(STDOUT_FILENO, output.buf, output.len);\n \treturn 0;\n }\n-- \n1.6.0.2.516.g12936\n"},{"id":"91782","messageId":"1222595139-32087-3-git-send-email-madcoder@debian.org","threadId":"15695","inReplyTo":"1222595139-32087-2-git-send-email-madcoder@debian.org","subject":"[PATCH] parse-opt: migrate git-merge-base.","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2008-09-28T09:45:38Z","receivedAt":"2008-09-28T09:45:38Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"Signed-off-by: Pierre Habouzit <madcoder@debian.org>\n---\n builtin-merge-base.c |   37 ++++++++++++++++---------------------\n 1 files changed, 16 insertions(+), 21 deletions(-)\n\ndiff --git a/builtin-merge-base.c b/builtin-merge-base.c\nindex b08da51..03fc1c2 100644\n--- a/builtin-merge-base.c\n+++ b/builtin-merge-base.c\n@@ -1,6 +1,7 @@\n #include \"builtin.h\"\n #include \"cache.h\"\n #include \"commit.h\"\n+#include \"parse-options.h\"\n \n static int show_merge_base(struct commit **rev, int rev_nr, int show_all)\n {\n@@ -21,8 +22,10 @@ static int show_merge_base(struct commit **rev, int rev_nr, int show_all)\n \treturn 0;\n }\n \n-static const char merge_base_usage[] =\n-\"git merge-base [--all] <commit-id> <commit-id>...\";\n+static const char * const merge_base_usage[] = {\n+\t\"git merge-base [--all] <commit-id> <commit-id>...\",\n+\tNULL\n+};\n \n static struct commit *get_commit_reference(const char *arg)\n {\n@@ -44,25 +47,17 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix)\n \tint rev_nr = 0;\n \tint show_all = 0;\n \n-\tgit_config(git_default_config, NULL);\n-\n-\twhile (1 < argc && argv[1][0] == '-') {\n-\t\tconst char *arg = argv[1];\n-\t\tif (!strcmp(arg, \"-a\") || !strcmp(arg, \"--all\"))\n-\t\t\tshow_all = 1;\n-\t\telse\n-\t\t\tusage(merge_base_usage);\n-\t\targc--; argv++;\n-\t}\n-\tif (argc < 3)\n-\t\tusage(merge_base_usage);\n-\n-\trev = xmalloc((argc - 1) * sizeof(*rev));\n-\n-\tdo {\n-\t\trev[rev_nr++] = get_commit_reference(argv[1]);\n-\t\targc--; argv++;\n-\t} while (argc > 1);\n+\tstruct option options[] = {\n+\t\tOPT_BOOLEAN('a', \"all\", &show_all, \"outputs all common ancestors\"),\n+\t\tOPT_END()\n+\t};\n \n+\tgit_config(git_default_config, NULL);\n+\targc = parse_options(argc, argv, options, merge_base_usage, 0);\n+\tif (argc < 2)\n+\t\tusage_with_options(merge_base_usage, options);\n+\trev = xmalloc(argc * sizeof(*rev));\n+\twhile (argc-- > 0)\n+\t\trev[rev_nr++] = get_commit_reference(*argv++);\n \treturn show_merge_base(rev, rev_nr, show_all);\n }\n-- \n1.6.0.2.516.g12936\n"},{"id":"91780","messageId":"1222595139-32087-4-git-send-email-madcoder@debian.org","threadId":"15695","inReplyTo":"1222595139-32087-3-git-send-email-madcoder@debian.org","subject":"[PATCH] parse-opt: migrate builtin-merge-file.","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2008-09-28T09:45:39Z","receivedAt":"2008-09-28T09:45:39Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"Signed-off-by: Pierre Habouzit <madcoder@debian.org>\n---\n builtin-merge-file.c |   68 +++++++++++++++++++++++++++----------------------\n 1 files changed, 37 insertions(+), 31 deletions(-)\n\ndiff --git a/builtin-merge-file.c b/builtin-merge-file.c\nindex 45c9853..7736fe8 100644\n--- a/builtin-merge-file.c\n+++ b/builtin-merge-file.c\n@@ -2,21 +2,44 @@\n #include \"cache.h\"\n #include \"xdiff/xdiff.h\"\n #include \"xdiff-interface.h\"\n+#include \"parse-options.h\"\n \n-static const char merge_file_usage[] =\n-\"git merge-file [-p | --stdout] [--diff3] [-q | --quiet] [-L name1 [-L orig [-L name2]]] file1 orig_file file2\";\n+static const char *const merge_file_usage[] = {\n+\t\"git merge-file [options] [-L name1 [-L orig [-L name2]]] file1 orig_file file2\",\n+\tNULL\n+};\n+\n+static int label_cb(const struct option *opt, const char *arg, int unset)\n+{\n+\tstatic int label_count = 0;\n+\tconst char **names = (const char **)opt->value;\n+\n+\tif (label_count >= 3)\n+\t\treturn error(\"too many labels on the command like\");\n+\tnames[label_count++] = arg;\n+\treturn 0;\n+}\n \n int cmd_merge_file(int argc, const char **argv, const char *prefix)\n {\n-\tconst char *names[3];\n+\tconst char *names[3] = { NULL, NULL, NULL };\n \tmmfile_t mmfs[3];\n \tmmbuffer_t result = {NULL, 0};\n \txpparam_t xpp = {XDF_NEED_MINIMAL};\n \tint ret = 0, i = 0, to_stdout = 0;\n \tint merge_level = XDL_MERGE_ZEALOUS_ALNUM;\n-\tint merge_style = 0;\n+\tint merge_style = 0, quiet = 0;\n \tint nongit;\n \n+\tstruct option options[] = {\n+\t\tOPT_BOOLEAN('p', \"stdout\", &to_stdout, \"send results to standard output\"),\n+\t\tOPT_SET_INT(0, \"diff3\", &merge_style, \"use a diff3 based merge\", XDL_MERGE_DIFF3),\n+\t\tOPT__QUIET(&quiet),\n+\t\tOPT_CALLBACK('L', NULL, names, \"name\",\n+\t\t\t     \"set labels for file1/orig_file/file2\", &label_cb),\n+\t\tOPT_END(),\n+\t};\n+\n \tprefix = setup_git_directory_gently(&nongit);\n \tif (!nongit) {\n \t\t/* Read the configuration file */\n@@ -25,37 +48,20 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)\n \t\t\tmerge_style = git_xmerge_style;\n \t}\n \n-\twhile (argc > 4) {\n-\t\tif (!strcmp(argv[1], \"-L\") && i < 3) {\n-\t\t\tnames[i++] = argv[2];\n-\t\t\targc--;\n-\t\t\targv++;\n-\t\t} else if (!strcmp(argv[1], \"-p\") ||\n-\t\t\t\t!strcmp(argv[1], \"--stdout\"))\n-\t\t\tto_stdout = 1;\n-\t\telse if (!strcmp(argv[1], \"-q\") ||\n-\t\t\t\t!strcmp(argv[1], \"--quiet\"))\n-\t\t\tfreopen(\"/dev/null\", \"w\", stderr);\n-\t\telse if (!strcmp(argv[1], \"--diff3\"))\n-\t\t\tmerge_style = XDL_MERGE_DIFF3;\n-\t\telse\n-\t\t\tusage(merge_file_usage);\n-\t\targc--;\n-\t\targv++;\n-\t}\n-\n-\tif (argc != 4)\n-\t\tusage(merge_file_usage);\n-\n-\tfor (; i < 3; i++)\n-\t\tnames[i] = argv[i + 1];\n+\targc = parse_options(argc, argv, options, merge_file_usage, 0);\n+\tif (argc != 3)\n+\t\tusage_with_options(merge_file_usage, options);\n+\tif (quiet)\n+\t\tfreopen(\"/dev/null\", \"w\", stderr);\n \n \tfor (i = 0; i < 3; i++) {\n-\t\tif (read_mmfile(mmfs + i, argv[i + 1]))\n+\t\tif (!names[i])\n+\t\t\tnames[i] = argv[i];\n+\t\tif (read_mmfile(mmfs + i, argv[i]))\n \t\t\treturn -1;\n \t\tif (buffer_is_binary(mmfs[i].ptr, mmfs[i].size))\n \t\t\treturn error(\"Cannot merge binary files: %s\\n\",\n-\t\t\t\t\targv[i + 1]);\n+\t\t\t\t\targv[i]);\n \t}\n \n \tret = xdl_merge(mmfs + 1, mmfs + 0, names[0], mmfs + 2, names[2],\n@@ -65,7 +71,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)\n \t\tfree(mmfs[i].ptr);\n \n \tif (ret >= 0) {\n-\t\tconst char *filename = argv[1];\n+\t\tconst char *filename = argv[0];\n \t\tFILE *f = to_stdout ? stdout : fopen(filename, \"wb\");\n \n \t\tif (!f)\n-- \n1.6.0.2.516.g12936\n"},{"id":"91793","messageId":"bd6139dc0809280620g2bf80d65k7866aab4a9bbe654@mail.gmail.com","threadId":"15695","inReplyTo":"1222595139-32087-1-git-send-email-madcoder@debian.org","subject":"Re: small warm-up: easy parse-opt migrations.","fromName":"Sverre Rabbelier","fromEmail":"alturin@gmail.com","sentAt":"2008-09-28T13:20:22Z","receivedAt":"2008-09-28T13:20:22Z","isPatch":false,"sender":{"key":"alturin@gmail.com","avatar":null},"body":"On Sun, Sep 28, 2008 at 11:45, Pierre Habouzit <madcoder@debian.org> wrote:\n> There's not a lot to tell, those are just three migration to\n> parse-options.\n\nI think you forgot the -n switch to git format-patch, yes?\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"91861","messageId":"20080929163523.GC18340@spearce.org","threadId":"15695","inReplyTo":"1222595139-32087-2-git-send-email-madcoder@debian.org","subject":"Re: [PATCH] parse-opt: migrate fmt-merge-msg.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-09-29T16:35:23Z","receivedAt":"2008-09-29T16:35:23Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Pierre Habouzit <madcoder@debian.org> wrote:\n> Also fix an inefficient printf(\"%s\", ...) where we can use write_in_full.\n> \n> Signed-off-by: Pierre Habouzit <madcoder@debian.org>\n> ---\n>  builtin-fmt-merge-msg.c |   50 +++++++++++++++++++++-------------------------\n>  1 files changed, 23 insertions(+), 27 deletions(-)\n\nNear as I can tell, this is based upon a merge commit in next.\n\nWe can't do that.  Patches need to be based on master, or worst-case\non a topic head that is in next or pu (in which case the name of\nthe topic, or its tip commit, is helpful in the note).\n\n-- \nShawn.\n"},{"id":"91910","messageId":"20080930084019.GB11453@artemis.corp","threadId":"15695","inReplyTo":"20080929163523.GC18340@spearce.org","subject":"Re: [PATCH] parse-opt: migrate fmt-merge-msg.","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2008-09-30T08:40:20Z","receivedAt":"2008-09-30T08:40:20Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"On Mon, Sep 29, 2008 at 04:35:23PM +0000, Shawn O. Pearce wrote:\n> Pierre Habouzit <madcoder@debian.org> wrote:\n> > Also fix an inefficient printf(\"%s\", ...) where we can use write_in_full.\n> > \n> > Signed-off-by: Pierre Habouzit <madcoder@debian.org>\n> > ---\n> >  builtin-fmt-merge-msg.c |   50 +++++++++++++++++++++-------------------------\n> >  1 files changed, 23 insertions(+), 27 deletions(-)\n> \n> Near as I can tell, this is based upon a merge commit in next.\n> \n> We can't do that.  Patches need to be based on master, or worst-case\n> on a topic head that is in next or pu (in which case the name of\n> the topic, or its tip commit, is helpful in the note).\n\nHmm I've always sent my patches this way, and I believe you can git am\n-3 them on top of master easily. I can send you the updated series if\nyou want.\n-- \n·O·  Pierre Habouzit\n··O                                                madcoder@debian.org\nOOO                                                http://www.madism.org\n"},{"id":"91972","messageId":"20080930191014.GH21310@spearce.org","threadId":"15695","inReplyTo":"20080930084019.GB11453@artemis.corp","subject":"Re: [PATCH] parse-opt: migrate fmt-merge-msg.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-09-30T19:10:14Z","receivedAt":"2008-09-30T19:10:14Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Pierre Habouzit <madcoder@debian.org> wrote:\n> On Mon, Sep 29, 2008 at 04:35:23PM +0000, Shawn O. Pearce wrote:\n> > Pierre Habouzit <madcoder@debian.org> wrote:\n> > > Also fix an inefficient printf(\"%s\", ...) where we can use write_in_full.\n> > \n> > Near as I can tell, this is based upon a merge commit in next.\n> \n> Hmm I've always sent my patches this way, and I believe you can git am\n> -3 them on top of master easily. I can send you the updated series if\n> you want.\n\nI'd appreciate an updated series if you can send it.  am -3 isn't\n\"easily\" applying it.  Here I define \"easy\" as \"the patch applies\nwithout me needing to resolve conflicts\":\n\n $ git co -b ph/parseopt master\n $ git am -3 -s X\n Applying: parse-opt: migrate fmt-merge-msg.\n error: patch failed: builtin-fmt-merge-msg.c:5\n error: builtin-fmt-merge-msg.c: patch does not apply\n Using index info to reconstruct a base tree...\n Falling back to patching base and 3-way merge...\n CONFLICT (content): Merge conflict in builtin-fmt-merge-msg.c\n Recorded preimage for 'builtin-fmt-merge-msg.c'\n Failed to merge in the changes.\n Patch failed at 0001.\n When you have resolved this problem run \"git am -3 --resolved\".\n If you would prefer to skip this patch, instead run \"git am -3 --skip\".\n To restore the original branch and stop patching run \"git am -3 --abort\".\n\n:-\\\n\n-- \nShawn.\n"},{"id":"91990","messageId":"20080930211643.GA16879@artemis.corp","threadId":"15695","inReplyTo":"20080930191014.GH21310@spearce.org","subject":"Re: [PATCH] parse-opt: migrate fmt-merge-msg.","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2008-09-30T21:16:45Z","receivedAt":"2008-09-30T21:16:45Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"On Tue, Sep 30, 2008 at 07:10:14PM +0000, Shawn O. Pearce wrote:\n> Pierre Habouzit <madcoder@debian.org> wrote:\n> > On Mon, Sep 29, 2008 at 04:35:23PM +0000, Shawn O. Pearce wrote:\n> > > Pierre Habouzit <madcoder@debian.org> wrote:\n> > > > Also fix an inefficient printf(\"%s\", ...) where we can use write_in_full.\n> > > \n> > > Near as I can tell, this is based upon a merge commit in next.\n> > \n> > Hmm I've always sent my patches this way, and I believe you can git am\n> > -3 them on top of master easily. I can send you the updated series if\n> > you want.\n> \n> I'd appreciate an updated series if you can send it.  am -3 isn't\n> \"easily\" applying it.  Here I define \"easy\" as \"the patch applies\n> without me needing to resolve conflicts\":\n> \n>  $ git co -b ph/parseopt master\n>  $ git am -3 -s X\n>  Applying: parse-opt: migrate fmt-merge-msg.\n>  error: patch failed: builtin-fmt-merge-msg.c:5\n>  error: builtin-fmt-merge-msg.c: patch does not apply\n>  Using index info to reconstruct a base tree...\n>  Falling back to patching base and 3-way merge...\n>  CONFLICT (content): Merge conflict in builtin-fmt-merge-msg.c\n>  Recorded preimage for 'builtin-fmt-merge-msg.c'\n>  Failed to merge in the changes.\n>  Patch failed at 0001.\n>  When you have resolved this problem run \"git am -3 --resolved\".\n>  If you would prefer to skip this patch, instead run \"git am -3 --skip\".\n>  To restore the original branch and stop patching run \"git am -3 --abort\".\n\nOkay, I will then, but FWIW it means that when you'll try to merge this\nin next it'll conflict at that time, so I'm not sure there's a huge win\nfor you at that point.\n\n-- \n·O·  Pierre Habouzit\n··O                                                madcoder@debian.org\nOOO                                                http://www.madism.org\n"},{"id":"91993","messageId":"20080930224623.GQ21310@spearce.org","threadId":"15695","inReplyTo":"20080930211643.GA16879@artemis.corp","subject":"Re: [PATCH] parse-opt: migrate fmt-merge-msg.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-09-30T22:46:23Z","receivedAt":"2008-09-30T22:46:23Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Pierre Habouzit <madcoder@debian.org> wrote:\n> On Tue, Sep 30, 2008 at 07:10:14PM +0000, Shawn O. Pearce wrote:\n> > Pierre Habouzit <madcoder@debian.org> wrote:\n> > > On Mon, Sep 29, 2008 at 04:35:23PM +0000, Shawn O. Pearce wrote:\n> > > > Pierre Habouzit <madcoder@debian.org> wrote:\n> > > > > Also fix an inefficient printf(\"%s\", ...) where we can use write_in_full.\n> > \n> > I'd appreciate an updated series if you can send it.  am -3 isn't\n> > \"easily\" applying it.\n> \n> Okay, I will then, but FWIW it means that when you'll try to merge this\n> in next it'll conflict at that time, so I'm not sure there's a huge win\n> for you at that point.\n\nIt may actually be a good idea to rebase this against master.\n\nReading Junio's notes for sg/merge-options (the branch this conflict\nis coming out of) it sounds like we'd want to revert that anyway.\nIts been around since April and Junio was talking about it needing\nto be in a 1.7.0 release.  Its not going to graduate anytime soon.\n\nIOW I'm quite tempted to revert sg/merge-options and cancel the\nbranch out of next.\n\n-- \nShawn.\n"},{"id":"92030","messageId":"1222841106-26148-1-git-send-email-madcoder@debian.org","threadId":"15695","inReplyTo":"20080930224623.GQ21310@spearce.org","subject":"[PATCH 1/3] parse-opt: migrate fmt-merge-msg.","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2008-10-01T06:05:04Z","receivedAt":"2008-10-01T06:05:04Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"Also fix an inefficient printf(\"%s\", ...) where we can use write_in_full.\n\nSigned-off-by: Pierre Habouzit <madcoder@debian.org>\n---\n builtin-fmt-merge-msg.c |   52 +++++++++++++++++++++-------------------------\n 1 files changed, 24 insertions(+), 28 deletions(-)\n\n   > It may actually be a good idea to rebase this against master.\n   >\n   > Reading Junio's notes for sg/merge-options (the branch this conflict\n   > is coming out of) it sounds like we'd want to revert that anyway.\n   > Its been around since April and Junio was talking about it needing\n   > to be in a 1.7.0 release.  Its not going to graduate anytime soon.\n\n   Fair enough, here it is.\n\n\ndiff --git a/builtin-fmt-merge-msg.c b/builtin-fmt-merge-msg.c\nindex df02ba7..78c04bf 100644\n--- a/builtin-fmt-merge-msg.c\n+++ b/builtin-fmt-merge-msg.c\n@@ -5,8 +5,10 @@\n #include \"revision.h\"\n #include \"tag.h\"\n \n-static const char *fmt_merge_msg_usage =\n-\t\"git fmt-merge-msg [--log] [--no-log] [--file <file>]\";\n+static const char * const fmt_merge_msg_usage[] = {\n+\t\"git fmt-merge-msg [--log|--no-log] [--file <file>]\",\n+\tNULL\n+};\n \n static int merge_summary;\n \n@@ -347,38 +349,32 @@ int fmt_merge_msg(int merge_summary, struct strbuf *in, struct strbuf *out) {\n \n int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)\n {\n+\tconst char *inpath = NULL;\n+\tstruct option options[] = {\n+\t\tOPT_BOOLEAN(0, \"log\",     &merge_summary, \"populate log with the shortlog\"),\n+\t\tOPT_BOOLEAN(0, \"summary\", &merge_summary, \"alias for --log\"),\n+\t\tOPT_STRING('F', \"file\",   &inpath, \"file\", \"file to read from\"),\n+\t\tOPT_END()\n+\t};\n+\n \tFILE *in = stdin;\n \tstruct strbuf input, output;\n \tint ret;\n \n \tgit_config(fmt_merge_msg_config, NULL);\n-\n-\twhile (argc > 1) {\n-\t\tif (!strcmp(argv[1], \"--log\") || !strcmp(argv[1], \"--summary\"))\n-\t\t\tmerge_summary = 1;\n-\t\telse if (!strcmp(argv[1], \"--no-log\")\n-\t\t\t\t|| !strcmp(argv[1], \"--no-summary\"))\n-\t\t\tmerge_summary = 0;\n-\t\telse if (!strcmp(argv[1], \"-F\") || !strcmp(argv[1], \"--file\")) {\n-\t\t\tif (argc < 3)\n-\t\t\t\tdie (\"Which file?\");\n-\t\t\tif (!strcmp(argv[2], \"-\"))\n-\t\t\t\tin = stdin;\n-\t\t\telse {\n-\t\t\t\tfclose(in);\n-\t\t\t\tin = fopen(argv[2], \"r\");\n-\t\t\t\tif (!in)\n-\t\t\t\t\tdie(\"cannot open %s\", argv[2]);\n-\t\t\t}\n-\t\t\targc--; argv++;\n-\t\t} else\n-\t\t\tbreak;\n-\t\targc--; argv++;\n+\targc = parse_options(argc, argv, options, fmt_merge_msg_usage, 0);\n+\tif (argc > 0)\n+\t\tusage_with_options(fmt_merge_msg_usage, options);\n+\n+\tif (!inpath || strcmp(inpath, \"-\"))\n+\t\tin = stdin;\n+\telse {\n+\t\tfclose(in);\n+\t\tin = fopen(argv[2], \"r\");\n+\t\tif (!in)\n+\t\t\tdie(\"cannot open %s\", argv[2]);\n \t}\n \n-\tif (argc > 1)\n-\t\tusage(fmt_merge_msg_usage);\n-\n \tstrbuf_init(&input, 0);\n \tif (strbuf_read(&input, fileno(in), 0) < 0)\n \t\tdie(\"could not read input file %s\", strerror(errno));\n@@ -387,6 +383,6 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)\n \tret = fmt_merge_msg(merge_summary, &input, &output);\n \tif (ret)\n \t\treturn ret;\n-\tprintf(\"%s\", output.buf);\n+\twrite_in_full(STDOUT_FILENO, output.buf, output.len);\n \treturn 0;\n }\n-- \n1.6.0.2.415.g9800c0.dirty\n"},{"id":"92029","messageId":"1222841106-26148-2-git-send-email-madcoder@debian.org","threadId":"15695","inReplyTo":"1222841106-26148-1-git-send-email-madcoder@debian.org","subject":"[PATCH 2/3] parse-opt: migrate git-merge-base.","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2008-10-01T06:05:05Z","receivedAt":"2008-10-01T06:05:05Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"Signed-off-by: Pierre Habouzit <madcoder@debian.org>\n---\n builtin-merge-base.c |   37 ++++++++++++++++---------------------\n 1 files changed, 16 insertions(+), 21 deletions(-)\n\ndiff --git a/builtin-merge-base.c b/builtin-merge-base.c\nindex b08da51..03fc1c2 100644\n--- a/builtin-merge-base.c\n+++ b/builtin-merge-base.c\n@@ -1,6 +1,7 @@\n #include \"builtin.h\"\n #include \"cache.h\"\n #include \"commit.h\"\n+#include \"parse-options.h\"\n \n static int show_merge_base(struct commit **rev, int rev_nr, int show_all)\n {\n@@ -21,8 +22,10 @@ static int show_merge_base(struct commit **rev, int rev_nr, int show_all)\n \treturn 0;\n }\n \n-static const char merge_base_usage[] =\n-\"git merge-base [--all] <commit-id> <commit-id>...\";\n+static const char * const merge_base_usage[] = {\n+\t\"git merge-base [--all] <commit-id> <commit-id>...\",\n+\tNULL\n+};\n \n static struct commit *get_commit_reference(const char *arg)\n {\n@@ -44,25 +47,17 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix)\n \tint rev_nr = 0;\n \tint show_all = 0;\n \n-\tgit_config(git_default_config, NULL);\n-\n-\twhile (1 < argc && argv[1][0] == '-') {\n-\t\tconst char *arg = argv[1];\n-\t\tif (!strcmp(arg, \"-a\") || !strcmp(arg, \"--all\"))\n-\t\t\tshow_all = 1;\n-\t\telse\n-\t\t\tusage(merge_base_usage);\n-\t\targc--; argv++;\n-\t}\n-\tif (argc < 3)\n-\t\tusage(merge_base_usage);\n-\n-\trev = xmalloc((argc - 1) * sizeof(*rev));\n-\n-\tdo {\n-\t\trev[rev_nr++] = get_commit_reference(argv[1]);\n-\t\targc--; argv++;\n-\t} while (argc > 1);\n+\tstruct option options[] = {\n+\t\tOPT_BOOLEAN('a', \"all\", &show_all, \"outputs all common ancestors\"),\n+\t\tOPT_END()\n+\t};\n \n+\tgit_config(git_default_config, NULL);\n+\targc = parse_options(argc, argv, options, merge_base_usage, 0);\n+\tif (argc < 2)\n+\t\tusage_with_options(merge_base_usage, options);\n+\trev = xmalloc(argc * sizeof(*rev));\n+\twhile (argc-- > 0)\n+\t\trev[rev_nr++] = get_commit_reference(*argv++);\n \treturn show_merge_base(rev, rev_nr, show_all);\n }\n-- \n1.6.0.2.415.g9800c0.dirty\n"},{"id":"92031","messageId":"1222841106-26148-3-git-send-email-madcoder@debian.org","threadId":"15695","inReplyTo":"1222841106-26148-2-git-send-email-madcoder@debian.org","subject":"[PATCH 3/3] parse-opt: migrate builtin-merge-file.","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2008-10-01T06:05:06Z","receivedAt":"2008-10-01T06:05:06Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"Signed-off-by: Pierre Habouzit <madcoder@debian.org>\n---\n builtin-merge-file.c |   68 +++++++++++++++++++++++++++----------------------\n 1 files changed, 37 insertions(+), 31 deletions(-)\n\ndiff --git a/builtin-merge-file.c b/builtin-merge-file.c\nindex 45c9853..7736fe8 100644\n--- a/builtin-merge-file.c\n+++ b/builtin-merge-file.c\n@@ -2,21 +2,44 @@\n #include \"cache.h\"\n #include \"xdiff/xdiff.h\"\n #include \"xdiff-interface.h\"\n+#include \"parse-options.h\"\n \n-static const char merge_file_usage[] =\n-\"git merge-file [-p | --stdout] [--diff3] [-q | --quiet] [-L name1 [-L orig [-L name2]]] file1 orig_file file2\";\n+static const char *const merge_file_usage[] = {\n+\t\"git merge-file [options] [-L name1 [-L orig [-L name2]]] file1 orig_file file2\",\n+\tNULL\n+};\n+\n+static int label_cb(const struct option *opt, const char *arg, int unset)\n+{\n+\tstatic int label_count = 0;\n+\tconst char **names = (const char **)opt->value;\n+\n+\tif (label_count >= 3)\n+\t\treturn error(\"too many labels on the command like\");\n+\tnames[label_count++] = arg;\n+\treturn 0;\n+}\n \n int cmd_merge_file(int argc, const char **argv, const char *prefix)\n {\n-\tconst char *names[3];\n+\tconst char *names[3] = { NULL, NULL, NULL };\n \tmmfile_t mmfs[3];\n \tmmbuffer_t result = {NULL, 0};\n \txpparam_t xpp = {XDF_NEED_MINIMAL};\n \tint ret = 0, i = 0, to_stdout = 0;\n \tint merge_level = XDL_MERGE_ZEALOUS_ALNUM;\n-\tint merge_style = 0;\n+\tint merge_style = 0, quiet = 0;\n \tint nongit;\n \n+\tstruct option options[] = {\n+\t\tOPT_BOOLEAN('p', \"stdout\", &to_stdout, \"send results to standard output\"),\n+\t\tOPT_SET_INT(0, \"diff3\", &merge_style, \"use a diff3 based merge\", XDL_MERGE_DIFF3),\n+\t\tOPT__QUIET(&quiet),\n+\t\tOPT_CALLBACK('L', NULL, names, \"name\",\n+\t\t\t     \"set labels for file1/orig_file/file2\", &label_cb),\n+\t\tOPT_END(),\n+\t};\n+\n \tprefix = setup_git_directory_gently(&nongit);\n \tif (!nongit) {\n \t\t/* Read the configuration file */\n@@ -25,37 +48,20 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)\n \t\t\tmerge_style = git_xmerge_style;\n \t}\n \n-\twhile (argc > 4) {\n-\t\tif (!strcmp(argv[1], \"-L\") && i < 3) {\n-\t\t\tnames[i++] = argv[2];\n-\t\t\targc--;\n-\t\t\targv++;\n-\t\t} else if (!strcmp(argv[1], \"-p\") ||\n-\t\t\t\t!strcmp(argv[1], \"--stdout\"))\n-\t\t\tto_stdout = 1;\n-\t\telse if (!strcmp(argv[1], \"-q\") ||\n-\t\t\t\t!strcmp(argv[1], \"--quiet\"))\n-\t\t\tfreopen(\"/dev/null\", \"w\", stderr);\n-\t\telse if (!strcmp(argv[1], \"--diff3\"))\n-\t\t\tmerge_style = XDL_MERGE_DIFF3;\n-\t\telse\n-\t\t\tusage(merge_file_usage);\n-\t\targc--;\n-\t\targv++;\n-\t}\n-\n-\tif (argc != 4)\n-\t\tusage(merge_file_usage);\n-\n-\tfor (; i < 3; i++)\n-\t\tnames[i] = argv[i + 1];\n+\targc = parse_options(argc, argv, options, merge_file_usage, 0);\n+\tif (argc != 3)\n+\t\tusage_with_options(merge_file_usage, options);\n+\tif (quiet)\n+\t\tfreopen(\"/dev/null\", \"w\", stderr);\n \n \tfor (i = 0; i < 3; i++) {\n-\t\tif (read_mmfile(mmfs + i, argv[i + 1]))\n+\t\tif (!names[i])\n+\t\t\tnames[i] = argv[i];\n+\t\tif (read_mmfile(mmfs + i, argv[i]))\n \t\t\treturn -1;\n \t\tif (buffer_is_binary(mmfs[i].ptr, mmfs[i].size))\n \t\t\treturn error(\"Cannot merge binary files: %s\\n\",\n-\t\t\t\t\targv[i + 1]);\n+\t\t\t\t\targv[i]);\n \t}\n \n \tret = xdl_merge(mmfs + 1, mmfs + 0, names[0], mmfs + 2, names[2],\n@@ -65,7 +71,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)\n \t\tfree(mmfs[i].ptr);\n \n \tif (ret >= 0) {\n-\t\tconst char *filename = argv[1];\n+\t\tconst char *filename = argv[0];\n \t\tFILE *f = to_stdout ? stdout : fopen(filename, \"wb\");\n \n \t\tif (!f)\n-- \n1.6.0.2.415.g9800c0.dirty\n"},{"id":"92055","messageId":"20081001145606.GX21310@spearce.org","threadId":"15695","inReplyTo":"1222841106-26148-1-git-send-email-madcoder@debian.org","subject":"Re: [PATCH 1/3] parse-opt: migrate fmt-merge-msg.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-10-01T14:56:06Z","receivedAt":"2008-10-01T14:56:06Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Pierre Habouzit <madcoder@debian.org> wrote:\n> @@ -347,38 +349,32 @@ int fmt_merge_msg(int merge_summary, struct strbuf *in, struct strbuf *out) {\n>  \n>  int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)\n>  {\n> +\tconst char *inpath = NULL;\n> +\tstruct option options[] = {\n> +\t\tOPT_BOOLEAN(0, \"log\",     &merge_summary, \"populate log with the shortlog\"),\n> +\t\tOPT_BOOLEAN(0, \"summary\", &merge_summary, \"alias for --log\"),\n> +\t\tOPT_STRING('F', \"file\",   &inpath, \"file\", \"file to read from\"),\n> +\t\tOPT_END()\n\n\n> +\targc = parse_options(argc, argv, options, fmt_merge_msg_usage, 0);\n> +\tif (argc > 0)\n> +\t\tusage_with_options(fmt_merge_msg_usage, options);\n> +\n> +\tif (!inpath || strcmp(inpath, \"-\"))\n> +\t\tin = stdin;\n> +\telse {\n> +\t\tfclose(in);\n> +\t\tin = fopen(argv[2], \"r\");\n> +\t\tif (!in)\n> +\t\t\tdie(\"cannot open %s\", argv[2]);\n\nReally argv[2]?  Shouldn't that be inpath?\n\n-- \nShawn.\n"},{"id":"92056","messageId":"20081001150159.GY21310@spearce.org","threadId":"15695","inReplyTo":"1222841106-26148-3-git-send-email-madcoder@debian.org","subject":"Re: [PATCH 3/3] parse-opt: migrate builtin-merge-file.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-10-01T15:01:59Z","receivedAt":"2008-10-01T15:01:59Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Pierre Habouzit <madcoder@debian.org> wrote:\n> diff --git a/builtin-merge-file.c b/builtin-merge-file.c\n> index 45c9853..7736fe8 100644\n> --- a/builtin-merge-file.c\n> +++ b/builtin-merge-file.c\n> @@ -2,21 +2,44 @@\n...\n> +static int label_cb(const struct option *opt, const char *arg, int unset)\n> +{\n> +\tstatic int label_count = 0;\n> +\tconst char **names = (const char **)opt->value;\n> +\n> +\tif (label_count >= 3)\n> +\t\treturn error(\"too many labels on the command like\");\n\nTypo on \"command line\".\n\n-- \nShawn.\n"},{"id":"92141","messageId":"20081002115118.GC17334@artemis.corp","threadId":"15695","inReplyTo":"20081001145606.GX21310@spearce.org","subject":"Re: [PATCH 1/3] parse-opt: migrate fmt-merge-msg.","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2008-10-02T11:51:19Z","receivedAt":"2008-10-02T11:51:19Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"On Wed, Oct 01, 2008 at 02:56:06PM +0000, Shawn O. Pearce wrote:\n> Pierre Habouzit <madcoder@debian.org> wrote:\n> > @@ -347,38 +349,32 @@ int fmt_merge_msg(int merge_summary, struct strbuf *in, struct strbuf *out) {\n> >  \n> >  int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)\n> >  {\n> > +\tconst char *inpath = NULL;\n> > +\tstruct option options[] = {\n> > +\t\tOPT_BOOLEAN(0, \"log\",     &merge_summary, \"populate log with the shortlog\"),\n> > +\t\tOPT_BOOLEAN(0, \"summary\", &merge_summary, \"alias for --log\"),\n> > +\t\tOPT_STRING('F', \"file\",   &inpath, \"file\", \"file to read from\"),\n> > +\t\tOPT_END()\n> \n> \n> > +\targc = parse_options(argc, argv, options, fmt_merge_msg_usage, 0);\n> > +\tif (argc > 0)\n> > +\t\tusage_with_options(fmt_merge_msg_usage, options);\n> > +\n> > +\tif (!inpath || strcmp(inpath, \"-\"))\n> > +\t\tin = stdin;\n> > +\telse {\n> > +\t\tfclose(in);\n> > +\t\tin = fopen(argv[2], \"r\");\n> > +\t\tif (!in)\n> > +\t\t\tdie(\"cannot open %s\", argv[2]);\n> \n> Really argv[2]?  Shouldn't that be inpath?\n\noh crap you're right. I'll submit and updated series soon... *sigh*\n\n-- \n·O·  Pierre Habouzit\n··O                                                madcoder@debian.org\nOOO                                                http://www.madism.org\n"},{"id":"92147","messageId":"1222952360-9262-1-git-send-email-madcoder@debian.org","threadId":"15695","inReplyTo":"20080930224623.GQ21310@spearce.org","subject":"[RESEND PATCH] parse-opt: migrate fmt-merge-msg.","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2008-10-02T12:59:18Z","receivedAt":"2008-10-02T12:59:18Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"Also fix an inefficient printf(\"%s\", ...) where we can use write_in_full.\n\nSigned-off-by: Pierre Habouzit <madcoder@debian.org>\n---\n builtin-fmt-merge-msg.c |   49 ++++++++++++++++++++--------------------------\n 1 files changed, 21 insertions(+), 28 deletions(-)\n\n Also fixes a thinko wrt strcmp(inpath, \"-\"), a ! was missing ;)\n\ndiff --git a/builtin-fmt-merge-msg.c b/builtin-fmt-merge-msg.c\nindex df02ba7..c6324dc 100644\n--- a/builtin-fmt-merge-msg.c\n+++ b/builtin-fmt-merge-msg.c\n@@ -5,8 +5,10 @@\n #include \"revision.h\"\n #include \"tag.h\"\n \n-static const char *fmt_merge_msg_usage =\n-\t\"git fmt-merge-msg [--log] [--no-log] [--file <file>]\";\n+static const char * const fmt_merge_msg_usage[] = {\n+\t\"git fmt-merge-msg [--log|--no-log] [--file <file>]\",\n+\tNULL\n+};\n \n static int merge_summary;\n \n@@ -347,38 +349,29 @@ int fmt_merge_msg(int merge_summary, struct strbuf *in, struct strbuf *out) {\n \n int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)\n {\n+\tconst char *inpath = NULL;\n+\tstruct option options[] = {\n+\t\tOPT_BOOLEAN(0, \"log\",     &merge_summary, \"populate log with the shortlog\"),\n+\t\tOPT_BOOLEAN(0, \"summary\", &merge_summary, \"alias for --log\"),\n+\t\tOPT_STRING('F', \"file\",   &inpath, \"file\", \"file to read from\"),\n+\t\tOPT_END()\n+\t};\n+\n \tFILE *in = stdin;\n \tstruct strbuf input, output;\n \tint ret;\n \n \tgit_config(fmt_merge_msg_config, NULL);\n-\n-\twhile (argc > 1) {\n-\t\tif (!strcmp(argv[1], \"--log\") || !strcmp(argv[1], \"--summary\"))\n-\t\t\tmerge_summary = 1;\n-\t\telse if (!strcmp(argv[1], \"--no-log\")\n-\t\t\t\t|| !strcmp(argv[1], \"--no-summary\"))\n-\t\t\tmerge_summary = 0;\n-\t\telse if (!strcmp(argv[1], \"-F\") || !strcmp(argv[1], \"--file\")) {\n-\t\t\tif (argc < 3)\n-\t\t\t\tdie (\"Which file?\");\n-\t\t\tif (!strcmp(argv[2], \"-\"))\n-\t\t\t\tin = stdin;\n-\t\t\telse {\n-\t\t\t\tfclose(in);\n-\t\t\t\tin = fopen(argv[2], \"r\");\n-\t\t\t\tif (!in)\n-\t\t\t\t\tdie(\"cannot open %s\", argv[2]);\n-\t\t\t}\n-\t\t\targc--; argv++;\n-\t\t} else\n-\t\t\tbreak;\n-\t\targc--; argv++;\n+\targc = parse_options(argc, argv, options, fmt_merge_msg_usage, 0);\n+\tif (argc > 0)\n+\t\tusage_with_options(fmt_merge_msg_usage, options);\n+\n+\tif (inpath && strcmp(inpath, \"-\")) {\n+\t\tin = fopen(inpath, \"r\");\n+\t\tif (!in)\n+\t\t\tdie(\"cannot open %s\", inpath);\n \t}\n \n-\tif (argc > 1)\n-\t\tusage(fmt_merge_msg_usage);\n-\n \tstrbuf_init(&input, 0);\n \tif (strbuf_read(&input, fileno(in), 0) < 0)\n \t\tdie(\"could not read input file %s\", strerror(errno));\n@@ -387,6 +380,6 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)\n \tret = fmt_merge_msg(merge_summary, &input, &output);\n \tif (ret)\n \t\treturn ret;\n-\tprintf(\"%s\", output.buf);\n+\twrite_in_full(STDOUT_FILENO, output.buf, output.len);\n \treturn 0;\n }\n-- \n1.6.0.2.431.gb53ee\n"},{"id":"92145","messageId":"1222952360-9262-2-git-send-email-madcoder@debian.org","threadId":"15695","inReplyTo":"1222952360-9262-1-git-send-email-madcoder@debian.org","subject":"[PATCH] parse-opt: migrate git-merge-base.","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2008-10-02T12:59:19Z","receivedAt":"2008-10-02T12:59:19Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"Signed-off-by: Pierre Habouzit <madcoder@debian.org>\n---\n builtin-merge-base.c |   37 ++++++++++++++++---------------------\n 1 files changed, 16 insertions(+), 21 deletions(-)\n\ndiff --git a/builtin-merge-base.c b/builtin-merge-base.c\nindex b08da51..03fc1c2 100644\n--- a/builtin-merge-base.c\n+++ b/builtin-merge-base.c\n@@ -1,6 +1,7 @@\n #include \"builtin.h\"\n #include \"cache.h\"\n #include \"commit.h\"\n+#include \"parse-options.h\"\n \n static int show_merge_base(struct commit **rev, int rev_nr, int show_all)\n {\n@@ -21,8 +22,10 @@ static int show_merge_base(struct commit **rev, int rev_nr, int show_all)\n \treturn 0;\n }\n \n-static const char merge_base_usage[] =\n-\"git merge-base [--all] <commit-id> <commit-id>...\";\n+static const char * const merge_base_usage[] = {\n+\t\"git merge-base [--all] <commit-id> <commit-id>...\",\n+\tNULL\n+};\n \n static struct commit *get_commit_reference(const char *arg)\n {\n@@ -44,25 +47,17 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix)\n \tint rev_nr = 0;\n \tint show_all = 0;\n \n-\tgit_config(git_default_config, NULL);\n-\n-\twhile (1 < argc && argv[1][0] == '-') {\n-\t\tconst char *arg = argv[1];\n-\t\tif (!strcmp(arg, \"-a\") || !strcmp(arg, \"--all\"))\n-\t\t\tshow_all = 1;\n-\t\telse\n-\t\t\tusage(merge_base_usage);\n-\t\targc--; argv++;\n-\t}\n-\tif (argc < 3)\n-\t\tusage(merge_base_usage);\n-\n-\trev = xmalloc((argc - 1) * sizeof(*rev));\n-\n-\tdo {\n-\t\trev[rev_nr++] = get_commit_reference(argv[1]);\n-\t\targc--; argv++;\n-\t} while (argc > 1);\n+\tstruct option options[] = {\n+\t\tOPT_BOOLEAN('a', \"all\", &show_all, \"outputs all common ancestors\"),\n+\t\tOPT_END()\n+\t};\n \n+\tgit_config(git_default_config, NULL);\n+\targc = parse_options(argc, argv, options, merge_base_usage, 0);\n+\tif (argc < 2)\n+\t\tusage_with_options(merge_base_usage, options);\n+\trev = xmalloc(argc * sizeof(*rev));\n+\twhile (argc-- > 0)\n+\t\trev[rev_nr++] = get_commit_reference(*argv++);\n \treturn show_merge_base(rev, rev_nr, show_all);\n }\n-- \n1.6.0.2.431.gb53ee\n"},{"id":"92146","messageId":"1222952360-9262-3-git-send-email-madcoder@debian.org","threadId":"15695","inReplyTo":"1222952360-9262-2-git-send-email-madcoder@debian.org","subject":"[RESEND PATCH] parse-opt: migrate builtin-merge-file.","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2008-10-02T12:59:20Z","receivedAt":"2008-10-02T12:59:20Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"Signed-off-by: Pierre Habouzit <madcoder@debian.org>\n---\n builtin-merge-file.c |   68 +++++++++++++++++++++++++++----------------------\n 1 files changed, 37 insertions(+), 31 deletions(-)\n\ndiff --git a/builtin-merge-file.c b/builtin-merge-file.c\nindex 45c9853..9d4e874 100644\n--- a/builtin-merge-file.c\n+++ b/builtin-merge-file.c\n@@ -2,21 +2,44 @@\n #include \"cache.h\"\n #include \"xdiff/xdiff.h\"\n #include \"xdiff-interface.h\"\n+#include \"parse-options.h\"\n \n-static const char merge_file_usage[] =\n-\"git merge-file [-p | --stdout] [--diff3] [-q | --quiet] [-L name1 [-L orig [-L name2]]] file1 orig_file file2\";\n+static const char *const merge_file_usage[] = {\n+\t\"git merge-file [options] [-L name1 [-L orig [-L name2]]] file1 orig_file file2\",\n+\tNULL\n+};\n+\n+static int label_cb(const struct option *opt, const char *arg, int unset)\n+{\n+\tstatic int label_count = 0;\n+\tconst char **names = (const char **)opt->value;\n+\n+\tif (label_count >= 3)\n+\t\treturn error(\"too many labels on the command line\");\n+\tnames[label_count++] = arg;\n+\treturn 0;\n+}\n \n int cmd_merge_file(int argc, const char **argv, const char *prefix)\n {\n-\tconst char *names[3];\n+\tconst char *names[3] = { NULL, NULL, NULL };\n \tmmfile_t mmfs[3];\n \tmmbuffer_t result = {NULL, 0};\n \txpparam_t xpp = {XDF_NEED_MINIMAL};\n \tint ret = 0, i = 0, to_stdout = 0;\n \tint merge_level = XDL_MERGE_ZEALOUS_ALNUM;\n-\tint merge_style = 0;\n+\tint merge_style = 0, quiet = 0;\n \tint nongit;\n \n+\tstruct option options[] = {\n+\t\tOPT_BOOLEAN('p', \"stdout\", &to_stdout, \"send results to standard output\"),\n+\t\tOPT_SET_INT(0, \"diff3\", &merge_style, \"use a diff3 based merge\", XDL_MERGE_DIFF3),\n+\t\tOPT__QUIET(&quiet),\n+\t\tOPT_CALLBACK('L', NULL, names, \"name\",\n+\t\t\t     \"set labels for file1/orig_file/file2\", &label_cb),\n+\t\tOPT_END(),\n+\t};\n+\n \tprefix = setup_git_directory_gently(&nongit);\n \tif (!nongit) {\n \t\t/* Read the configuration file */\n@@ -25,37 +48,20 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)\n \t\t\tmerge_style = git_xmerge_style;\n \t}\n \n-\twhile (argc > 4) {\n-\t\tif (!strcmp(argv[1], \"-L\") && i < 3) {\n-\t\t\tnames[i++] = argv[2];\n-\t\t\targc--;\n-\t\t\targv++;\n-\t\t} else if (!strcmp(argv[1], \"-p\") ||\n-\t\t\t\t!strcmp(argv[1], \"--stdout\"))\n-\t\t\tto_stdout = 1;\n-\t\telse if (!strcmp(argv[1], \"-q\") ||\n-\t\t\t\t!strcmp(argv[1], \"--quiet\"))\n-\t\t\tfreopen(\"/dev/null\", \"w\", stderr);\n-\t\telse if (!strcmp(argv[1], \"--diff3\"))\n-\t\t\tmerge_style = XDL_MERGE_DIFF3;\n-\t\telse\n-\t\t\tusage(merge_file_usage);\n-\t\targc--;\n-\t\targv++;\n-\t}\n-\n-\tif (argc != 4)\n-\t\tusage(merge_file_usage);\n-\n-\tfor (; i < 3; i++)\n-\t\tnames[i] = argv[i + 1];\n+\targc = parse_options(argc, argv, options, merge_file_usage, 0);\n+\tif (argc != 3)\n+\t\tusage_with_options(merge_file_usage, options);\n+\tif (quiet)\n+\t\tfreopen(\"/dev/null\", \"w\", stderr);\n \n \tfor (i = 0; i < 3; i++) {\n-\t\tif (read_mmfile(mmfs + i, argv[i + 1]))\n+\t\tif (!names[i])\n+\t\t\tnames[i] = argv[i];\n+\t\tif (read_mmfile(mmfs + i, argv[i]))\n \t\t\treturn -1;\n \t\tif (buffer_is_binary(mmfs[i].ptr, mmfs[i].size))\n \t\t\treturn error(\"Cannot merge binary files: %s\\n\",\n-\t\t\t\t\targv[i + 1]);\n+\t\t\t\t\targv[i]);\n \t}\n \n \tret = xdl_merge(mmfs + 1, mmfs + 0, names[0], mmfs + 2, names[2],\n@@ -65,7 +71,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)\n \t\tfree(mmfs[i].ptr);\n \n \tif (ret >= 0) {\n-\t\tconst char *filename = argv[1];\n+\t\tconst char *filename = argv[0];\n \t\tFILE *f = to_stdout ? stdout : fopen(filename, \"wb\");\n \n \t\tif (!f)\n-- \n1.6.0.2.431.gb53ee\n"}]}