{"thread":{"id":"48527","subject":"[PATCH] Use OPT_SET_INT_F() for cmdline option specification","startedAt":"2018-05-20T08:12:58Z","lastAt":"2018-05-20T15:43:22Z","messageCount":4,"participants":["Nguyễn Thái Ngọc Duy","Martin Ågren","Duy Nguyen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"348082","messageId":"20180520081244.14619-1-pclouds@gmail.com","threadId":"48527","inReplyTo":null,"subject":"[PATCH] Use OPT_SET_INT_F() for cmdline option specification","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-05-20T08:12:44Z","receivedAt":"2018-05-20T08:12:58Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"The only thing these commands need is extra parseopt flags which can be\npassed in by OPT_SET_INT_F() and it is a bit more compact than full\nstruct initialization.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n archive.c              |  6 ++----\n builtin/am.c           | 12 ++++++------\n builtin/branch.c       |  4 ++--\n builtin/difftool.c     |  9 ++++-----\n builtin/fetch.c        |  6 +++---\n builtin/grep.c         |  6 +++---\n builtin/log.c          |  6 +++---\n builtin/ls-files.c     |  6 +++---\n builtin/merge.c        |  6 +++---\n builtin/notes.c        | 12 ++++++------\n builtin/pack-objects.c | 24 ++++++++++++------------\n 11 files changed, 47 insertions(+), 50 deletions(-)\n\ndiff --git a/archive.c b/archive.c\nindex 93ab175b0b..4fe7bec60c 100644\n--- a/archive.c\n+++ b/archive.c\n@@ -411,11 +411,9 @@ static void parse_treeish_arg(const char **argv,\n }\n \n #define OPT__COMPR(s, v, h, p) \\\n-\t{ OPTION_SET_INT, (s), NULL, (v), NULL, (h), \\\n-\t  PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, (p) }\n+\tOPT_SET_INT_F(s, NULL, v, h, p, PARSE_OPT_NONEG)\n #define OPT__COMPR_HIDDEN(s, v, p) \\\n-\t{ OPTION_SET_INT, (s), NULL, (v), NULL, \"\", \\\n-\t  PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_HIDDEN, NULL, (p) }\n+\tOPT_SET_INT_F(s, NULL, v, \"\", p, PARSE_OPT_NONEG | PARSE_OPT_HIDDEN)\n \n static int parse_archive_args(int argc, const char **argv,\n \t\tconst struct archiver **ar, struct archiver_args *args,\ndiff --git a/builtin/am.c b/builtin/am.c\nindex d834f9e62b..666287b497 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -2231,12 +2231,12 @@ int cmd_am(int argc, const char **argv, const char *prefix)\n \t\t\tN_(\"pass -b flag to git-mailinfo\"), KEEP_NON_PATCH),\n \t\tOPT_BOOL('m', \"message-id\", &state.message_id,\n \t\t\tN_(\"pass -m flag to git-mailinfo\")),\n-\t\t{ OPTION_SET_INT, 0, \"keep-cr\", &keep_cr, NULL,\n-\t\t  N_(\"pass --keep-cr flag to git-mailsplit for mbox format\"),\n-\t\t  PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1},\n-\t\t{ OPTION_SET_INT, 0, \"no-keep-cr\", &keep_cr, NULL,\n-\t\t  N_(\"do not pass --keep-cr flag to git-mailsplit independent of am.keepcr\"),\n-\t\t  PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 0},\n+\t\tOPT_SET_INT_F(0, \"keep-cr\", &keep_cr,\n+\t\t\tN_(\"pass --keep-cr flag to git-mailsplit for mbox format\"),\n+\t\t\t1, PARSE_OPT_NONEG),\n+\t\tOPT_SET_INT_F(0, \"no-keep-cr\", &keep_cr,\n+\t\t\tN_(\"do not pass --keep-cr flag to git-mailsplit for mbox format\"),\n+\t\t\t0, PARSE_OPT_NONEG),\n \t\tOPT_BOOL('c', \"scissors\", &state.scissors,\n \t\t\tN_(\"strip everything before a scissors line\")),\n \t\tOPT_PASSTHRU_ARGV(0, \"whitespace\", &state.git_apply_opts, N_(\"action\"),\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex efc9ac1922..cc089f9efb 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -592,8 +592,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\tOPT__QUIET(&quiet, N_(\"suppress informational messages\")),\n \t\tOPT_SET_INT('t', \"track\",  &track, N_(\"set up tracking mode (see git-pull(1))\"),\n \t\t\tBRANCH_TRACK_EXPLICIT),\n-\t\t{ OPTION_SET_INT, 0, \"set-upstream\", &track, NULL, N_(\"do not use\"),\n-\t\t\tPARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, BRANCH_TRACK_OVERRIDE },\n+\t\tOPT_SET_INT_F(0, \"set-upstream\", &track, N_(\"do not use\"),\n+\t\t\tBRANCH_TRACK_OVERRIDE, PARSE_OPT_HIDDEN),\n \t\tOPT_STRING('u', \"set-upstream-to\", &new_upstream, N_(\"upstream\"), N_(\"change the upstream info\")),\n \t\tOPT_BOOL(0, \"unset-upstream\", &unset_upstream, N_(\"Unset the upstream info\")),\n \t\tOPT__COLOR(&branch_use_color, N_(\"use colored output\")),\ndiff --git a/builtin/difftool.c b/builtin/difftool.c\nindex aad0e073ee..c439b64207 100644\n--- a/builtin/difftool.c\n+++ b/builtin/difftool.c\n@@ -695,12 +695,11 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)\n \t\t\t N_(\"use `diff.guitool` instead of `diff.tool`\")),\n \t\tOPT_BOOL('d', \"dir-diff\", &dir_diff,\n \t\t\t N_(\"perform a full-directory diff\")),\n-\t\t{ OPTION_SET_INT, 'y', \"no-prompt\", &prompt, NULL,\n+\t\tOPT_SET_INT_F('y', \"no-prompt\", &prompt,\n \t\t\tN_(\"do not prompt before launching a diff tool\"),\n-\t\t\tPARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 0},\n-\t\t{ OPTION_SET_INT, 0, \"prompt\", &prompt, NULL, NULL,\n-\t\t\tPARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_HIDDEN,\n-\t\t\tNULL, 1 },\n+\t\t\t0, PARSE_OPT_NONEG),\n+\t\tOPT_SET_INT_F(0, \"prompt\", &prompt, NULL,\n+\t\t\t1, PARSE_OPT_NONEG | PARSE_OPT_HIDDEN),\n \t\tOPT_BOOL(0, \"symlinks\", &symlinks,\n \t\t\t N_(\"use symlinks in dir-diff mode\")),\n \t\tOPT_STRING('t', \"tool\", &difftool_cmd, N_(\"<tool>\"),\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 7ee83ac0f8..b6530a5ce0 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -156,9 +156,9 @@ static struct option builtin_fetch_options[] = {\n \t\t\tN_(\"deepen history of shallow clone, excluding rev\")),\n \tOPT_INTEGER(0, \"deepen\", &deepen_relative,\n \t\t    N_(\"deepen history of shallow clone\")),\n-\t{ OPTION_SET_INT, 0, \"unshallow\", &unshallow, NULL,\n-\t\t   N_(\"convert to a complete repository\"),\n-\t\t   PARSE_OPT_NONEG | PARSE_OPT_NOARG, NULL, 1 },\n+\tOPT_SET_INT_F(0, \"unshallow\", &unshallow,\n+\t\t      N_(\"convert to a complete repository\"),\n+\t\t      1, PARSE_OPT_NONEG),\n \t{ OPTION_STRING, 0, \"submodule-prefix\", &submodule_prefix, N_(\"dir\"),\n \t\t   N_(\"prepend this to submodule path output\"), PARSE_OPT_HIDDEN },\n \t{ OPTION_CALLBACK, 0, \"recurse-submodules-default\",\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 6e7bc76785..850bcffd99 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -885,9 +885,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\t\t   N_(\"indicate hit with exit status without output\")),\n \t\tOPT_BOOL(0, \"all-match\", &opt.all_match,\n \t\t\tN_(\"show only matches from files that match all patterns\")),\n-\t\t{ OPTION_SET_INT, 0, \"debug\", &opt.debug, NULL,\n-\t\t  N_(\"show parse tree for grep expression\"),\n-\t\t  PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1 },\n+\t\tOPT_SET_INT_F(0, \"debug\", &opt.debug,\n+\t\t\t      N_(\"show parse tree for grep expression\"),\n+\t\t\t      1, PARSE_OPT_HIDDEN),\n \t\tOPT_GROUP(\"\"),\n \t\t{ OPTION_STRING, 'O', \"open-files-in-pager\", &show_in_pager,\n \t\t\tN_(\"pager\"), N_(\"show matching files in the pager\"),\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 71f68a3e4f..8f27921505 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1474,9 +1474,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\t\t N_(\"output all-zero hash in From header\")),\n \t\tOPT_BOOL(0, \"ignore-if-in-upstream\", &ignore_if_in_upstream,\n \t\t\t N_(\"don't include a patch matching a commit upstream\")),\n-\t\t{ OPTION_SET_INT, 'p', \"no-stat\", &use_patch_format, NULL,\n-\t\t  N_(\"show patch format instead of default (patch + stat)\"),\n-\t\t  PARSE_OPT_NONEG | PARSE_OPT_NOARG, NULL, 1},\n+\t\tOPT_SET_INT_F('p', \"no-stat\", &use_patch_format,\n+\t\t\t      N_(\"show patch format instead of default (patch + stat)\"),\n+\t\t\t      1, PARSE_OPT_NONEG),\n \t\tOPT_GROUP(N_(\"Messaging\")),\n \t\t{ OPTION_CALLBACK, 0, \"add-header\", NULL, N_(\"header\"),\n \t\t\t    N_(\"add email header\"), 0, header_callback },\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex a71f6bd088..40d9138c46 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -556,9 +556,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)\n \t\t{ OPTION_CALLBACK, 0, \"exclude-standard\", &dir, NULL,\n \t\t\tN_(\"add the standard git exclusions\"),\n \t\t\tPARSE_OPT_NOARG, option_parse_exclude_standard },\n-\t\t{ OPTION_SET_INT, 0, \"full-name\", &prefix_len, NULL,\n-\t\t\tN_(\"make the output relative to the project top directory\"),\n-\t\t\tPARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL },\n+\t\tOPT_SET_INT_F(0, \"full-name\", &prefix_len,\n+\t\t\t      N_(\"make the output relative to the project top directory\"),\n+\t\t\t      0, PARSE_OPT_NONEG),\n \t\tOPT_BOOL(0, \"recurse-submodules\", &recurse_submodules,\n \t\t\tN_(\"recurse through submodules\")),\n \t\tOPT_BOOL(0, \"error-unmatch\", &error_unmatch,\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 9db5a2cf16..4be71dd81b 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -213,9 +213,9 @@ static struct option builtin_merge_options[] = {\n \tOPT_BOOL('e', \"edit\", &option_edit,\n \t\tN_(\"edit message before committing\")),\n \tOPT_SET_INT(0, \"ff\", &fast_forward, N_(\"allow fast-forward (default)\"), FF_ALLOW),\n-\t{ OPTION_SET_INT, 0, \"ff-only\", &fast_forward, NULL,\n-\t\tN_(\"abort if fast-forward is not possible\"),\n-\t\tPARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, FF_ONLY },\n+\tOPT_SET_INT_F(0, \"ff-only\", &fast_forward,\n+\t\t      N_(\"abort if fast-forward is not possible\"),\n+\t\t      FF_ONLY, PARSE_OPT_NONEG),\n \tOPT_RERERE_AUTOUPDATE(&allow_rerere_auto),\n \tOPT_BOOL(0, \"verify-signatures\", &verify_signatures,\n \t\tN_(\"verify that the named commit has a valid GPG signature\")),\ndiff --git a/builtin/notes.c b/builtin/notes.c\nindex e5bf80eef1..4d34994c34 100644\n--- a/builtin/notes.c\n+++ b/builtin/notes.c\n@@ -778,13 +778,13 @@ static int merge(int argc, const char **argv, const char *prefix)\n \t\t\t   N_(\"resolve notes conflicts using the given strategy \"\n \t\t\t      \"(manual/ours/theirs/union/cat_sort_uniq)\")),\n \t\tOPT_GROUP(N_(\"Committing unmerged notes\")),\n-\t\t{ OPTION_SET_INT, 0, \"commit\", &do_commit, NULL,\n-\t\t\tN_(\"finalize notes merge by committing unmerged notes\"),\n-\t\t\tPARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1},\n+\t\tOPT_SET_INT_F(0, \"commit\", &do_commit,\n+\t\t\t      N_(\"finalize notes merge by committing unmerged notes\"),\n+\t\t\t      1, PARSE_OPT_NONEG),\n \t\tOPT_GROUP(N_(\"Aborting notes merge resolution\")),\n-\t\t{ OPTION_SET_INT, 0, \"abort\", &do_abort, NULL,\n-\t\t\tN_(\"abort notes merge\"),\n-\t\t\tPARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1},\n+\t\tOPT_SET_INT_F(0, \"abort\", &do_abort,\n+\t\t\t      N_(\"abort notes merge\"),\n+\t\t\t      1, PARSE_OPT_NONEG),\n \t\tOPT_END()\n \t};\n \ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex 24b1c6c5dd..5134c655c7 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -2992,18 +2992,18 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)\n \t\t\t N_(\"do not create an empty pack output\")),\n \t\tOPT_BOOL(0, \"revs\", &use_internal_rev_list,\n \t\t\t N_(\"read revision arguments from standard input\")),\n-\t\t{ OPTION_SET_INT, 0, \"unpacked\", &rev_list_unpacked, NULL,\n-\t\t  N_(\"limit the objects to those that are not yet packed\"),\n-\t\t  PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1 },\n-\t\t{ OPTION_SET_INT, 0, \"all\", &rev_list_all, NULL,\n-\t\t  N_(\"include objects reachable from any reference\"),\n-\t\t  PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1 },\n-\t\t{ OPTION_SET_INT, 0, \"reflog\", &rev_list_reflog, NULL,\n-\t\t  N_(\"include objects referred by reflog entries\"),\n-\t\t  PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1 },\n-\t\t{ OPTION_SET_INT, 0, \"indexed-objects\", &rev_list_index, NULL,\n-\t\t  N_(\"include objects referred to by the index\"),\n-\t\t  PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1 },\n+\t\tOPT_SET_INT_F(0, \"unpacked\", &rev_list_unpacked,\n+\t\t\t      N_(\"limit the objects to those that are not yet packed\"),\n+\t\t\t      1, PARSE_OPT_NONEG),\n+\t\tOPT_SET_INT_F(0, \"all\", &rev_list_all,\n+\t\t\t      N_(\"include objects reachable from any reference\"),\n+\t\t\t      1, PARSE_OPT_NONEG),\n+\t\tOPT_SET_INT_F(0, \"reflog\", &rev_list_reflog,\n+\t\t\t      N_(\"include objects referred by reflog entries\"),\n+\t\t\t      1, PARSE_OPT_NONEG),\n+\t\tOPT_SET_INT_F(0, \"indexed-objects\", &rev_list_index,\n+\t\t\t      N_(\"include objects referred to by the index\"),\n+\t\t\t      1, PARSE_OPT_NONEG),\n \t\tOPT_BOOL(0, \"stdout\", &pack_to_stdout,\n \t\t\t N_(\"output pack to stdout\")),\n \t\tOPT_BOOL(0, \"include-tag\", &include_tag,\n-- \n2.17.0.705.g3525833791\n\n"},{"id":"348083","messageId":"CAN0heSpdtiUVSYGsT+VnUaSy0BO+p+mnod6Ut4Y3UrNVVQkrbA@mail.gmail.com","threadId":"48527","inReplyTo":"20180520081244.14619-1-pclouds@gmail.com","subject":"Re: [PATCH] Use OPT_SET_INT_F() for cmdline option specification","fromName":"Martin Ågren","fromEmail":"martin.agren@gmail.com","sentAt":"2018-05-20T09:15:58Z","receivedAt":"2018-05-20T09:16:02Z","isPatch":true,"sender":{"key":"martin.agren@gmail.com","avatar":null},"body":"On 20 May 2018 at 10:12, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:\n> The only thing these commands need is extra parseopt flags which can be\n> passed in by OPT_SET_INT_F() and it is a bit more compact than full\n> struct initialization.\n\n> diff --git a/archive.c b/archive.c\n> index 93ab175b0b..4fe7bec60c 100644\n> --- a/archive.c\n> +++ b/archive.c\n> @@ -411,11 +411,9 @@ static void parse_treeish_arg(const char **argv,\n>  }\n>\n>  #define OPT__COMPR(s, v, h, p) \\\n> -       { OPTION_SET_INT, (s), NULL, (v), NULL, (h), \\\n> -         PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, (p) }\n> +       OPT_SET_INT_F(s, NULL, v, h, p, PARSE_OPT_NONEG)\n>  #define OPT__COMPR_HIDDEN(s, v, p) \\\n> -       { OPTION_SET_INT, (s), NULL, (v), NULL, \"\", \\\n> -         PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_HIDDEN, NULL, (p) }\n> +       OPT_SET_INT_F(s, NULL, v, \"\", p, PARSE_OPT_NONEG | PARSE_OPT_HIDDEN)\n\nRight. We have NULLs in the fifth and the second-to-last positions, and\nwe use PARSE_OPT_NOARG.  By switching to OPT_SET_INT_F we get those for\nfree.\n\nDo we want to keep \"(s)\" instead of \"s\", just to be safe? And same for\n\"(v)\", \"(p)\". Macro expansion always makes me paranoid.\n\n> diff --git a/builtin/am.c b/builtin/am.c\n> index d834f9e62b..666287b497 100644\n> --- a/builtin/am.c\n> +++ b/builtin/am.c\n> @@ -2231,12 +2231,12 @@ int cmd_am(int argc, const char **argv, const char *prefix)\n>                         N_(\"pass -b flag to git-mailinfo\"), KEEP_NON_PATCH),\n>                 OPT_BOOL('m', \"message-id\", &state.message_id,\n>                         N_(\"pass -m flag to git-mailinfo\")),\n> -               { OPTION_SET_INT, 0, \"keep-cr\", &keep_cr, NULL,\n> -                 N_(\"pass --keep-cr flag to git-mailsplit for mbox format\"),\n> -                 PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1},\n> -               { OPTION_SET_INT, 0, \"no-keep-cr\", &keep_cr, NULL,\n> -                 N_(\"do not pass --keep-cr flag to git-mailsplit independent of am.keepcr\"),\n> -                 PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 0},\n> +               OPT_SET_INT_F(0, \"keep-cr\", &keep_cr,\n> +                       N_(\"pass --keep-cr flag to git-mailsplit for mbox format\"),\n> +                       1, PARSE_OPT_NONEG),\n> +               OPT_SET_INT_F(0, \"no-keep-cr\", &keep_cr,\n> +                       N_(\"do not pass --keep-cr flag to git-mailsplit for mbox format\"),\n> +                       0, PARSE_OPT_NONEG),\n\nI found `-w` and `--word-diff` useful. You actually change the N_(\"...\")\nfor `--no-keep-cr` here: [-independent of am.keepcr-]{+for mbox format+}\nCopy-paste mistake?\n\nOther than that, `--word-diff` has a very structured appearance and\nnothing stood out. The ordering is different (f goes at the end in the\npost-image), which makes the diff busier than it would have had to be.\n(That's obviously nothing this patch can do anything about.)\n\nMartin\n"},{"id":"348101","messageId":"CACsJy8DxvZXw=J=Hh-TKL-2B+dcj2OV-CzTUuBBBxecDuAQrZQ@mail.gmail.com","threadId":"48527","inReplyTo":"CAN0heSpdtiUVSYGsT+VnUaSy0BO+p+mnod6Ut4Y3UrNVVQkrbA@mail.gmail.com","subject":"Re: [PATCH] Use OPT_SET_INT_F() for cmdline option specification","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-05-20T15:40:29Z","receivedAt":"2018-05-20T15:41:03Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sun, May 20, 2018 at 11:15 AM, Martin Ågren <martin.agren@gmail.com> wrote:\n> On 20 May 2018 at 10:12, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:\n>> The only thing these commands need is extra parseopt flags which can be\n>> passed in by OPT_SET_INT_F() and it is a bit more compact than full\n>> struct initialization.\n>\n>> diff --git a/archive.c b/archive.c\n>> index 93ab175b0b..4fe7bec60c 100644\n>> --- a/archive.c\n>> +++ b/archive.c\n>> @@ -411,11 +411,9 @@ static void parse_treeish_arg(const char **argv,\n>>  }\n>>\n>>  #define OPT__COMPR(s, v, h, p) \\\n>> -       { OPTION_SET_INT, (s), NULL, (v), NULL, (h), \\\n>> -         PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, (p) }\n>> +       OPT_SET_INT_F(s, NULL, v, h, p, PARSE_OPT_NONEG)\n>>  #define OPT__COMPR_HIDDEN(s, v, p) \\\n>> -       { OPTION_SET_INT, (s), NULL, (v), NULL, \"\", \\\n>> -         PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_HIDDEN, NULL, (p) }\n>> +       OPT_SET_INT_F(s, NULL, v, \"\", p, PARSE_OPT_NONEG | PARSE_OPT_HIDDEN)\n>\n> Right. We have NULLs in the fifth and the second-to-last positions, and\n> we use PARSE_OPT_NOARG.  By switching to OPT_SET_INT_F we get those for\n> free.\n>\n> Do we want to keep \"(s)\" instead of \"s\", just to be safe? And same for\n> \"(v)\", \"(p)\". Macro expansion always makes me paranoid.\n\nThey are still wrapped in () in the end by OPT_SET_INT_F() so the\nexpanded struct initialization  is the same. I think we're fine here.\n\n>> diff --git a/builtin/am.c b/builtin/am.c\n>> index d834f9e62b..666287b497 100644\n>> --- a/builtin/am.c\n>> +++ b/builtin/am.c\n>> @@ -2231,12 +2231,12 @@ int cmd_am(int argc, const char **argv, const char *prefix)\n>>                         N_(\"pass -b flag to git-mailinfo\"), KEEP_NON_PATCH),\n>>                 OPT_BOOL('m', \"message-id\", &state.message_id,\n>>                         N_(\"pass -m flag to git-mailinfo\")),\n>> -               { OPTION_SET_INT, 0, \"keep-cr\", &keep_cr, NULL,\n>> -                 N_(\"pass --keep-cr flag to git-mailsplit for mbox format\"),\n>> -                 PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1},\n>> -               { OPTION_SET_INT, 0, \"no-keep-cr\", &keep_cr, NULL,\n>> -                 N_(\"do not pass --keep-cr flag to git-mailsplit independent of am.keepcr\"),\n>> -                 PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 0},\n>> +               OPT_SET_INT_F(0, \"keep-cr\", &keep_cr,\n>> +                       N_(\"pass --keep-cr flag to git-mailsplit for mbox format\"),\n>> +                       1, PARSE_OPT_NONEG),\n>> +               OPT_SET_INT_F(0, \"no-keep-cr\", &keep_cr,\n>> +                       N_(\"do not pass --keep-cr flag to git-mailsplit for mbox format\"),\n>> +                       0, PARSE_OPT_NONEG),\n>\n> I found `-w` and `--word-diff` useful. You actually change the N_(\"...\")\n> for `--no-keep-cr` here: [-independent of am.keepcr-]{+for mbox format+}\n> Copy-paste mistake?\n\nOops. You're correct. Fixed in v2.\n\n>\n> Other than that, `--word-diff` has a very structured appearance and\n> nothing stood out. The ordering is different (f goes at the end in the\n> post-image), which makes the diff busier than it would have had to be.\n> (That's obviously nothing this patch can do anything about.)\n>\n> Martin\n-- \nDuy\n"},{"id":"348102","messageId":"20180520154258.28866-1-pclouds@gmail.com","threadId":"48527","inReplyTo":"20180520081244.14619-1-pclouds@gmail.com","subject":"[PATCH v2] Use OPT_SET_INT_F() for cmdline option specification","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-05-20T15:42:58Z","receivedAt":"2018-05-20T15:43:22Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"The only thing these commands need is extra parseopt flag which can be\npassed in by OPT_SET_INT_F() and it is a bit more compact than full\nstruct initialization.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n Changes from v1\n\n    diff --git a/builtin/am.c b/builtin/am.c\n    index 666287b497..a1ff235fbc 100644\n    --- a/builtin/am.c\n    +++ b/builtin/am.c\n    @@ -2235,7 +2235,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)\n     \t\t\tN_(\"pass --keep-cr flag to git-mailsplit for mbox format\"),\n     \t\t\t1, PARSE_OPT_NONEG),\n     \t\tOPT_SET_INT_F(0, \"no-keep-cr\", &keep_cr,\n    -\t\t\tN_(\"do not pass --keep-cr flag to git-mailsplit for mbox format\"),\n    +\t\t\tN_(\"do not pass --keep-cr flag to git-mailsplit independent of am.keepcr\"),\n     \t\t\t0, PARSE_OPT_NONEG),\n     \t\tOPT_BOOL('c', \"scissors\", &state.scissors,\n     \t\t\tN_(\"strip everything before a scissors line\")),\n\n archive.c              |  6 ++----\n builtin/am.c           | 12 ++++++------\n builtin/branch.c       |  4 ++--\n builtin/difftool.c     |  9 ++++-----\n builtin/fetch.c        |  6 +++---\n builtin/grep.c         |  6 +++---\n builtin/log.c          |  6 +++---\n builtin/ls-files.c     |  6 +++---\n builtin/merge.c        |  6 +++---\n builtin/notes.c        | 12 ++++++------\n builtin/pack-objects.c | 24 ++++++++++++------------\n 11 files changed, 47 insertions(+), 50 deletions(-)\n\ndiff --git a/archive.c b/archive.c\nindex 93ab175b0b..4fe7bec60c 100644\n--- a/archive.c\n+++ b/archive.c\n@@ -411,11 +411,9 @@ static void parse_treeish_arg(const char **argv,\n }\n \n #define OPT__COMPR(s, v, h, p) \\\n-\t{ OPTION_SET_INT, (s), NULL, (v), NULL, (h), \\\n-\t  PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, (p) }\n+\tOPT_SET_INT_F(s, NULL, v, h, p, PARSE_OPT_NONEG)\n #define OPT__COMPR_HIDDEN(s, v, p) \\\n-\t{ OPTION_SET_INT, (s), NULL, (v), NULL, \"\", \\\n-\t  PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_HIDDEN, NULL, (p) }\n+\tOPT_SET_INT_F(s, NULL, v, \"\", p, PARSE_OPT_NONEG | PARSE_OPT_HIDDEN)\n \n static int parse_archive_args(int argc, const char **argv,\n \t\tconst struct archiver **ar, struct archiver_args *args,\ndiff --git a/builtin/am.c b/builtin/am.c\nindex d834f9e62b..a1ff235fbc 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -2231,12 +2231,12 @@ int cmd_am(int argc, const char **argv, const char *prefix)\n \t\t\tN_(\"pass -b flag to git-mailinfo\"), KEEP_NON_PATCH),\n \t\tOPT_BOOL('m', \"message-id\", &state.message_id,\n \t\t\tN_(\"pass -m flag to git-mailinfo\")),\n-\t\t{ OPTION_SET_INT, 0, \"keep-cr\", &keep_cr, NULL,\n-\t\t  N_(\"pass --keep-cr flag to git-mailsplit for mbox format\"),\n-\t\t  PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1},\n-\t\t{ OPTION_SET_INT, 0, \"no-keep-cr\", &keep_cr, NULL,\n-\t\t  N_(\"do not pass --keep-cr flag to git-mailsplit independent of am.keepcr\"),\n-\t\t  PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 0},\n+\t\tOPT_SET_INT_F(0, \"keep-cr\", &keep_cr,\n+\t\t\tN_(\"pass --keep-cr flag to git-mailsplit for mbox format\"),\n+\t\t\t1, PARSE_OPT_NONEG),\n+\t\tOPT_SET_INT_F(0, \"no-keep-cr\", &keep_cr,\n+\t\t\tN_(\"do not pass --keep-cr flag to git-mailsplit independent of am.keepcr\"),\n+\t\t\t0, PARSE_OPT_NONEG),\n \t\tOPT_BOOL('c', \"scissors\", &state.scissors,\n \t\t\tN_(\"strip everything before a scissors line\")),\n \t\tOPT_PASSTHRU_ARGV(0, \"whitespace\", &state.git_apply_opts, N_(\"action\"),\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex efc9ac1922..cc089f9efb 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -592,8 +592,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\tOPT__QUIET(&quiet, N_(\"suppress informational messages\")),\n \t\tOPT_SET_INT('t', \"track\",  &track, N_(\"set up tracking mode (see git-pull(1))\"),\n \t\t\tBRANCH_TRACK_EXPLICIT),\n-\t\t{ OPTION_SET_INT, 0, \"set-upstream\", &track, NULL, N_(\"do not use\"),\n-\t\t\tPARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, BRANCH_TRACK_OVERRIDE },\n+\t\tOPT_SET_INT_F(0, \"set-upstream\", &track, N_(\"do not use\"),\n+\t\t\tBRANCH_TRACK_OVERRIDE, PARSE_OPT_HIDDEN),\n \t\tOPT_STRING('u', \"set-upstream-to\", &new_upstream, N_(\"upstream\"), N_(\"change the upstream info\")),\n \t\tOPT_BOOL(0, \"unset-upstream\", &unset_upstream, N_(\"Unset the upstream info\")),\n \t\tOPT__COLOR(&branch_use_color, N_(\"use colored output\")),\ndiff --git a/builtin/difftool.c b/builtin/difftool.c\nindex aad0e073ee..c439b64207 100644\n--- a/builtin/difftool.c\n+++ b/builtin/difftool.c\n@@ -695,12 +695,11 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)\n \t\t\t N_(\"use `diff.guitool` instead of `diff.tool`\")),\n \t\tOPT_BOOL('d', \"dir-diff\", &dir_diff,\n \t\t\t N_(\"perform a full-directory diff\")),\n-\t\t{ OPTION_SET_INT, 'y', \"no-prompt\", &prompt, NULL,\n+\t\tOPT_SET_INT_F('y', \"no-prompt\", &prompt,\n \t\t\tN_(\"do not prompt before launching a diff tool\"),\n-\t\t\tPARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 0},\n-\t\t{ OPTION_SET_INT, 0, \"prompt\", &prompt, NULL, NULL,\n-\t\t\tPARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_HIDDEN,\n-\t\t\tNULL, 1 },\n+\t\t\t0, PARSE_OPT_NONEG),\n+\t\tOPT_SET_INT_F(0, \"prompt\", &prompt, NULL,\n+\t\t\t1, PARSE_OPT_NONEG | PARSE_OPT_HIDDEN),\n \t\tOPT_BOOL(0, \"symlinks\", &symlinks,\n \t\t\t N_(\"use symlinks in dir-diff mode\")),\n \t\tOPT_STRING('t', \"tool\", &difftool_cmd, N_(\"<tool>\"),\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 7ee83ac0f8..b6530a5ce0 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -156,9 +156,9 @@ static struct option builtin_fetch_options[] = {\n \t\t\tN_(\"deepen history of shallow clone, excluding rev\")),\n \tOPT_INTEGER(0, \"deepen\", &deepen_relative,\n \t\t    N_(\"deepen history of shallow clone\")),\n-\t{ OPTION_SET_INT, 0, \"unshallow\", &unshallow, NULL,\n-\t\t   N_(\"convert to a complete repository\"),\n-\t\t   PARSE_OPT_NONEG | PARSE_OPT_NOARG, NULL, 1 },\n+\tOPT_SET_INT_F(0, \"unshallow\", &unshallow,\n+\t\t      N_(\"convert to a complete repository\"),\n+\t\t      1, PARSE_OPT_NONEG),\n \t{ OPTION_STRING, 0, \"submodule-prefix\", &submodule_prefix, N_(\"dir\"),\n \t\t   N_(\"prepend this to submodule path output\"), PARSE_OPT_HIDDEN },\n \t{ OPTION_CALLBACK, 0, \"recurse-submodules-default\",\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 6e7bc76785..850bcffd99 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -885,9 +885,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\t\t   N_(\"indicate hit with exit status without output\")),\n \t\tOPT_BOOL(0, \"all-match\", &opt.all_match,\n \t\t\tN_(\"show only matches from files that match all patterns\")),\n-\t\t{ OPTION_SET_INT, 0, \"debug\", &opt.debug, NULL,\n-\t\t  N_(\"show parse tree for grep expression\"),\n-\t\t  PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1 },\n+\t\tOPT_SET_INT_F(0, \"debug\", &opt.debug,\n+\t\t\t      N_(\"show parse tree for grep expression\"),\n+\t\t\t      1, PARSE_OPT_HIDDEN),\n \t\tOPT_GROUP(\"\"),\n \t\t{ OPTION_STRING, 'O', \"open-files-in-pager\", &show_in_pager,\n \t\t\tN_(\"pager\"), N_(\"show matching files in the pager\"),\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 71f68a3e4f..8f27921505 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1474,9 +1474,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\t\t N_(\"output all-zero hash in From header\")),\n \t\tOPT_BOOL(0, \"ignore-if-in-upstream\", &ignore_if_in_upstream,\n \t\t\t N_(\"don't include a patch matching a commit upstream\")),\n-\t\t{ OPTION_SET_INT, 'p', \"no-stat\", &use_patch_format, NULL,\n-\t\t  N_(\"show patch format instead of default (patch + stat)\"),\n-\t\t  PARSE_OPT_NONEG | PARSE_OPT_NOARG, NULL, 1},\n+\t\tOPT_SET_INT_F('p', \"no-stat\", &use_patch_format,\n+\t\t\t      N_(\"show patch format instead of default (patch + stat)\"),\n+\t\t\t      1, PARSE_OPT_NONEG),\n \t\tOPT_GROUP(N_(\"Messaging\")),\n \t\t{ OPTION_CALLBACK, 0, \"add-header\", NULL, N_(\"header\"),\n \t\t\t    N_(\"add email header\"), 0, header_callback },\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex a71f6bd088..40d9138c46 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -556,9 +556,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)\n \t\t{ OPTION_CALLBACK, 0, \"exclude-standard\", &dir, NULL,\n \t\t\tN_(\"add the standard git exclusions\"),\n \t\t\tPARSE_OPT_NOARG, option_parse_exclude_standard },\n-\t\t{ OPTION_SET_INT, 0, \"full-name\", &prefix_len, NULL,\n-\t\t\tN_(\"make the output relative to the project top directory\"),\n-\t\t\tPARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL },\n+\t\tOPT_SET_INT_F(0, \"full-name\", &prefix_len,\n+\t\t\t      N_(\"make the output relative to the project top directory\"),\n+\t\t\t      0, PARSE_OPT_NONEG),\n \t\tOPT_BOOL(0, \"recurse-submodules\", &recurse_submodules,\n \t\t\tN_(\"recurse through submodules\")),\n \t\tOPT_BOOL(0, \"error-unmatch\", &error_unmatch,\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 9db5a2cf16..4be71dd81b 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -213,9 +213,9 @@ static struct option builtin_merge_options[] = {\n \tOPT_BOOL('e', \"edit\", &option_edit,\n \t\tN_(\"edit message before committing\")),\n \tOPT_SET_INT(0, \"ff\", &fast_forward, N_(\"allow fast-forward (default)\"), FF_ALLOW),\n-\t{ OPTION_SET_INT, 0, \"ff-only\", &fast_forward, NULL,\n-\t\tN_(\"abort if fast-forward is not possible\"),\n-\t\tPARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, FF_ONLY },\n+\tOPT_SET_INT_F(0, \"ff-only\", &fast_forward,\n+\t\t      N_(\"abort if fast-forward is not possible\"),\n+\t\t      FF_ONLY, PARSE_OPT_NONEG),\n \tOPT_RERERE_AUTOUPDATE(&allow_rerere_auto),\n \tOPT_BOOL(0, \"verify-signatures\", &verify_signatures,\n \t\tN_(\"verify that the named commit has a valid GPG signature\")),\ndiff --git a/builtin/notes.c b/builtin/notes.c\nindex e5bf80eef1..4d34994c34 100644\n--- a/builtin/notes.c\n+++ b/builtin/notes.c\n@@ -778,13 +778,13 @@ static int merge(int argc, const char **argv, const char *prefix)\n \t\t\t   N_(\"resolve notes conflicts using the given strategy \"\n \t\t\t      \"(manual/ours/theirs/union/cat_sort_uniq)\")),\n \t\tOPT_GROUP(N_(\"Committing unmerged notes\")),\n-\t\t{ OPTION_SET_INT, 0, \"commit\", &do_commit, NULL,\n-\t\t\tN_(\"finalize notes merge by committing unmerged notes\"),\n-\t\t\tPARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1},\n+\t\tOPT_SET_INT_F(0, \"commit\", &do_commit,\n+\t\t\t      N_(\"finalize notes merge by committing unmerged notes\"),\n+\t\t\t      1, PARSE_OPT_NONEG),\n \t\tOPT_GROUP(N_(\"Aborting notes merge resolution\")),\n-\t\t{ OPTION_SET_INT, 0, \"abort\", &do_abort, NULL,\n-\t\t\tN_(\"abort notes merge\"),\n-\t\t\tPARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1},\n+\t\tOPT_SET_INT_F(0, \"abort\", &do_abort,\n+\t\t\t      N_(\"abort notes merge\"),\n+\t\t\t      1, PARSE_OPT_NONEG),\n \t\tOPT_END()\n \t};\n \ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex 24b1c6c5dd..5134c655c7 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -2992,18 +2992,18 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)\n \t\t\t N_(\"do not create an empty pack output\")),\n \t\tOPT_BOOL(0, \"revs\", &use_internal_rev_list,\n \t\t\t N_(\"read revision arguments from standard input\")),\n-\t\t{ OPTION_SET_INT, 0, \"unpacked\", &rev_list_unpacked, NULL,\n-\t\t  N_(\"limit the objects to those that are not yet packed\"),\n-\t\t  PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1 },\n-\t\t{ OPTION_SET_INT, 0, \"all\", &rev_list_all, NULL,\n-\t\t  N_(\"include objects reachable from any reference\"),\n-\t\t  PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1 },\n-\t\t{ OPTION_SET_INT, 0, \"reflog\", &rev_list_reflog, NULL,\n-\t\t  N_(\"include objects referred by reflog entries\"),\n-\t\t  PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1 },\n-\t\t{ OPTION_SET_INT, 0, \"indexed-objects\", &rev_list_index, NULL,\n-\t\t  N_(\"include objects referred to by the index\"),\n-\t\t  PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1 },\n+\t\tOPT_SET_INT_F(0, \"unpacked\", &rev_list_unpacked,\n+\t\t\t      N_(\"limit the objects to those that are not yet packed\"),\n+\t\t\t      1, PARSE_OPT_NONEG),\n+\t\tOPT_SET_INT_F(0, \"all\", &rev_list_all,\n+\t\t\t      N_(\"include objects reachable from any reference\"),\n+\t\t\t      1, PARSE_OPT_NONEG),\n+\t\tOPT_SET_INT_F(0, \"reflog\", &rev_list_reflog,\n+\t\t\t      N_(\"include objects referred by reflog entries\"),\n+\t\t\t      1, PARSE_OPT_NONEG),\n+\t\tOPT_SET_INT_F(0, \"indexed-objects\", &rev_list_index,\n+\t\t\t      N_(\"include objects referred to by the index\"),\n+\t\t\t      1, PARSE_OPT_NONEG),\n \t\tOPT_BOOL(0, \"stdout\", &pack_to_stdout,\n \t\t\t N_(\"output pack to stdout\")),\n \t\tOPT_BOOL(0, \"include-tag\", &include_tag,\n-- \n2.17.0.705.g3525833791\n\n"}]}