{"thread":{"id":"19380","subject":"[PATCH 2/3] tests: Add tests for missing format-patch long options","startedAt":"2009-05-16T09:24:44Z","lastAt":"2009-05-17T21:30:04Z","messageCount":5,"participants":["Stephen Boyd"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"114084","messageId":"1242465886-31769-1-git-send-email-bebarino@gmail.com","threadId":"19380","inReplyTo":null,"subject":"[PATCH 1/3] api-parse-options.txt: use 'func' instead of 'funct'","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-05-16T09:24:44Z","receivedAt":"2009-05-16T09:24:44Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"\nSigned-off-by: Stephen Boyd <bebarino@gmail.com>\n---\n Documentation/technical/api-parse-options.txt |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/technical/api-parse-options.txt b/Documentation/technical/api-parse-options.txt\nindex e66ca9f..e30c602 100644\n--- a/Documentation/technical/api-parse-options.txt\n+++ b/Documentation/technical/api-parse-options.txt\n@@ -198,7 +198,7 @@ The function must be defined in this form:\n \n The callback mechanism is as follows:\n \n-* Inside `funct`, the only interesting member of the structure\n+* Inside `func`, the only interesting member of the structure\n   given by `opt` is the void pointer `opt->value`.\n   `\\*opt->value` will be the value that is saved into `var`, if you\n   use `OPT_CALLBACK()`.\n-- \n1.6.3.1.9.g95405b\n"},{"id":"114083","messageId":"1242465886-31769-2-git-send-email-bebarino@gmail.com","threadId":"19380","inReplyTo":"1242465886-31769-1-git-send-email-bebarino@gmail.com","subject":"[PATCH 2/3] tests: Add tests for missing format-patch long options","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-05-16T09:24:45Z","receivedAt":"2009-05-16T09:24:45Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"Exercise format-patch's --signoff, --in-reply-to and --start-number long\noptions.\n\nSigned-off-by: Stephen Boyd <bebarino@gmail.com>\n---\n t/t4014-format-patch.sh          |   11 +++++++++++\n t/t4021-format-patch-numbered.sh |    6 ++++++\n 2 files changed, 17 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\nindex 11061dd..922a894 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -505,4 +505,15 @@ test_expect_success 'format-patch from a subdirectory (3)' '\n \ttest -f \"$basename\"\n '\n \n+test_expect_success 'format-patch --in-reply-to' '\n+\tgit format-patch -1 --stdout --in-reply-to \"baz@foo.bar\" > patch8 &&\n+\tgrep \"^In-Reply-To: <baz@foo.bar>\" patch8 &&\n+\tgrep \"^References: <baz@foo.bar>\" patch8\n+'\n+\n+test_expect_success 'format-patch --signoff' '\n+\tgit format-patch -1 --signoff --stdout |\n+\tgrep \"^Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>\"\n+'\n+\n test_done\ndiff --git a/t/t4021-format-patch-numbered.sh b/t/t4021-format-patch-numbered.sh\nindex 390af23..3c27f0d 100755\n--- a/t/t4021-format-patch-numbered.sh\n+++ b/t/t4021-format-patch-numbered.sh\n@@ -108,4 +108,10 @@ test_expect_success 'format.numbered = auto && --no-numbered' '\n \n '\n \n+test_expect_success '--start-number && --numbered' '\n+\n+\tgit format-patch --start-number 3 --numbered --stdout HEAD~1 > patch8 &&\n+\tgrep \"^Subject: \\[PATCH 3/3\\]\" patch8\n+'\n+\n test_done\n-- \n1.6.3.1.9.g95405b\n"},{"id":"114085","messageId":"1242465886-31769-3-git-send-email-bebarino@gmail.com","threadId":"19380","inReplyTo":"1242465886-31769-2-git-send-email-bebarino@gmail.com","subject":"[PATCH 3/3] format-patch: migrate to parse-options API","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-05-16T09:24:46Z","receivedAt":"2009-05-16T09:24:46Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"\nSigned-off-by: Stephen Boyd <bebarino@gmail.com>\n---\n\nI know that two patch series are coming which will conflict. One is already\nin next, ca6b91d (format-patch let -k override format.numbered, 2009-05-09).\nI will send a patch against next as a followup, just in case.\n\n builtin-log.c |  255 +++++++++++++++++++++++++++++++++++----------------------\n 1 files changed, 158 insertions(+), 97 deletions(-)\n\ndiff --git a/builtin-log.c b/builtin-log.c\nindex 5eaec5d..2a35b6b 100644\n--- a/builtin-log.c\n+++ b/builtin-log.c\n@@ -18,6 +18,7 @@\n #include \"shortlog.h\"\n #include \"remote.h\"\n #include \"string-list.h\"\n+#include \"parse-options.h\"\n \n /* Set a default date-time format for git log (\"log.date\" config variable) */\n static const char *default_date_mode = NULL;\n@@ -740,17 +741,117 @@ static const char *set_outdir(const char *prefix, const char *output_directory)\n \t\t\t\t       output_directory));\n }\n \n+static const char * const builtin_format_patch_usage[] = {\n+\t\"git format-patch [options] [<since> | <revision range>]\",\n+\tNULL\n+};\n+\n+static int keep_subject = 0;\n+\n+static int keep_callback(const struct option *opt, const char *arg, int unset)\n+{\n+\t((struct rev_info *)opt->value)->total = -1;\n+\tkeep_subject = 1;\n+\treturn 0;\n+}\n+\n+static int subject_prefix = 0;\n+\n+static int subject_prefix_callback(const struct option *opt, const char *arg,\n+\t\t\t    int unset)\n+{\n+\tsubject_prefix = 1;\n+\t((struct rev_info *)opt->value)->subject_prefix = arg;\n+\treturn 0;\n+}\n+\n+static int numbered_callback(const struct option *opt, const char *arg,\n+\t\t\t     int unset)\n+{\n+\t*(int *)opt->value = unset ? 0 : 1;\n+\tif (unset)\n+\t\tauto_number =  0;\n+\treturn 0;\n+}\n+\n+static int no_numbered_callback(const struct option *opt, const char *arg,\n+\t\t\t\tint unset)\n+{\n+\treturn numbered_callback(opt, arg, 1);\n+}\n+\n+static int output_directory_callback(const struct option *opt, const char *arg,\n+\t\t\t      int unset)\n+{\n+\tconst char **dir = (const char **)opt->value;\n+\tif (*dir)\n+\t\tdie(\"Two output directories?\");\n+\t*dir = arg;\n+\treturn 0;\n+}\n+\n+static int thread_callback(const struct option *opt, const char *arg, int unset)\n+{\n+\tint *thread = (int *)opt->value;\n+\tif (unset)\n+\t\t*thread = 0;\n+\telse if (!arg || !strcmp(arg, \"shallow\"))\n+\t\t*thread = THREAD_SHALLOW;\n+\telse if (!strcmp(arg, \"deep\"))\n+\t\t*thread = THREAD_DEEP;\n+\telse\n+\t\treturn 1;\n+\treturn 0;\n+}\n+\n+static int attach_callback(const struct option *opt, const char *arg, int unset)\n+{\n+\tstruct rev_info *rev = (struct rev_info *)opt->value;\n+\tif (unset)\n+\t\trev->mime_boundary = NULL;\n+\telse if (arg)\n+\t\trev->mime_boundary = arg;\n+\telse\n+\t\trev->mime_boundary = git_version_string;\n+\trev->no_inline = unset ? 0 : 1;\n+\treturn 0;\n+}\n+\n+static int inline_callback(const struct option *opt, const char *arg, int unset)\n+{\n+\tstruct rev_info *rev = (struct rev_info *)opt->value;\n+\tif (unset)\n+\t\trev->mime_boundary = NULL;\n+\telse if (arg)\n+\t\trev->mime_boundary = arg;\n+\telse\n+\t\trev->mime_boundary = git_version_string;\n+\trev->no_inline = 0;\n+\treturn 0;\n+}\n+\n+static int header_callback(const struct option *opt, const char *arg, int unset)\n+{\n+\tadd_header(arg);\n+\treturn 0;\n+}\n+\n+static int cc_callback(const struct option *opt, const char *arg, int unset)\n+{\n+\tALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc);\n+\textra_cc[extra_cc_nr++] = xstrdup(arg);\n+\treturn 0;\n+}\n+\n int cmd_format_patch(int argc, const char **argv, const char *prefix)\n {\n \tstruct commit *commit;\n \tstruct commit **list = NULL;\n \tstruct rev_info rev;\n-\tint nr = 0, total, i, j;\n+\tint nr = 0, total, i;\n \tint use_stdout = 0;\n \tint start_number = -1;\n-\tint keep_subject = 0;\n \tint numbered_files = 0;\t\t/* _just_ numbers */\n-\tint subject_prefix = 0;\n \tint ignore_if_in_upstream = 0;\n \tint cover_letter = 0;\n \tint boundary_count = 0;\n@@ -760,6 +861,57 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \tstruct patch_ids ids;\n \tchar *add_signoff = NULL;\n \tstruct strbuf buf = STRBUF_INIT;\n+\tconst struct option builtin_format_patch_options[] = {\n+\t\t{ OPTION_CALLBACK, 'n', \"numbered\", &numbered, NULL,\n+\t\t\t    \"use [PATCH n/m] even with a single patch\",\n+\t\t\t    PARSE_OPT_NOARG, numbered_callback },\n+\t\t{ OPTION_CALLBACK, 'N', \"no-numbered\", &numbered, NULL,\n+\t\t\t    \"use [PATCH] even with a multiple patches\",\n+\t\t\t    PARSE_OPT_NOARG, no_numbered_callback },\n+\t\tOPT_BOOLEAN('s', \"signoff\", &do_signoff, \"add Signed-off-by:\"),\n+\t\tOPT_BOOLEAN(0, \"stdout\", &use_stdout,\n+\t\t\t    \"print patches to standard out\"),\n+\t\tOPT_BOOLEAN(0, \"cover-letter\", &cover_letter,\n+\t\t\t    \"generate a cover letter\"),\n+\t\tOPT_BOOLEAN(0, \"numbered-files\", &numbered_files,\n+\t\t\t    \"use simple number sequence for output file names\"),\n+\t\tOPT_STRING(0, \"suffix\", &fmt_patch_suffix, \"sfx\",\n+\t\t\t    \"use <sfx> instead of '.patch'\"),\n+\t\tOPT_INTEGER(0, \"start-number\", &start_number,\n+\t\t\t    \"start numbering patches at <n> instead of 1\"),\n+\t\t{ OPTION_CALLBACK, 0, \"subject-prefix\", &rev, \"prefix\",\n+\t\t\t    \"Use [<prefix>] instead of [PATCH]\",\n+\t\t\t    PARSE_OPT_NONEG, subject_prefix_callback },\n+\t\t{ OPTION_CALLBACK, 'o', \"output-directory\", &output_directory,\n+\t\t\t    \"dir\", \"store resulting files in <dir>\",\n+\t\t\t    PARSE_OPT_NONEG, output_directory_callback },\n+\t\t{ OPTION_CALLBACK, 'k', \"keep-subject\", &rev, NULL,\n+\t\t\t    \"don't strip/add [PATCH]\",\n+\t\t\t    PARSE_OPT_NOARG | PARSE_OPT_NONEG, keep_callback },\n+\t\tOPT_BOOLEAN(0, \"no-binary\", &no_binary_diff,\n+\t\t\t    \"don't output binary diffs\"),\n+\t\tOPT_BOOLEAN(0, \"ignore-if-in-upstream\", &ignore_if_in_upstream,\n+\t\t\t    \"don't include a patch matching a commit upstream\"),\n+\t\tOPT_GROUP(\"Messaging\"),\n+\t\t{ OPTION_CALLBACK, 0, \"add-header\", NULL, \"header\",\n+\t\t\t    \"add email header\", PARSE_OPT_NONEG,\n+\t\t\t    header_callback },\n+\t\t{ OPTION_CALLBACK, 0, \"cc\", NULL, \"email\", \"add Cc: header\",\n+\t\t\t    PARSE_OPT_NONEG, cc_callback },\n+\t\tOPT_STRING(0, \"in-reply-to\", &in_reply_to, \"message-id\",\n+\t\t\t    \"make first mail a reply to <message-id>\"),\n+\t\t{ OPTION_CALLBACK, 0, \"attach\", &rev, \"boundary\",\n+\t\t\t    \"attach the patch\", PARSE_OPT_OPTARG,\n+\t\t\t    attach_callback },\n+\t\t{ OPTION_CALLBACK, 0, \"inline\", &rev, \"boundary\",\n+\t\t\t    \"inline the patch\",\n+\t\t\t    PARSE_OPT_OPTARG | PARSE_OPT_NONEG,\n+\t\t\t    inline_callback },\n+\t\t{ OPTION_CALLBACK, 0, \"thread\", &thread, \"style\",\n+\t\t\t    \"enable message threading, styles: shallow, deep\",\n+\t\t\t    PARSE_OPT_OPTARG, thread_callback },\n+\t\tOPT_END()\n+\t};\n \n \tgit_config(git_format_config, NULL);\n \tinit_revisions(&rev, prefix);\n@@ -782,100 +934,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t * like \"git format-patch -o a123 HEAD^..\" may fail; a123 is\n \t * possibly a valid SHA1.\n \t */\n-\tfor (i = 1, j = 1; i < argc; i++) {\n-\t\tif (!strcmp(argv[i], \"--stdout\"))\n-\t\t\tuse_stdout = 1;\n-\t\telse if (!strcmp(argv[i], \"-n\") ||\n-\t\t\t\t!strcmp(argv[i], \"--numbered\"))\n-\t\t\tnumbered = 1;\n-\t\telse if (!strcmp(argv[i], \"-N\") ||\n-\t\t\t\t!strcmp(argv[i], \"--no-numbered\")) {\n-\t\t\tnumbered = 0;\n-\t\t\tauto_number = 0;\n-\t\t}\n-\t\telse if (!prefixcmp(argv[i], \"--start-number=\"))\n-\t\t\tstart_number = strtol(argv[i] + 15, NULL, 10);\n-\t\telse if (!strcmp(argv[i], \"--numbered-files\"))\n-\t\t\tnumbered_files = 1;\n-\t\telse if (!strcmp(argv[i], \"--start-number\")) {\n-\t\t\ti++;\n-\t\t\tif (i == argc)\n-\t\t\t\tdie(\"Need a number for --start-number\");\n-\t\t\tstart_number = strtol(argv[i], NULL, 10);\n-\t\t}\n-\t\telse if (!prefixcmp(argv[i], \"--cc=\")) {\n-\t\t\tALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc);\n-\t\t\textra_cc[extra_cc_nr++] = xstrdup(argv[i] + 5);\n-\t\t}\n-\t\telse if (!strcmp(argv[i], \"-k\") ||\n-\t\t\t\t!strcmp(argv[i], \"--keep-subject\")) {\n-\t\t\tkeep_subject = 1;\n-\t\t\trev.total = -1;\n-\t\t}\n-\t\telse if (!strcmp(argv[i], \"--output-directory\") ||\n-\t\t\t !strcmp(argv[i], \"-o\")) {\n-\t\t\ti++;\n-\t\t\tif (argc <= i)\n-\t\t\t\tdie(\"Which directory?\");\n-\t\t\tif (output_directory)\n-\t\t\t\tdie(\"Two output directories?\");\n-\t\t\toutput_directory = argv[i];\n-\t\t}\n-\t\telse if (!strcmp(argv[i], \"--signoff\") ||\n-\t\t\t !strcmp(argv[i], \"-s\")) {\n-\t\t\tdo_signoff = 1;\n-\t\t}\n-\t\telse if (!strcmp(argv[i], \"--attach\")) {\n-\t\t\trev.mime_boundary = git_version_string;\n-\t\t\trev.no_inline = 1;\n-\t\t}\n-\t\telse if (!prefixcmp(argv[i], \"--attach=\")) {\n-\t\t\trev.mime_boundary = argv[i] + 9;\n-\t\t\trev.no_inline = 1;\n-\t\t}\n-\t\telse if (!strcmp(argv[i], \"--no-attach\")) {\n-\t\t\trev.mime_boundary = NULL;\n-\t\t\trev.no_inline = 0;\n-\t\t}\n-\t\telse if (!strcmp(argv[i], \"--inline\")) {\n-\t\t\trev.mime_boundary = git_version_string;\n-\t\t\trev.no_inline = 0;\n-\t\t}\n-\t\telse if (!prefixcmp(argv[i], \"--inline=\")) {\n-\t\t\trev.mime_boundary = argv[i] + 9;\n-\t\t\trev.no_inline = 0;\n-\t\t}\n-\t\telse if (!strcmp(argv[i], \"--ignore-if-in-upstream\"))\n-\t\t\tignore_if_in_upstream = 1;\n-\t\telse if (!strcmp(argv[i], \"--thread\")\n-\t\t\t|| !strcmp(argv[i], \"--thread=shallow\"))\n-\t\t\tthread = THREAD_SHALLOW;\n-\t\telse if (!strcmp(argv[i], \"--thread=deep\"))\n-\t\t\tthread = THREAD_DEEP;\n-\t\telse if (!strcmp(argv[i], \"--no-thread\"))\n-\t\t\tthread = 0;\n-\t\telse if (!prefixcmp(argv[i], \"--in-reply-to=\"))\n-\t\t\tin_reply_to = argv[i] + 14;\n-\t\telse if (!strcmp(argv[i], \"--in-reply-to\")) {\n-\t\t\ti++;\n-\t\t\tif (i == argc)\n-\t\t\t\tdie(\"Need a Message-Id for --in-reply-to\");\n-\t\t\tin_reply_to = argv[i];\n-\t\t} else if (!prefixcmp(argv[i], \"--subject-prefix=\")) {\n-\t\t\tsubject_prefix = 1;\n-\t\t\trev.subject_prefix = argv[i] + 17;\n-\t\t} else if (!prefixcmp(argv[i], \"--suffix=\"))\n-\t\t\tfmt_patch_suffix = argv[i] + 9;\n-\t\telse if (!strcmp(argv[i], \"--cover-letter\"))\n-\t\t\tcover_letter = 1;\n-\t\telse if (!strcmp(argv[i], \"--no-binary\"))\n-\t\t\tno_binary_diff = 1;\n-\t\telse if (!prefixcmp(argv[i], \"--add-header=\"))\n-\t\t\tadd_header(argv[i] + 13);\n-\t\telse\n-\t\t\targv[j++] = argv[i];\n-\t}\n-\targc = j;\n+\targc = parse_options(argc, argv, builtin_format_patch_options,\n+\t\t\t     builtin_format_patch_usage,\n+\t\t\t     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN);\n \n \tif (do_signoff) {\n \t\tconst char *committer;\n-- \n1.6.3.1.9.g95405b\n"},{"id":"114086","messageId":"1242466062-31997-1-git-send-email-bebarino@gmail.com","threadId":"19380","inReplyTo":"1242465886-31769-3-git-send-email-bebarino@gmail.com","subject":"[PATCH] format-patch: migrate to parse-options API","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-05-16T09:27:42Z","receivedAt":"2009-05-16T09:27:42Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"\nSigned-off-by: Stephen Boyd <bebarino@gmail.com>\n---\n\nThis is against next. Essentially numbered_cmdline_opt becomes global and\nis assigned to in the callback.\n\n builtin-log.c |  260 +++++++++++++++++++++++++++++++++++----------------------\n 1 files changed, 160 insertions(+), 100 deletions(-)\n\ndiff --git a/builtin-log.c b/builtin-log.c\nindex f10cfeb..2acf2cd 100644\n--- a/builtin-log.c\n+++ b/builtin-log.c\n@@ -18,6 +18,7 @@\n #include \"shortlog.h\"\n #include \"remote.h\"\n #include \"string-list.h\"\n+#include \"parse-options.h\"\n \n /* Set a default date-time format for git log (\"log.date\" config variable) */\n static const char *default_date_mode = NULL;\n@@ -740,27 +741,179 @@ static const char *set_outdir(const char *prefix, const char *output_directory)\n \t\t\t\t       output_directory));\n }\n \n+static const char * const builtin_format_patch_usage[] = {\n+\t\"git format-patch [options] [<since> | <revision range>]\",\n+\tNULL\n+};\n+\n+static int keep_subject = 0;\n+\n+static int keep_callback(const struct option *opt, const char *arg, int unset)\n+{\n+\t((struct rev_info *)opt->value)->total = -1;\n+\tkeep_subject = 1;\n+\treturn 0;\n+}\n+\n+static int subject_prefix = 0;\n+\n+static int subject_prefix_callback(const struct option *opt, const char *arg,\n+\t\t\t    int unset)\n+{\n+\tsubject_prefix = 1;\n+\t((struct rev_info *)opt->value)->subject_prefix = arg;\n+\treturn 0;\n+}\n+\n+static int numbered_cmdline_opt = 0;\n+\n+static int numbered_callback(const struct option *opt, const char *arg,\n+\t\t\t     int unset)\n+{\n+\t*(int *)opt->value = numbered_cmdline_opt = unset ? 0 : 1;\n+\tif (unset)\n+\t\tauto_number =  0;\n+\treturn 0;\n+}\n+\n+static int no_numbered_callback(const struct option *opt, const char *arg,\n+\t\t\t\tint unset)\n+{\n+\treturn numbered_callback(opt, arg, 1);\n+}\n+\n+static int output_directory_callback(const struct option *opt, const char *arg,\n+\t\t\t      int unset)\n+{\n+\tconst char **dir = (const char **)opt->value;\n+\tif (*dir)\n+\t\tdie(\"Two output directories?\");\n+\t*dir = arg;\n+\treturn 0;\n+}\n+\n+static int thread_callback(const struct option *opt, const char *arg, int unset)\n+{\n+\tint *thread = (int *)opt->value;\n+\tif (unset)\n+\t\t*thread = 0;\n+\telse if (!arg || !strcmp(arg, \"shallow\"))\n+\t\t*thread = THREAD_SHALLOW;\n+\telse if (!strcmp(arg, \"deep\"))\n+\t\t*thread = THREAD_DEEP;\n+\telse\n+\t\treturn 1;\n+\treturn 0;\n+}\n+\n+static int attach_callback(const struct option *opt, const char *arg, int unset)\n+{\n+\tstruct rev_info *rev = (struct rev_info *)opt->value;\n+\tif (unset)\n+\t\trev->mime_boundary = NULL;\n+\telse if (arg)\n+\t\trev->mime_boundary = arg;\n+\telse\n+\t\trev->mime_boundary = git_version_string;\n+\trev->no_inline = unset ? 0 : 1;\n+\treturn 0;\n+}\n+\n+static int inline_callback(const struct option *opt, const char *arg, int unset)\n+{\n+\tstruct rev_info *rev = (struct rev_info *)opt->value;\n+\tif (unset)\n+\t\trev->mime_boundary = NULL;\n+\telse if (arg)\n+\t\trev->mime_boundary = arg;\n+\telse\n+\t\trev->mime_boundary = git_version_string;\n+\trev->no_inline = 0;\n+\treturn 0;\n+}\n+\n+static int header_callback(const struct option *opt, const char *arg, int unset)\n+{\n+\tadd_header(arg);\n+\treturn 0;\n+}\n+\n+static int cc_callback(const struct option *opt, const char *arg, int unset)\n+{\n+\tALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc);\n+\textra_cc[extra_cc_nr++] = xstrdup(arg);\n+\treturn 0;\n+}\n+\n int cmd_format_patch(int argc, const char **argv, const char *prefix)\n {\n \tstruct commit *commit;\n \tstruct commit **list = NULL;\n \tstruct rev_info rev;\n-\tint nr = 0, total, i, j;\n+\tint nr = 0, total, i;\n \tint use_stdout = 0;\n \tint start_number = -1;\n-\tint keep_subject = 0;\n \tint numbered_files = 0;\t\t/* _just_ numbers */\n-\tint subject_prefix = 0;\n \tint ignore_if_in_upstream = 0;\n \tint cover_letter = 0;\n \tint boundary_count = 0;\n \tint no_binary_diff = 0;\n-\tint numbered_cmdline_opt = 0;\n \tstruct commit *origin = NULL, *head = NULL;\n \tconst char *in_reply_to = NULL;\n \tstruct patch_ids ids;\n \tchar *add_signoff = NULL;\n \tstruct strbuf buf = STRBUF_INIT;\n+\tconst struct option builtin_format_patch_options[] = {\n+\t\t{ OPTION_CALLBACK, 'n', \"numbered\", &numbered, NULL,\n+\t\t\t    \"use [PATCH n/m] even with a single patch\",\n+\t\t\t    PARSE_OPT_NOARG, numbered_callback },\n+\t\t{ OPTION_CALLBACK, 'N', \"no-numbered\", &numbered, NULL,\n+\t\t\t    \"use [PATCH] even with a multiple patches\",\n+\t\t\t    PARSE_OPT_NOARG, no_numbered_callback },\n+\t\tOPT_BOOLEAN('s', \"signoff\", &do_signoff, \"add Signed-off-by:\"),\n+\t\tOPT_BOOLEAN(0, \"stdout\", &use_stdout,\n+\t\t\t    \"print patches to standard out\"),\n+\t\tOPT_BOOLEAN(0, \"cover-letter\", &cover_letter,\n+\t\t\t    \"generate a cover letter\"),\n+\t\tOPT_BOOLEAN(0, \"numbered-files\", &numbered_files,\n+\t\t\t    \"use simple number sequence for output file names\"),\n+\t\tOPT_STRING(0, \"suffix\", &fmt_patch_suffix, \"sfx\",\n+\t\t\t    \"use <sfx> instead of '.patch'\"),\n+\t\tOPT_INTEGER(0, \"start-number\", &start_number,\n+\t\t\t    \"start numbering patches at <n> instead of 1\"),\n+\t\t{ OPTION_CALLBACK, 0, \"subject-prefix\", &rev, \"prefix\",\n+\t\t\t    \"Use [<prefix>] instead of [PATCH]\",\n+\t\t\t    PARSE_OPT_NONEG, subject_prefix_callback },\n+\t\t{ OPTION_CALLBACK, 'o', \"output-directory\", &output_directory,\n+\t\t\t    \"dir\", \"store resulting files in <dir>\",\n+\t\t\t    PARSE_OPT_NONEG, output_directory_callback },\n+\t\t{ OPTION_CALLBACK, 'k', \"keep-subject\", &rev, NULL,\n+\t\t\t    \"don't strip/add [PATCH]\",\n+\t\t\t    PARSE_OPT_NOARG | PARSE_OPT_NONEG, keep_callback },\n+\t\tOPT_BOOLEAN(0, \"no-binary\", &no_binary_diff,\n+\t\t\t    \"don't output binary diffs\"),\n+\t\tOPT_BOOLEAN(0, \"ignore-if-in-upstream\", &ignore_if_in_upstream,\n+\t\t\t    \"don't include a patch matching a commit upstream\"),\n+\t\tOPT_GROUP(\"Messaging\"),\n+\t\t{ OPTION_CALLBACK, 0, \"add-header\", NULL, \"header\",\n+\t\t\t    \"add email header\", PARSE_OPT_NONEG,\n+\t\t\t    header_callback },\n+\t\t{ OPTION_CALLBACK, 0, \"cc\", NULL, \"email\", \"add Cc: header\",\n+\t\t\t    PARSE_OPT_NONEG, cc_callback },\n+\t\tOPT_STRING(0, \"in-reply-to\", &in_reply_to, \"message-id\",\n+\t\t\t    \"make first mail a reply to <message-id>\"),\n+\t\t{ OPTION_CALLBACK, 0, \"attach\", &rev, \"boundary\",\n+\t\t\t    \"attach the patch\", PARSE_OPT_OPTARG,\n+\t\t\t    attach_callback },\n+\t\t{ OPTION_CALLBACK, 0, \"inline\", &rev, \"boundary\",\n+\t\t\t    \"inline the patch\",\n+\t\t\t    PARSE_OPT_OPTARG | PARSE_OPT_NONEG,\n+\t\t\t    inline_callback },\n+\t\t{ OPTION_CALLBACK, 0, \"thread\", &thread, \"style\",\n+\t\t\t    \"enable message threading, styles: shallow, deep\",\n+\t\t\t    PARSE_OPT_OPTARG, thread_callback },\n+\t\tOPT_END()\n+\t};\n \n \tgit_config(git_format_config, NULL);\n \tinit_revisions(&rev, prefix);\n@@ -783,102 +936,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t * like \"git format-patch -o a123 HEAD^..\" may fail; a123 is\n \t * possibly a valid SHA1.\n \t */\n-\tfor (i = 1, j = 1; i < argc; i++) {\n-\t\tif (!strcmp(argv[i], \"--stdout\"))\n-\t\t\tuse_stdout = 1;\n-\t\telse if (!strcmp(argv[i], \"-n\") ||\n-\t\t\t\t!strcmp(argv[i], \"--numbered\")) {\n-\t\t\tnumbered = 1;\n-\t\t\tnumbered_cmdline_opt = 1;\n-\t\t}\n-\t\telse if (!strcmp(argv[i], \"-N\") ||\n-\t\t\t\t!strcmp(argv[i], \"--no-numbered\")) {\n-\t\t\tnumbered = 0;\n-\t\t\tauto_number = 0;\n-\t\t}\n-\t\telse if (!prefixcmp(argv[i], \"--start-number=\"))\n-\t\t\tstart_number = strtol(argv[i] + 15, NULL, 10);\n-\t\telse if (!strcmp(argv[i], \"--numbered-files\"))\n-\t\t\tnumbered_files = 1;\n-\t\telse if (!strcmp(argv[i], \"--start-number\")) {\n-\t\t\ti++;\n-\t\t\tif (i == argc)\n-\t\t\t\tdie(\"Need a number for --start-number\");\n-\t\t\tstart_number = strtol(argv[i], NULL, 10);\n-\t\t}\n-\t\telse if (!prefixcmp(argv[i], \"--cc=\")) {\n-\t\t\tALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc);\n-\t\t\textra_cc[extra_cc_nr++] = xstrdup(argv[i] + 5);\n-\t\t}\n-\t\telse if (!strcmp(argv[i], \"-k\") ||\n-\t\t\t\t!strcmp(argv[i], \"--keep-subject\")) {\n-\t\t\tkeep_subject = 1;\n-\t\t\trev.total = -1;\n-\t\t}\n-\t\telse if (!strcmp(argv[i], \"--output-directory\") ||\n-\t\t\t !strcmp(argv[i], \"-o\")) {\n-\t\t\ti++;\n-\t\t\tif (argc <= i)\n-\t\t\t\tdie(\"Which directory?\");\n-\t\t\tif (output_directory)\n-\t\t\t\tdie(\"Two output directories?\");\n-\t\t\toutput_directory = argv[i];\n-\t\t}\n-\t\telse if (!strcmp(argv[i], \"--signoff\") ||\n-\t\t\t !strcmp(argv[i], \"-s\")) {\n-\t\t\tdo_signoff = 1;\n-\t\t}\n-\t\telse if (!strcmp(argv[i], \"--attach\")) {\n-\t\t\trev.mime_boundary = git_version_string;\n-\t\t\trev.no_inline = 1;\n-\t\t}\n-\t\telse if (!prefixcmp(argv[i], \"--attach=\")) {\n-\t\t\trev.mime_boundary = argv[i] + 9;\n-\t\t\trev.no_inline = 1;\n-\t\t}\n-\t\telse if (!strcmp(argv[i], \"--no-attach\")) {\n-\t\t\trev.mime_boundary = NULL;\n-\t\t\trev.no_inline = 0;\n-\t\t}\n-\t\telse if (!strcmp(argv[i], \"--inline\")) {\n-\t\t\trev.mime_boundary = git_version_string;\n-\t\t\trev.no_inline = 0;\n-\t\t}\n-\t\telse if (!prefixcmp(argv[i], \"--inline=\")) {\n-\t\t\trev.mime_boundary = argv[i] + 9;\n-\t\t\trev.no_inline = 0;\n-\t\t}\n-\t\telse if (!strcmp(argv[i], \"--ignore-if-in-upstream\"))\n-\t\t\tignore_if_in_upstream = 1;\n-\t\telse if (!strcmp(argv[i], \"--thread\")\n-\t\t\t|| !strcmp(argv[i], \"--thread=shallow\"))\n-\t\t\tthread = THREAD_SHALLOW;\n-\t\telse if (!strcmp(argv[i], \"--thread=deep\"))\n-\t\t\tthread = THREAD_DEEP;\n-\t\telse if (!strcmp(argv[i], \"--no-thread\"))\n-\t\t\tthread = 0;\n-\t\telse if (!prefixcmp(argv[i], \"--in-reply-to=\"))\n-\t\t\tin_reply_to = argv[i] + 14;\n-\t\telse if (!strcmp(argv[i], \"--in-reply-to\")) {\n-\t\t\ti++;\n-\t\t\tif (i == argc)\n-\t\t\t\tdie(\"Need a Message-Id for --in-reply-to\");\n-\t\t\tin_reply_to = argv[i];\n-\t\t} else if (!prefixcmp(argv[i], \"--subject-prefix=\")) {\n-\t\t\tsubject_prefix = 1;\n-\t\t\trev.subject_prefix = argv[i] + 17;\n-\t\t} else if (!prefixcmp(argv[i], \"--suffix=\"))\n-\t\t\tfmt_patch_suffix = argv[i] + 9;\n-\t\telse if (!strcmp(argv[i], \"--cover-letter\"))\n-\t\t\tcover_letter = 1;\n-\t\telse if (!strcmp(argv[i], \"--no-binary\"))\n-\t\t\tno_binary_diff = 1;\n-\t\telse if (!prefixcmp(argv[i], \"--add-header=\"))\n-\t\t\tadd_header(argv[i] + 13);\n-\t\telse\n-\t\t\targv[j++] = argv[i];\n-\t}\n-\targc = j;\n+\targc = parse_options(argc, argv, builtin_format_patch_options,\n+\t\t\t     builtin_format_patch_usage,\n+\t\t\t     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN);\n \n \tif (do_signoff) {\n \t\tconst char *committer;\n-- \n1.6.3.1.9.g95405b\n"},{"id":"114146","messageId":"4A1081DC.9030403@gmail.com","threadId":"19380","inReplyTo":"1242465886-31769-3-git-send-email-bebarino@gmail.com","subject":"Re: [PATCH 3/3] format-patch: migrate to parse-options API","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-05-17T21:30:04Z","receivedAt":"2009-05-17T21:30:04Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"Oops there's a typo. Junio, can you squash this in?\n\nThanks,\n-Stephen\n\ndiff --git a/builtin-log.c b/builtin-log.c\nindex 3a8b9fa..d522b3d 100644\n--- a/builtin-log.c\n+++ b/builtin-log.c\n@@ -868,7 +868,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n                            \"use [PATCH n/m] even with a single patch\",\n                            PARSE_OPT_NOARG, numbered_callback },\n                { OPTION_CALLBACK, 'N', \"no-numbered\", &numbered, NULL,\n-                           \"use [PATCH] even with a multiple patches\",\n+                           \"use [PATCH] even with multiple patches\",\n                            PARSE_OPT_NOARG, no_numbered_callback },\n                OPT_BOOLEAN('s', \"signoff\", &do_signoff, \"add Signed-off-by:\"),\n                OPT_BOOLEAN(0, \"stdout\", &use_stdout,\n"}]}