{"thread":{"id":"50247","subject":"[PATCH 00/76] Convert diff opt parser to parse_options()","startedAt":"2019-01-17T13:06:35Z","lastAt":"2019-01-21T12:14:26Z","messageCount":88,"participants":["Nguyễn Thái Ngọc Duy","Ævar Arnfjörð Bjarmason","Stefan Beller","Johannes Schindelin","Duy Nguyen","SZEDER Gábor"],"isPatch":true,"patchVersion":1,"patchTotal":76},"messages":[{"id":"366911","messageId":"20190117130615.18732-1-pclouds@gmail.com","threadId":"50247","inReplyTo":null,"subject":"[PATCH 00/76] Convert diff opt parser to parse_options()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:04:59Z","receivedAt":"2019-01-17T13:06:35Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This series converts diff option parsing to using parse-options. There\nare a couple benefits of using parse-options, including \"git <cmd> -h\"\noutput, completion and less duplicate work.\n\nThis is the first half. The second one would be converting the option\nparser in revision.c.  After that, the end game is, any command can\ntake a 'struct option[]' somewhere from diff/rev code, remove the\noptions they are not interested, then merge with their own options and\ndo parse_options() just once. There will be no separate parse phase\nfor revision/diff anymore.\n\nI sent a sneak peek [1] last year and got two good comments. I take it\npeople at least did not oppose to this. The most interesting parts are\nat the top and bottom. The middle is just boring conversion, usually\none option per patch.\n\nThis will conflict with pw/diff-color-moved-ws-fix on 'pu' because\nthat series adds --no-color-moved-ws option. I redid the same thing in\n73/76 so that conflict resolution could be simply taking this side of\nchange.\n\nThis series is also available for fetching here\n\nhttps://gitlab.com/pclouds/git/commits/diff-opt-parse-options\n\n[1] http://public-inbox.org/git/20181227162536.15895-1-pclouds@gmail.com/\n\nNguyễn Thái Ngọc Duy (76):\n  parse-options.h: remove extern on function prototypes\n  parse-options: add one-shot mode\n  parse-options: allow keep-unknown + stop-at-non-opt combination\n  parse-options: disable option abbreviation with PARSE_OPT_KEEP_UNKNOWN\n  parse-options: add OPT_BITOP()\n  parse-options: stop abusing 'callback' for lowlevel callbacks\n  parse-options: avoid magic return codes\n  parse-options: allow ll_callback with OPTION_CALLBACK\n  diff.h: keep forward struct declarations sorted\n  diff.h: avoid bit fields in struct diff_flags\n  diff.c: prepare to use parse_options() for parsing\n  diff.c: convert -u|-p|--patch\n  diff.c: convert -U|--unified\n  diff.c: convert -W|--[no-]function-context\n  diff.c: convert --raw\n  diff.c: convert --patch-with-raw\n  diff.c: convert --numstat and --shortstat\n  diff.c: convert --dirstat and friends\n  diff.c: convert --check\n  diff.c: convert --summary\n  diff.c: convert --patch-with-stat\n  diff.c: convert --name-only\n  diff.c: convert --name-status\n  diff.c: convert -s|--no-patch\n  diff.c: convert --stat*\n  diff.c: convert --[no-]compact-summary\n  diff.c: convert --output-*\n  diff.c: convert -B|--break-rewrites\n  diff.c: convert -M|--find-renames\n  diff.c: convert -D|--irreversible-delete\n  diff.c: convert -C|--find-copies\n  diff.c: convert --find-copies-harder\n  diff.c: convert --no-renames|--[no--rename-empty\n  diff.c: convert --relative\n  diff.c: convert --[no-]minimal\n  diff.c: convert --ignore-some-changes\n  diff.c: convert --[no-]indent-heuristic\n  diff.c: convert --patience\n  diff.c: convert --histogram\n  diff.c: convert --diff-algorithm\n  diff.c: convert --anchored\n  diff.c: convert --binary\n  diff.c: convert --full-index\n  diff.c: convert -a|--text\n  diff.c: convert -R\n  diff.c: convert --[no-]follow\n  diff.c: convert --[no-]color\n  diff.c: convert --word-diff\n  diff.c: convert --word-diff-regex\n  diff.c: convert --color-words\n  diff.c: convert --exit-code\n  diff.c: convert --quiet\n  diff.c: convert --ext-diff\n  diff.c: convert --textconv\n  diff.c: convert --ignore-submodules\n  diff.c: convert --submodule\n  diff.c: convert --ws-error-highlight\n  diff.c: convert --ita-[in]visible-in-index\n  diff.c: convert -z\n  diff.c: convert -l\n  diff.c: convert -S|-G\n  diff.c: convert --pickaxe-all|--pickaxe-regex\n  diff.c: convert -O\n  diff.c: convert --find-object\n  diff.c: convert --diff-filter\n  diff.c: convert --[no-]abbrev\n  diff.c: convert --[src|dst]-prefix\n  diff.c: convert --line-prefix\n  diff.c: convert --no-prefix\n  diff.c: convert --inter-hunk-context\n  diff.c: convert --color-moved\n  diff.c: convert --color-moved-ws\n  diff.c: allow --no-color-moved-ws\n  range-diff: use parse_options() instead of diff_opt_parse()\n  diff --no-index: use parse_options() instead of diff_opt_parse()\n  am: avoid diff_opt_parse()\n\n Documentation/diff-options.txt |   24 +-\n builtin/am.c                   |    4 +-\n builtin/blame.c                |    2 +-\n builtin/diff.c                 |   21 +-\n builtin/merge.c                |    9 +-\n builtin/range-diff.c           |   26 +-\n builtin/update-index.c         |   41 +-\n diff-no-index.c                |   49 +-\n diff.c                         | 1136 ++++++++++++++++++++------------\n diff.h                         |   85 +--\n parse-options-cb.c             |   11 +-\n parse-options.c                |  152 +++--\n parse-options.h                |  114 ++--\n t/t4053-diff-no-index.sh       |    3 +-\n t/t7800-difftool.sh            |    4 +-\n 15 files changed, 1054 insertions(+), 627 deletions(-)\n\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366912","messageId":"20190117130615.18732-2-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 01/76] parse-options.h: remove extern on function prototypes","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:00Z","receivedAt":"2019-01-17T13:06:40Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n parse-options.h | 58 ++++++++++++++++++++++++-------------------------\n 1 file changed, 29 insertions(+), 29 deletions(-)\n\ndiff --git a/parse-options.h b/parse-options.h\nindex 14fe32428e..f5e7ec7d23 100644\n--- a/parse-options.h\n+++ b/parse-options.h\n@@ -174,18 +174,18 @@ struct option {\n  * for translation with N_().\n  * Returns the number of arguments left in argv[].\n  */\n-extern int parse_options(int argc, const char **argv, const char *prefix,\n-\t\t\t const struct option *options,\n-\t\t\t const char * const usagestr[], int flags);\n+int parse_options(int argc, const char **argv, const char *prefix,\n+\t\t  const struct option *options,\n+\t\t  const char * const usagestr[], int flags);\n \n-extern NORETURN void usage_with_options(const char * const *usagestr,\n-\t\t\t\t\tconst struct option *options);\n+NORETURN void usage_with_options(const char * const *usagestr,\n+\t\t\t\t const struct option *options);\n \n-extern NORETURN void usage_msg_opt(const char *msg,\n-\t\t\t\t   const char * const *usagestr,\n-\t\t\t\t   const struct option *options);\n+NORETURN void usage_msg_opt(const char *msg,\n+\t\t\t    const char * const *usagestr,\n+\t\t\t    const struct option *options);\n \n-extern int optbug(const struct option *opt, const char *reason);\n+int optbug(const struct option *opt, const char *reason);\n const char *optname(const struct option *opt, int flags);\n \n /*\n@@ -227,31 +227,31 @@ struct parse_opt_ctx_t {\n \tconst char *prefix;\n };\n \n-extern void parse_options_start(struct parse_opt_ctx_t *ctx,\n-\t\t\t\tint argc, const char **argv, const char *prefix,\n-\t\t\t\tconst struct option *options, int flags);\n+void parse_options_start(struct parse_opt_ctx_t *ctx,\n+\t\t\t int argc, const char **argv, const char *prefix,\n+\t\t\t const struct option *options, int flags);\n \n-extern int parse_options_step(struct parse_opt_ctx_t *ctx,\n-\t\t\t      const struct option *options,\n-\t\t\t      const char * const usagestr[]);\n+int parse_options_step(struct parse_opt_ctx_t *ctx,\n+\t\t       const struct option *options,\n+\t\t       const char * const usagestr[]);\n \n-extern int parse_options_end(struct parse_opt_ctx_t *ctx);\n+int parse_options_end(struct parse_opt_ctx_t *ctx);\n \n-extern struct option *parse_options_concat(struct option *a, struct option *b);\n+struct option *parse_options_concat(struct option *a, struct option *b);\n \n /*----- some often used options -----*/\n-extern int parse_opt_abbrev_cb(const struct option *, const char *, int);\n-extern int parse_opt_expiry_date_cb(const struct option *, const char *, int);\n-extern int parse_opt_color_flag_cb(const struct option *, const char *, int);\n-extern int parse_opt_verbosity_cb(const struct option *, const char *, int);\n-extern int parse_opt_object_name(const struct option *, const char *, int);\n-extern int parse_opt_commits(const struct option *, const char *, int);\n-extern int parse_opt_tertiary(const struct option *, const char *, int);\n-extern int parse_opt_string_list(const struct option *, const char *, int);\n-extern int parse_opt_noop_cb(const struct option *, const char *, int);\n-extern int parse_opt_unknown_cb(const struct option *, const char *, int);\n-extern int parse_opt_passthru(const struct option *, const char *, int);\n-extern int parse_opt_passthru_argv(const struct option *, const char *, int);\n+int parse_opt_abbrev_cb(const struct option *, const char *, int);\n+int parse_opt_expiry_date_cb(const struct option *, const char *, int);\n+int parse_opt_color_flag_cb(const struct option *, const char *, int);\n+int parse_opt_verbosity_cb(const struct option *, const char *, int);\n+int parse_opt_object_name(const struct option *, const char *, int);\n+int parse_opt_commits(const struct option *, const char *, int);\n+int parse_opt_tertiary(const struct option *, const char *, int);\n+int parse_opt_string_list(const struct option *, const char *, int);\n+int parse_opt_noop_cb(const struct option *, const char *, int);\n+int parse_opt_unknown_cb(const struct option *, const char *, int);\n+int parse_opt_passthru(const struct option *, const char *, int);\n+int parse_opt_passthru_argv(const struct option *, const char *, int);\n \n #define OPT__VERBOSE(var, h)  OPT_COUNTUP('v', \"verbose\", (var), (h))\n #define OPT__QUIET(var, h)    OPT_COUNTUP('q', \"quiet\",   (var), (h))\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366913","messageId":"20190117130615.18732-3-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 02/76] parse-options: add one-shot mode","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:01Z","receivedAt":"2019-01-17T13:06:45Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This is to help reimplement diff_opt_parse() using parse_options().\nThe behavior of parse_options() is changed to be the same as the\nother:\n\n- no argv0 in argv[], everything can be processed\n- argv[] must not be updated, it's the caller's job to do that\n- return the number of arguments processed\n- leave all unknown options / non-options alone (this one can already\n  be achieved with PARSE_OPT_KEEP_UNKNOWN and\n  PARSE_OPT_STOP_AT_NON_OPTION)\n\nThis mode is NOT supposed to stay here for long. It's to help\nconverting diff/rev option parsing. Once that work is over and we can\njust use parse_options() throughout the code base, this will be\ndeleted.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n parse-options.c | 23 ++++++++++++++++++++---\n parse-options.h | 17 +++++++++++++----\n 2 files changed, 33 insertions(+), 7 deletions(-)\n\ndiff --git a/parse-options.c b/parse-options.c\nindex 9f84bacce6..eb5de0da29 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -416,15 +416,23 @@ void parse_options_start(struct parse_opt_ctx_t *ctx,\n \t\t\t const struct option *options, int flags)\n {\n \tmemset(ctx, 0, sizeof(*ctx));\n-\tctx->argc = ctx->total = argc - 1;\n-\tctx->argv = argv + 1;\n-\tctx->out  = argv;\n+\tctx->argc = argc;\n+\tctx->argv = argv;\n+\tif (!(flags & PARSE_OPT_ONE_SHOT)) {\n+\t\tctx->argc--;\n+\t\tctx->argv++;\n+\t}\n+\tctx->total = ctx->argc;\n+\tctx->out   = argv;\n \tctx->prefix = prefix;\n \tctx->cpidx = ((flags & PARSE_OPT_KEEP_ARGV0) != 0);\n \tctx->flags = flags;\n \tif ((flags & PARSE_OPT_KEEP_UNKNOWN) &&\n \t    (flags & PARSE_OPT_STOP_AT_NON_OPTION))\n \t\tBUG(\"STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together\");\n+\tif ((flags & PARSE_OPT_ONE_SHOT) &&\n+\t    (flags & PARSE_OPT_KEEP_ARGV0))\n+\t\tBUG(\"Can't keep argv0 if you don't have it\");\n \tparse_options_check(options);\n }\n \n@@ -536,6 +544,10 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,\n \tfor (; ctx->argc; ctx->argc--, ctx->argv++) {\n \t\tconst char *arg = ctx->argv[0];\n \n+\t\tif (ctx->flags & PARSE_OPT_ONE_SHOT &&\n+\t\t    ctx->argc != ctx->total)\n+\t\t\tbreak;\n+\n \t\tif (*arg != '-' || !arg[1]) {\n \t\t\tif (parse_nodash_opt(ctx, arg, options) == 0)\n \t\t\t\tcontinue;\n@@ -610,6 +622,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,\n \t\t}\n \t\tcontinue;\n unknown:\n+\t\tif (ctx->flags & PARSE_OPT_ONE_SHOT)\n+\t\t\tbreak;\n \t\tif (!(ctx->flags & PARSE_OPT_KEEP_UNKNOWN))\n \t\t\treturn PARSE_OPT_UNKNOWN;\n \t\tctx->out[ctx->cpidx++] = ctx->argv[0];\n@@ -623,6 +637,9 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,\n \n int parse_options_end(struct parse_opt_ctx_t *ctx)\n {\n+\tif (ctx->flags & PARSE_OPT_ONE_SHOT)\n+\t\treturn ctx->total - ctx->argc;\n+\n \tMOVE_ARRAY(ctx->out + ctx->cpidx, ctx->argv, ctx->argc);\n \tctx->out[ctx->cpidx + ctx->argc] = NULL;\n \treturn ctx->cpidx + ctx->argc;\ndiff --git a/parse-options.h b/parse-options.h\nindex f5e7ec7d23..d663b83973 100644\n--- a/parse-options.h\n+++ b/parse-options.h\n@@ -27,7 +27,8 @@ enum parse_opt_flags {\n \tPARSE_OPT_STOP_AT_NON_OPTION = 2,\n \tPARSE_OPT_KEEP_ARGV0 = 4,\n \tPARSE_OPT_KEEP_UNKNOWN = 8,\n-\tPARSE_OPT_NO_INTERNAL_HELP = 16\n+\tPARSE_OPT_NO_INTERNAL_HELP = 16,\n+\tPARSE_OPT_ONE_SHOT = 32\n };\n \n enum parse_opt_option_flags {\n@@ -169,10 +170,18 @@ struct option {\n \t  N_(\"no-op (backward compatibility)\"),\t\t\\\n \t  PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, parse_opt_noop_cb }\n \n-/* parse_options() will filter out the processed options and leave the\n- * non-option arguments in argv[]. usagestr strings should be marked\n- * for translation with N_().\n+/*\n+ * parse_options() will filter out the processed options and leave the\n+ * non-option arguments in argv[]. argv0 is assumed program name and\n+ * skipped.\n+ *\n+ * usagestr strings should be marked for translation with N_().\n+ *\n  * Returns the number of arguments left in argv[].\n+ *\n+ * In one-shot mode, argv0 is not a program name, argv[] is left\n+ * untouched and parse_options() returns the number of options\n+ * processed.\n  */\n int parse_options(int argc, const char **argv, const char *prefix,\n \t\t  const struct option *options,\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366914","messageId":"20190117130615.18732-4-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 03/76] parse-options: allow keep-unknown + stop-at-non-opt combination","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:02Z","receivedAt":"2019-01-17T13:06:50Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"These two are orthogonal. One is about unknown _option_ while the\nother non-option.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n parse-options.c | 3 ---\n 1 file changed, 3 deletions(-)\n\ndiff --git a/parse-options.c b/parse-options.c\nindex eb5de0da29..678b263897 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -427,9 +427,6 @@ void parse_options_start(struct parse_opt_ctx_t *ctx,\n \tctx->prefix = prefix;\n \tctx->cpidx = ((flags & PARSE_OPT_KEEP_ARGV0) != 0);\n \tctx->flags = flags;\n-\tif ((flags & PARSE_OPT_KEEP_UNKNOWN) &&\n-\t    (flags & PARSE_OPT_STOP_AT_NON_OPTION))\n-\t\tBUG(\"STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together\");\n \tif ((flags & PARSE_OPT_ONE_SHOT) &&\n \t    (flags & PARSE_OPT_KEEP_ARGV0))\n \t\tBUG(\"Can't keep argv0 if you don't have it\");\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366915","messageId":"20190117130615.18732-5-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 04/76] parse-options: disable option abbreviation with PARSE_OPT_KEEP_UNKNOWN","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:03Z","receivedAt":"2019-01-17T13:06:54Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"parse-options can unambiguously find an abbreviation only if it sees\nall available options. This is usually the case when you use\nparse_options(). But there are other callers like blame or shortlog\nwhich uses parse_options_start() in combination with a custom option\nparser, like rev-list. parse-options cannot see all options in this\ncase and will get abbrev detection wrong. Disable it.\n\nt7800 needs update because --symlink no longer expands to --symlinks\nand will be passed down to git-diff, which will not recognize it. I\nstill think this is the correct thing to do. But if --symlink has been\nactually used in the wild, we would just add an option alias for it.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n parse-options.c     | 3 ++-\n t/t7800-difftool.sh | 4 ++--\n 2 files changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/parse-options.c b/parse-options.c\nindex 678b263897..9710ec9d5e 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -266,7 +266,8 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,\n \t\t}\n \t\tif (!rest) {\n \t\t\t/* abbreviated? */\n-\t\t\tif (!strncmp(long_name, arg, arg_end - arg)) {\n+\t\t\tif (!(p->flags & PARSE_OPT_KEEP_UNKNOWN) &&\n+\t\t\t    !strncmp(long_name, arg, arg_end - arg)) {\n is_abbreviated:\n \t\t\t\tif (abbrev_option) {\n \t\t\t\t\t/*\ndiff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh\nindex 22b9199d59..bb9a7f4ff9 100755\n--- a/t/t7800-difftool.sh\n+++ b/t/t7800-difftool.sh\n@@ -546,7 +546,7 @@ do\n done >actual\n EOF\n \n-test_expect_success SYMLINKS 'difftool --dir-diff --symlink without unstaged changes' '\n+test_expect_success SYMLINKS 'difftool --dir-diff --symlinks without unstaged changes' '\n \tcat >expect <<-EOF &&\n \tfile\n \t$PWD/file\n@@ -555,7 +555,7 @@ test_expect_success SYMLINKS 'difftool --dir-diff --symlink without unstaged cha\n \tsub/sub\n \t$PWD/sub/sub\n \tEOF\n-\tgit difftool --dir-diff --symlink \\\n+\tgit difftool --dir-diff --symlinks \\\n \t\t--extcmd \"./.git/CHECK_SYMLINKS\" branch HEAD &&\n \ttest_cmp expect actual\n '\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366916","messageId":"20190117130615.18732-6-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 05/76] parse-options: add OPT_BITOP()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:04Z","receivedAt":"2019-01-17T13:06:59Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This is needed for diff_opt_parse() where we do\n\n   value = (value & ~mask) | some_more;\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n parse-options.c | 7 +++++++\n parse-options.h | 5 +++++\n 2 files changed, 12 insertions(+)\n\ndiff --git a/parse-options.c b/parse-options.c\nindex 9710ec9d5e..1244968855 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -109,6 +109,13 @@ static int get_value(struct parse_opt_ctx_t *p,\n \t\t\t*(int *)opt->value &= ~opt->defval;\n \t\treturn 0;\n \n+\tcase OPTION_BITOP:\n+\t\tif (unset)\n+\t\t\tBUG(\"BITOP can't have unset form\");\n+\t\t*(int *)opt->value &= ~opt->extra;\n+\t\t*(int *)opt->value |= opt->defval;\n+\t\treturn 0;\n+\n \tcase OPTION_COUNTUP:\n \t\tif (*(int *)opt->value < 0)\n \t\t\t*(int *)opt->value = 0;\ndiff --git a/parse-options.h b/parse-options.h\nindex d663b83973..c97324f576 100644\n--- a/parse-options.h\n+++ b/parse-options.h\n@@ -10,6 +10,7 @@ enum parse_opt_type {\n \t/* options with no arguments */\n \tOPTION_BIT,\n \tOPTION_NEGBIT,\n+\tOPTION_BITOP,\n \tOPTION_COUNTUP,\n \tOPTION_SET_INT,\n \tOPTION_CMDMODE,\n@@ -118,6 +119,7 @@ struct option {\n \tint flags;\n \tparse_opt_cb *callback;\n \tintptr_t defval;\n+\tintptr_t extra;\n };\n \n #define OPT_BIT_F(s, l, v, h, b, f) { OPTION_BIT, (s), (l), (v), NULL, (h), \\\n@@ -133,6 +135,9 @@ struct option {\n \t\t\t\t      (h), PARSE_OPT_NOARG}\n #define OPT_GROUP(h)                { OPTION_GROUP, 0, NULL, NULL, NULL, (h) }\n #define OPT_BIT(s, l, v, h, b)      OPT_BIT_F(s, l, v, h, b, 0)\n+#define OPT_BITOP(s, l, v, h, set, clear) { OPTION_BITOP, (s), (l), (v), NULL, (h), \\\n+\t\t\t\t\t    PARSE_OPT_NOARG|PARSE_OPT_NONEG, NULL, \\\n+\t\t\t\t\t    (set), (clear) }\n #define OPT_NEGBIT(s, l, v, h, b)   { OPTION_NEGBIT, (s), (l), (v), NULL, \\\n \t\t\t\t      (h), PARSE_OPT_NOARG, NULL, (b) }\n #define OPT_COUNTUP(s, l, v, h)     OPT_COUNTUP_F(s, l, v, h, 0)\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366917","messageId":"20190117130615.18732-7-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 06/76] parse-options: stop abusing 'callback' for lowlevel callbacks","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:05Z","receivedAt":"2019-01-17T13:07:05Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Lowlevel callbacks have different function signatures. Add a new field\nin 'struct option' with the right type for lowlevel callbacks.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/blame.c        |  2 +-\n builtin/merge.c        |  2 +-\n builtin/update-index.c | 11 ++++++-----\n parse-options-cb.c     |  3 ++-\n parse-options.c        | 15 ++++++++++++++-\n parse-options.h        | 12 ++++++++----\n 6 files changed, 32 insertions(+), 13 deletions(-)\n\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 6d798f9939..8dcc55dffa 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -814,7 +814,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)\n \t\t * and are only included here to get included in the \"-h\"\n \t\t * output:\n \t\t */\n-\t\t{ OPTION_LOWLEVEL_CALLBACK, 0, \"indent-heuristic\", NULL, NULL, N_(\"Use an experimental heuristic to improve diffs\"), PARSE_OPT_NOARG, parse_opt_unknown_cb },\n+\t\t{ OPTION_LOWLEVEL_CALLBACK, 0, \"indent-heuristic\", NULL, NULL, N_(\"Use an experimental heuristic to improve diffs\"), PARSE_OPT_NOARG, NULL, 0, parse_opt_unknown_cb },\n \n \t\tOPT_BIT(0, \"minimal\", &xdl_opts, N_(\"Spend extra cycles to find better match\"), XDF_NEED_MINIMAL),\n \t\tOPT_STRING('S', NULL, &revs_file, N_(\"file\"), N_(\"Use revisions from <file> instead of calling git-rev-list\")),\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex dc0b7cc521..07839b0bb8 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -261,7 +261,7 @@ static struct option builtin_merge_options[] = {\n \t\toption_parse_message),\n \t{ OPTION_LOWLEVEL_CALLBACK, 'F', \"file\", &merge_msg, N_(\"path\"),\n \t\tN_(\"read message from file\"), PARSE_OPT_NONEG,\n-\t\t(parse_opt_cb *) option_read_message },\n+\t\tNULL, 0, option_read_message },\n \tOPT__VERBOSITY(&verbosity),\n \tOPT_BOOL(0, \"abort\", &abort_current_merge,\n \t\tN_(\"abort the current in-progress merge\")),\ndiff --git a/builtin/update-index.c b/builtin/update-index.c\nindex e19da77edc..727a8118b8 100644\n--- a/builtin/update-index.c\n+++ b/builtin/update-index.c\n@@ -985,7 +985,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \t\t\tN_(\"add the specified entry to the index\"),\n \t\t\tPARSE_OPT_NOARG | /* disallow --cacheinfo=<mode> form */\n \t\t\tPARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP,\n-\t\t\t(parse_opt_cb *) cacheinfo_callback},\n+\t\t\tNULL, 0,\n+\t\t\tcacheinfo_callback},\n \t\t{OPTION_CALLBACK, 0, \"chmod\", &set_executable_bit, \"(+|-)x\",\n \t\t\tN_(\"override the executable bit of the listed files\"),\n \t\t\tPARSE_OPT_NONEG,\n@@ -1011,19 +1012,19 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \t\t{OPTION_LOWLEVEL_CALLBACK, 0, \"stdin\", &read_from_stdin, NULL,\n \t\t\tN_(\"read list of paths to be updated from standard input\"),\n \t\t\tPARSE_OPT_NONEG | PARSE_OPT_NOARG,\n-\t\t\t(parse_opt_cb *) stdin_callback},\n+\t\t\tNULL, 0, stdin_callback},\n \t\t{OPTION_LOWLEVEL_CALLBACK, 0, \"index-info\", &nul_term_line, NULL,\n \t\t\tN_(\"add entries from standard input to the index\"),\n \t\t\tPARSE_OPT_NONEG | PARSE_OPT_NOARG,\n-\t\t\t(parse_opt_cb *) stdin_cacheinfo_callback},\n+\t\t\tNULL, 0, stdin_cacheinfo_callback},\n \t\t{OPTION_LOWLEVEL_CALLBACK, 0, \"unresolve\", &has_errors, NULL,\n \t\t\tN_(\"repopulate stages #2 and #3 for the listed paths\"),\n \t\t\tPARSE_OPT_NONEG | PARSE_OPT_NOARG,\n-\t\t\t(parse_opt_cb *) unresolve_callback},\n+\t\t\tNULL, 0, unresolve_callback},\n \t\t{OPTION_LOWLEVEL_CALLBACK, 'g', \"again\", &has_errors, NULL,\n \t\t\tN_(\"only update entries that differ from HEAD\"),\n \t\t\tPARSE_OPT_NONEG | PARSE_OPT_NOARG,\n-\t\t\t(parse_opt_cb *) reupdate_callback},\n+\t\t\tNULL, 0, reupdate_callback},\n \t\tOPT_BIT(0, \"ignore-missing\", &refresh_args.flags,\n \t\t\tN_(\"ignore files missing from worktree\"),\n \t\t\tREFRESH_IGNORE_MISSING),\ndiff --git a/parse-options-cb.c b/parse-options-cb.c\nindex e2f3eaed07..e05bcea809 100644\n--- a/parse-options-cb.c\n+++ b/parse-options-cb.c\n@@ -170,7 +170,8 @@ int parse_opt_noop_cb(const struct option *opt, const char *arg, int unset)\n  * \"-h\" output even if it's not being handled directly by\n  * parse_options().\n  */\n-int parse_opt_unknown_cb(const struct option *opt, const char *arg, int unset)\n+int parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx,\n+\t\t\t const struct option *opt, int unset)\n {\n \treturn -2;\n }\ndiff --git a/parse-options.c b/parse-options.c\nindex 1244968855..ac109e11e9 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -93,7 +93,7 @@ static int get_value(struct parse_opt_ctx_t *p,\n \n \tswitch (opt->type) {\n \tcase OPTION_LOWLEVEL_CALLBACK:\n-\t\treturn (*(parse_opt_ll_cb *)opt->callback)(p, opt, unset);\n+\t\treturn opt->ll_callback(p, opt, unset);\n \n \tcase OPTION_BIT:\n \t\tif (unset)\n@@ -408,6 +408,19 @@ static void parse_options_check(const struct option *opts)\n \t\t\tif ((opts->flags & PARSE_OPT_OPTARG) ||\n \t\t\t    !(opts->flags & PARSE_OPT_NOARG))\n \t\t\t\terr |= optbug(opts, \"should not accept an argument\");\n+\t\t\tbreak;\n+\t\tcase OPTION_CALLBACK:\n+\t\t\tif (!opts->callback)\n+\t\t\t\tBUG(\"OPTION_CALLBACK needs a callback\");\n+\t\t\tif (opts->ll_callback)\n+\t\t\t\tBUG(\"OPTION_CALLBACK needs no ll_callback\");\n+\t\t\tbreak;\n+\t\tcase OPTION_LOWLEVEL_CALLBACK:\n+\t\t\tif (!opts->ll_callback)\n+\t\t\t\tBUG(\"OPTION_LOWLEVEL_CALLBACK needs a callback\");\n+\t\t\tif (opts->callback)\n+\t\t\t\tBUG(\"OPTION_LOWLEVEL_CALLBACK needs no high level callback\");\n+\t\t\tbreak;\n \t\tdefault:\n \t\t\t; /* ok. (usually accepts an argument) */\n \t\t}\ndiff --git a/parse-options.h b/parse-options.h\nindex c97324f576..f1f246387c 100644\n--- a/parse-options.h\n+++ b/parse-options.h\n@@ -100,13 +100,16 @@ typedef int parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,\n  *\t\t\t the option takes optional argument.\n  *\n  * `callback`::\n- *   pointer to the callback to use for OPTION_CALLBACK or\n- *   OPTION_LOWLEVEL_CALLBACK.\n+ *   pointer to the callback to use for OPTION_CALLBACK\n  *\n  * `defval`::\n  *   default value to fill (*->value) with for PARSE_OPT_OPTARG.\n  *   OPTION_{BIT,SET_INT} store the {mask,integer} to put in the value when met.\n  *   CALLBACKS can use it like they want.\n+ *\n+ * `ll_callback`::\n+ *   pointer to the callback to use for OPTION_LOWLEVEL_CALLBACK\n+ *\n  */\n struct option {\n \tenum parse_opt_type type;\n@@ -119,6 +122,7 @@ struct option {\n \tint flags;\n \tparse_opt_cb *callback;\n \tintptr_t defval;\n+\tparse_opt_ll_cb *ll_callback;\n \tintptr_t extra;\n };\n \n@@ -137,7 +141,7 @@ struct option {\n #define OPT_BIT(s, l, v, h, b)      OPT_BIT_F(s, l, v, h, b, 0)\n #define OPT_BITOP(s, l, v, h, set, clear) { OPTION_BITOP, (s), (l), (v), NULL, (h), \\\n \t\t\t\t\t    PARSE_OPT_NOARG|PARSE_OPT_NONEG, NULL, \\\n-\t\t\t\t\t    (set), (clear) }\n+\t\t\t\t\t    (set), NULL, (clear) }\n #define OPT_NEGBIT(s, l, v, h, b)   { OPTION_NEGBIT, (s), (l), (v), NULL, \\\n \t\t\t\t      (h), PARSE_OPT_NOARG, NULL, (b) }\n #define OPT_COUNTUP(s, l, v, h)     OPT_COUNTUP_F(s, l, v, h, 0)\n@@ -263,7 +267,7 @@ int parse_opt_commits(const struct option *, const char *, int);\n int parse_opt_tertiary(const struct option *, const char *, int);\n int parse_opt_string_list(const struct option *, const char *, int);\n int parse_opt_noop_cb(const struct option *, const char *, int);\n-int parse_opt_unknown_cb(const struct option *, const char *, int);\n+int parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx, const struct option *, int);\n int parse_opt_passthru(const struct option *, const char *, int);\n int parse_opt_passthru_argv(const struct option *, const char *, int);\n \n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366918","messageId":"20190117130615.18732-8-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 07/76] parse-options: avoid magic return codes","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:06Z","receivedAt":"2019-01-17T13:07:10Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Give names to these magic negative numbers. Make parse_opt_ll_cb\nreturn an enum to make clear it can actually control parse_options()\nwith different return values (parse_opt_cb can too, but nobody needs\nit).\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/merge.c        |  5 +--\n builtin/update-index.c | 20 ++++++------\n parse-options-cb.c     |  6 ++--\n parse-options.c        | 69 +++++++++++++++++++++++++++---------------\n parse-options.h        | 14 ++++-----\n 5 files changed, 68 insertions(+), 46 deletions(-)\n\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 07839b0bb8..de64d7850e 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -112,8 +112,9 @@ static int option_parse_message(const struct option *opt,\n \treturn 0;\n }\n \n-static int option_read_message(struct parse_opt_ctx_t *ctx,\n-\t\t\t       const struct option *opt, int unset)\n+static enum parse_opt_result option_read_message(struct parse_opt_ctx_t *ctx,\n+\t\t\t\t\t\t const struct option *opt,\n+\t\t\t\t\t\t int unset)\n {\n \tstruct strbuf *buf = opt->value;\n \tconst char *arg;\ndiff --git a/builtin/update-index.c b/builtin/update-index.c\nindex 727a8118b8..21c84e5590 100644\n--- a/builtin/update-index.c\n+++ b/builtin/update-index.c\n@@ -847,8 +847,8 @@ static int parse_new_style_cacheinfo(const char *arg,\n \treturn 0;\n }\n \n-static int cacheinfo_callback(struct parse_opt_ctx_t *ctx,\n-\t\t\t\tconst struct option *opt, int unset)\n+static enum parse_opt_result cacheinfo_callback(\n+\tstruct parse_opt_ctx_t *ctx, const struct option *opt, int unset)\n {\n \tstruct object_id oid;\n \tunsigned int mode;\n@@ -873,8 +873,8 @@ static int cacheinfo_callback(struct parse_opt_ctx_t *ctx,\n \treturn 0;\n }\n \n-static int stdin_cacheinfo_callback(struct parse_opt_ctx_t *ctx,\n-\t\t\t      const struct option *opt, int unset)\n+static enum parse_opt_result stdin_cacheinfo_callback(\n+\tstruct parse_opt_ctx_t *ctx, const struct option *opt, int unset)\n {\n \tint *nul_term_line = opt->value;\n \n@@ -887,8 +887,8 @@ static int stdin_cacheinfo_callback(struct parse_opt_ctx_t *ctx,\n \treturn 0;\n }\n \n-static int stdin_callback(struct parse_opt_ctx_t *ctx,\n-\t\t\t\tconst struct option *opt, int unset)\n+static enum parse_opt_result stdin_callback(\n+\tstruct parse_opt_ctx_t *ctx, const struct option *opt, int unset)\n {\n \tint *read_from_stdin = opt->value;\n \n@@ -900,8 +900,8 @@ static int stdin_callback(struct parse_opt_ctx_t *ctx,\n \treturn 0;\n }\n \n-static int unresolve_callback(struct parse_opt_ctx_t *ctx,\n-\t\t\t\tconst struct option *opt, int unset)\n+static enum parse_opt_result unresolve_callback(\n+\tstruct parse_opt_ctx_t *ctx, const struct option *opt, int unset)\n {\n \tint *has_errors = opt->value;\n \tconst char *prefix = startup_info->prefix;\n@@ -919,8 +919,8 @@ static int unresolve_callback(struct parse_opt_ctx_t *ctx,\n \treturn 0;\n }\n \n-static int reupdate_callback(struct parse_opt_ctx_t *ctx,\n-\t\t\t\tconst struct option *opt, int unset)\n+static enum parse_opt_result reupdate_callback(\n+\tstruct parse_opt_ctx_t *ctx, const struct option *opt, int unset)\n {\n \tint *has_errors = opt->value;\n \tconst char *prefix = startup_info->prefix;\ndiff --git a/parse-options-cb.c b/parse-options-cb.c\nindex e05bcea809..ec01ef722b 100644\n--- a/parse-options-cb.c\n+++ b/parse-options-cb.c\n@@ -170,10 +170,10 @@ int parse_opt_noop_cb(const struct option *opt, const char *arg, int unset)\n  * \"-h\" output even if it's not being handled directly by\n  * parse_options().\n  */\n-int parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx,\n-\t\t\t const struct option *opt, int unset)\n+enum parse_opt_result parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx,\n+\t\t\t\t\t   const struct option *opt, int unset)\n {\n-\treturn -2;\n+\treturn PARSE_OPT_UNKNOWN;\n }\n \n /**\ndiff --git a/parse-options.c b/parse-options.c\nindex ac109e11e9..372f5cede4 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -20,8 +20,9 @@ int optbug(const struct option *opt, const char *reason)\n \treturn error(\"BUG: switch '%c' %s\", opt->short_name, reason);\n }\n \n-static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt,\n-\t\t   int flags, const char **arg)\n+static enum parse_opt_result get_arg(struct parse_opt_ctx_t *p,\n+\t\t\t\t     const struct option *opt,\n+\t\t\t\t     int flags, const char **arg)\n {\n \tif (p->opt) {\n \t\t*arg = p->opt;\n@@ -44,9 +45,10 @@ static void fix_filename(const char *prefix, const char **file)\n \t*file = prefix_filename(prefix, *file);\n }\n \n-static int opt_command_mode_error(const struct option *opt,\n-\t\t\t\t  const struct option *all_opts,\n-\t\t\t\t  int flags)\n+static enum parse_opt_result opt_command_mode_error(\n+\tconst struct option *opt,\n+\tconst struct option *all_opts,\n+\tint flags)\n {\n \tconst struct option *that;\n \tstruct strbuf that_name = STRBUF_INIT;\n@@ -69,16 +71,16 @@ static int opt_command_mode_error(const struct option *opt,\n \t\terror(_(\"%s is incompatible with %s\"),\n \t\t      optname(opt, flags), that_name.buf);\n \t\tstrbuf_release(&that_name);\n-\t\treturn -1;\n+\t\treturn PARSE_OPT_ERROR;\n \t}\n \treturn error(_(\"%s : incompatible with something else\"),\n \t\t     optname(opt, flags));\n }\n \n-static int get_value(struct parse_opt_ctx_t *p,\n-\t\t     const struct option *opt,\n-\t\t     const struct option *all_opts,\n-\t\t     int flags)\n+static enum parse_opt_result get_value(struct parse_opt_ctx_t *p,\n+\t\t\t\t       const struct option *opt,\n+\t\t\t\t       const struct option *all_opts,\n+\t\t\t\t       int flags)\n {\n \tconst char *s, *arg;\n \tconst int unset = flags & OPT_UNSET;\n@@ -208,7 +210,8 @@ static int get_value(struct parse_opt_ctx_t *p,\n \t}\n }\n \n-static int parse_short_opt(struct parse_opt_ctx_t *p, const struct option *options)\n+static enum parse_opt_result parse_short_opt(struct parse_opt_ctx_t *p,\n+\t\t\t\t\t     const struct option *options)\n {\n \tconst struct option *all_opts = options;\n \tconst struct option *numopt = NULL;\n@@ -239,11 +242,12 @@ static int parse_short_opt(struct parse_opt_ctx_t *p, const struct option *optio\n \t\tfree(arg);\n \t\treturn rc;\n \t}\n-\treturn -2;\n+\treturn PARSE_OPT_UNKNOWN;\n }\n \n-static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,\n-\t\t\t  const struct option *options)\n+static enum parse_opt_result parse_long_opt(\n+\tstruct parse_opt_ctx_t *p, const char *arg,\n+\tconst struct option *options)\n {\n \tconst struct option *all_opts = options;\n \tconst char *arg_end = strchrnul(arg, '=');\n@@ -269,7 +273,7 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,\n \t\t\tif (*rest)\n \t\t\t\tcontinue;\n \t\t\tp->out[p->cpidx++] = arg - 2;\n-\t\t\treturn 0;\n+\t\t\treturn PARSE_OPT_DONE;\n \t\t}\n \t\tif (!rest) {\n \t\t\t/* abbreviated? */\n@@ -334,11 +338,11 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,\n \t\t\tambiguous_option->long_name,\n \t\t\t(abbrev_flags & OPT_UNSET) ?  \"no-\" : \"\",\n \t\t\tabbrev_option->long_name);\n-\t\treturn -3;\n+\t\treturn PARSE_OPT_HELP;\n \t}\n \tif (abbrev_option)\n \t\treturn get_value(p, abbrev_option, all_opts, abbrev_flags);\n-\treturn -2;\n+\treturn PARSE_OPT_UNKNOWN;\n }\n \n static int parse_nodash_opt(struct parse_opt_ctx_t *p, const char *arg,\n@@ -586,22 +590,28 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,\n \t\tif (arg[1] != '-') {\n \t\t\tctx->opt = arg + 1;\n \t\t\tswitch (parse_short_opt(ctx, options)) {\n-\t\t\tcase -1:\n+\t\t\tcase PARSE_OPT_ERROR:\n \t\t\t\treturn PARSE_OPT_ERROR;\n-\t\t\tcase -2:\n+\t\t\tcase PARSE_OPT_UNKNOWN:\n \t\t\t\tif (ctx->opt)\n \t\t\t\t\tcheck_typos(arg + 1, options);\n \t\t\t\tif (internal_help && *ctx->opt == 'h')\n \t\t\t\t\tgoto show_usage;\n \t\t\t\tgoto unknown;\n+\t\t\tcase PARSE_OPT_NON_OPTION:\n+\t\t\tcase PARSE_OPT_HELP:\n+\t\t\tcase PARSE_OPT_COMPLETE:\n+\t\t\t\tBUG(\"parse_short_opt() cannot return these\");\n+\t\t\tcase PARSE_OPT_DONE:\n+\t\t\t\tbreak;\n \t\t\t}\n \t\t\tif (ctx->opt)\n \t\t\t\tcheck_typos(arg + 1, options);\n \t\t\twhile (ctx->opt) {\n \t\t\t\tswitch (parse_short_opt(ctx, options)) {\n-\t\t\t\tcase -1:\n+\t\t\t\tcase PARSE_OPT_ERROR:\n \t\t\t\t\treturn PARSE_OPT_ERROR;\n-\t\t\t\tcase -2:\n+\t\t\t\tcase PARSE_OPT_UNKNOWN:\n \t\t\t\t\tif (internal_help && *ctx->opt == 'h')\n \t\t\t\t\t\tgoto show_usage;\n \n@@ -613,6 +623,12 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,\n \t\t\t\t\tctx->argv[0] = xstrdup(ctx->opt - 1);\n \t\t\t\t\t*(char *)ctx->argv[0] = '-';\n \t\t\t\t\tgoto unknown;\n+\t\t\t\tcase PARSE_OPT_NON_OPTION:\n+\t\t\t\tcase PARSE_OPT_COMPLETE:\n+\t\t\t\tcase PARSE_OPT_HELP:\n+\t\t\t\t\tBUG(\"parse_short_opt() cannot return these\");\n+\t\t\t\tcase PARSE_OPT_DONE:\n+\t\t\t\t\tbreak;\n \t\t\t\t}\n \t\t\t}\n \t\t\tcontinue;\n@@ -631,12 +647,17 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,\n \t\tif (internal_help && !strcmp(arg + 2, \"help\"))\n \t\t\tgoto show_usage;\n \t\tswitch (parse_long_opt(ctx, arg + 2, options)) {\n-\t\tcase -1:\n+\t\tcase PARSE_OPT_ERROR:\n \t\t\treturn PARSE_OPT_ERROR;\n-\t\tcase -2:\n+\t\tcase PARSE_OPT_UNKNOWN:\n \t\t\tgoto unknown;\n-\t\tcase -3:\n+\t\tcase PARSE_OPT_HELP:\n \t\t\tgoto show_usage;\n+\t\tcase PARSE_OPT_NON_OPTION:\n+\t\tcase PARSE_OPT_COMPLETE:\n+\t\t\tBUG(\"parse_long_opt() cannot return these\");\n+\t\tcase PARSE_OPT_DONE:\n+\t\t\tbreak;\n \t\t}\n \t\tcontinue;\n unknown:\ndiff --git a/parse-options.h b/parse-options.h\nindex f1f246387c..4e49185027 100644\n--- a/parse-options.h\n+++ b/parse-options.h\n@@ -49,8 +49,8 @@ struct option;\n typedef int parse_opt_cb(const struct option *, const char *arg, int unset);\n \n struct parse_opt_ctx_t;\n-typedef int parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,\n-\t\t\t\tconst struct option *opt, int unset);\n+typedef enum parse_opt_result parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,\n+\t\t\t\t\t      const struct option *opt, int unset);\n \n /*\n  * `type`::\n@@ -222,12 +222,12 @@ const char *optname(const struct option *opt, int flags);\n \n /*----- incremental advanced APIs -----*/\n \n-enum {\n-\tPARSE_OPT_COMPLETE = -2,\n-\tPARSE_OPT_HELP = -1,\n-\tPARSE_OPT_DONE,\n+enum parse_opt_result {\n+\tPARSE_OPT_COMPLETE = -3,\n+\tPARSE_OPT_HELP = -2,\n+\tPARSE_OPT_ERROR = -1,\t/* must be the same as error() */\n+\tPARSE_OPT_DONE = 0,\t/* fixed so that \"return 0\" works */\n \tPARSE_OPT_NON_OPTION,\n-\tPARSE_OPT_ERROR,\n \tPARSE_OPT_UNKNOWN\n };\n \n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366919","messageId":"20190117130615.18732-9-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 08/76] parse-options: allow ll_callback with OPTION_CALLBACK","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:07Z","receivedAt":"2019-01-17T13:07:14Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"OPTION_CALLBACK is much simpler/safer to use, but parse_opt_cb does\nnot allow access to parse_opt_ctx_t, which sometimes is useful\n(e.g. to obtain the prefix).\n\nExtending parse_opt_cb to take parse_opt_cb could result in a lot of\nchanges. Instead let's just allow ll_callback to be used with\nOPTION_CALLBACK. The user will have to be careful, not to change\nanything in ctx, or return wrong result code. But that's the price for\nll_callback.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/merge.c        |  2 ++\n builtin/update-index.c | 20 +++++++++++++++-----\n parse-options-cb.c     |  4 +++-\n parse-options.c        | 42 ++++++++++++++++++++++++++++--------------\n parse-options.h        |  5 +++--\n 5 files changed, 51 insertions(+), 22 deletions(-)\n\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex de64d7850e..563a16f38a 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -114,11 +114,13 @@ static int option_parse_message(const struct option *opt,\n \n static enum parse_opt_result option_read_message(struct parse_opt_ctx_t *ctx,\n \t\t\t\t\t\t const struct option *opt,\n+\t\t\t\t\t\t const char *arg_not_used,\n \t\t\t\t\t\t int unset)\n {\n \tstruct strbuf *buf = opt->value;\n \tconst char *arg;\n \n+\tBUG_ON_OPT_ARG(arg_not_used);\n \tif (unset)\n \t\tBUG(\"-F cannot be negated\");\n \ndiff --git a/builtin/update-index.c b/builtin/update-index.c\nindex 21c84e5590..7abde20169 100644\n--- a/builtin/update-index.c\n+++ b/builtin/update-index.c\n@@ -848,13 +848,15 @@ static int parse_new_style_cacheinfo(const char *arg,\n }\n \n static enum parse_opt_result cacheinfo_callback(\n-\tstruct parse_opt_ctx_t *ctx, const struct option *opt, int unset)\n+\tstruct parse_opt_ctx_t *ctx, const struct option *opt,\n+\tconst char *arg, int unset)\n {\n \tstruct object_id oid;\n \tunsigned int mode;\n \tconst char *path;\n \n \tBUG_ON_OPT_NEG(unset);\n+\tBUG_ON_OPT_ARG(arg);\n \n \tif (!parse_new_style_cacheinfo(ctx->argv[1], &mode, &oid, &path)) {\n \t\tif (add_cacheinfo(mode, &oid, path, 0))\n@@ -874,11 +876,13 @@ static enum parse_opt_result cacheinfo_callback(\n }\n \n static enum parse_opt_result stdin_cacheinfo_callback(\n-\tstruct parse_opt_ctx_t *ctx, const struct option *opt, int unset)\n+\tstruct parse_opt_ctx_t *ctx, const struct option *opt,\n+\tconst char *arg, int unset)\n {\n \tint *nul_term_line = opt->value;\n \n \tBUG_ON_OPT_NEG(unset);\n+\tBUG_ON_OPT_ARG(arg);\n \n \tif (ctx->argc != 1)\n \t\treturn error(\"option '%s' must be the last argument\", opt->long_name);\n@@ -888,11 +892,13 @@ static enum parse_opt_result stdin_cacheinfo_callback(\n }\n \n static enum parse_opt_result stdin_callback(\n-\tstruct parse_opt_ctx_t *ctx, const struct option *opt, int unset)\n+\tstruct parse_opt_ctx_t *ctx, const struct option *opt,\n+\tconst char *arg, int unset)\n {\n \tint *read_from_stdin = opt->value;\n \n \tBUG_ON_OPT_NEG(unset);\n+\tBUG_ON_OPT_ARG(arg);\n \n \tif (ctx->argc != 1)\n \t\treturn error(\"option '%s' must be the last argument\", opt->long_name);\n@@ -901,12 +907,14 @@ static enum parse_opt_result stdin_callback(\n }\n \n static enum parse_opt_result unresolve_callback(\n-\tstruct parse_opt_ctx_t *ctx, const struct option *opt, int unset)\n+\tstruct parse_opt_ctx_t *ctx, const struct option *opt,\n+\tconst char *arg, int unset)\n {\n \tint *has_errors = opt->value;\n \tconst char *prefix = startup_info->prefix;\n \n \tBUG_ON_OPT_NEG(unset);\n+\tBUG_ON_OPT_ARG(arg);\n \n \t/* consume remaining arguments. */\n \t*has_errors = do_unresolve(ctx->argc, ctx->argv,\n@@ -920,12 +928,14 @@ static enum parse_opt_result unresolve_callback(\n }\n \n static enum parse_opt_result reupdate_callback(\n-\tstruct parse_opt_ctx_t *ctx, const struct option *opt, int unset)\n+\tstruct parse_opt_ctx_t *ctx, const struct option *opt,\n+\tconst char *arg, int unset)\n {\n \tint *has_errors = opt->value;\n \tconst char *prefix = startup_info->prefix;\n \n \tBUG_ON_OPT_NEG(unset);\n+\tBUG_ON_OPT_ARG(arg);\n \n \t/* consume remaining arguments. */\n \tsetup_work_tree();\ndiff --git a/parse-options-cb.c b/parse-options-cb.c\nindex ec01ef722b..2733393546 100644\n--- a/parse-options-cb.c\n+++ b/parse-options-cb.c\n@@ -171,8 +171,10 @@ int parse_opt_noop_cb(const struct option *opt, const char *arg, int unset)\n  * parse_options().\n  */\n enum parse_opt_result parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx,\n-\t\t\t\t\t   const struct option *opt, int unset)\n+\t\t\t\t\t   const struct option *opt,\n+\t\t\t\t\t   const char *arg, int unset)\n {\n+\tBUG_ON_OPT_ARG(arg);\n \treturn PARSE_OPT_UNKNOWN;\n }\n \ndiff --git a/parse-options.c b/parse-options.c\nindex 372f5cede4..a0ff8ea225 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -95,7 +95,7 @@ static enum parse_opt_result get_value(struct parse_opt_ctx_t *p,\n \n \tswitch (opt->type) {\n \tcase OPTION_LOWLEVEL_CALLBACK:\n-\t\treturn opt->ll_callback(p, opt, unset);\n+\t\treturn opt->ll_callback(p, opt, NULL, unset);\n \n \tcase OPTION_BIT:\n \t\tif (unset)\n@@ -161,16 +161,27 @@ static enum parse_opt_result get_value(struct parse_opt_ctx_t *p,\n \t\treturn err;\n \n \tcase OPTION_CALLBACK:\n+\t{\n+\t\tconst char *p_arg = NULL;\n+\t\tint p_unset;\n+\n \t\tif (unset)\n-\t\t\treturn (*opt->callback)(opt, NULL, 1) ? (-1) : 0;\n-\t\tif (opt->flags & PARSE_OPT_NOARG)\n-\t\t\treturn (*opt->callback)(opt, NULL, 0) ? (-1) : 0;\n-\t\tif (opt->flags & PARSE_OPT_OPTARG && !p->opt)\n-\t\t\treturn (*opt->callback)(opt, NULL, 0) ? (-1) : 0;\n-\t\tif (get_arg(p, opt, flags, &arg))\n+\t\t\tp_unset = 1;\n+\t\telse if (opt->flags & PARSE_OPT_NOARG)\n+\t\t\tp_unset = 0;\n+\t\telse if (opt->flags & PARSE_OPT_OPTARG && !p->opt)\n+\t\t\tp_unset = 0;\n+\t\telse if (get_arg(p, opt, flags, &arg))\n \t\t\treturn -1;\n-\t\treturn (*opt->callback)(opt, arg, 0) ? (-1) : 0;\n-\n+\t\telse {\n+\t\t\tp_unset = 0;\n+\t\t\tp_arg = arg;\n+\t\t}\n+\t\tif (opt->callback)\n+\t\t\treturn (*opt->callback)(opt, p_arg, p_unset) ? (-1) : 0;\n+\t\telse\n+\t\t\treturn (*opt->ll_callback)(p, opt, p_arg, p_unset);\n+\t}\n \tcase OPTION_INTEGER:\n \t\tif (unset) {\n \t\t\t*(int *)opt->value = 0;\n@@ -238,7 +249,10 @@ static enum parse_opt_result parse_short_opt(struct parse_opt_ctx_t *p,\n \t\t\tlen++;\n \t\targ = xmemdupz(p->opt, len);\n \t\tp->opt = p->opt[len] ? p->opt + len : NULL;\n-\t\trc = (*numopt->callback)(numopt, arg, 0) ? (-1) : 0;\n+\t\tif (numopt->callback)\n+\t\t\trc = (*numopt->callback)(numopt, arg, 0) ? (-1) : 0;\n+\t\telse\n+\t\t\trc = (*numopt->ll_callback)(p, numopt, arg, 0);\n \t\tfree(arg);\n \t\treturn rc;\n \t}\n@@ -414,10 +428,10 @@ static void parse_options_check(const struct option *opts)\n \t\t\t\terr |= optbug(opts, \"should not accept an argument\");\n \t\t\tbreak;\n \t\tcase OPTION_CALLBACK:\n-\t\t\tif (!opts->callback)\n-\t\t\t\tBUG(\"OPTION_CALLBACK needs a callback\");\n-\t\t\tif (opts->ll_callback)\n-\t\t\t\tBUG(\"OPTION_CALLBACK needs no ll_callback\");\n+\t\t\tif (!opts->callback && !opts->ll_callback)\n+\t\t\t\tBUG(\"OPTION_CALLBACK needs one callback\");\n+\t\t\tif (opts->callback && opts->ll_callback)\n+\t\t\t\tBUG(\"OPTION_CALLBACK can't have two callbacks\");\n \t\t\tbreak;\n \t\tcase OPTION_LOWLEVEL_CALLBACK:\n \t\t\tif (!opts->ll_callback)\ndiff --git a/parse-options.h b/parse-options.h\nindex 4e49185027..ce75278804 100644\n--- a/parse-options.h\n+++ b/parse-options.h\n@@ -50,7 +50,8 @@ typedef int parse_opt_cb(const struct option *, const char *arg, int unset);\n \n struct parse_opt_ctx_t;\n typedef enum parse_opt_result parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,\n-\t\t\t\t\t      const struct option *opt, int unset);\n+\t\t\t\t\t      const struct option *opt,\n+\t\t\t\t\t      const char *arg, int unset);\n \n /*\n  * `type`::\n@@ -267,7 +268,7 @@ int parse_opt_commits(const struct option *, const char *, int);\n int parse_opt_tertiary(const struct option *, const char *, int);\n int parse_opt_string_list(const struct option *, const char *, int);\n int parse_opt_noop_cb(const struct option *, const char *, int);\n-int parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx, const struct option *, int);\n+int parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx, const struct option *, const char *, int);\n int parse_opt_passthru(const struct option *, const char *, int);\n int parse_opt_passthru_argv(const struct option *, const char *, int);\n \n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366920","messageId":"20190117130615.18732-10-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 09/76] diff.h: keep forward struct declarations sorted","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:08Z","receivedAt":"2019-01-17T13:07:19Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.h | 12 ++++++------\n 1 file changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/diff.h b/diff.h\nindex b512d0477a..c872a41344 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -9,16 +9,16 @@\n #include \"object.h\"\n #include \"oidset.h\"\n \n-struct rev_info;\n+struct combine_diff_path;\n+struct commit;\n+struct diff_filespec;\n struct diff_options;\n struct diff_queue_struct;\n-struct strbuf;\n-struct diff_filespec;\n-struct userdiff_driver;\n struct oid_array;\n-struct commit;\n-struct combine_diff_path;\n struct repository;\n+struct rev_info;\n+struct strbuf;\n+struct userdiff_driver;\n \n typedef int (*pathchange_fn_t)(struct diff_options *options,\n \t\t struct combine_diff_path *path);\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366921","messageId":"20190117130615.18732-11-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 10/76] diff.h: avoid bit fields in struct diff_flags","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:09Z","receivedAt":"2019-01-17T13:07:24Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Bitfield addresses cannot be passed around in a pointer. This makes it\nhard to use parse-options to set/unset them. Turn this struct to\nnormal integers. This of course increases the size of this struct\nmultiple times, but since we only have a handful of diff_options\nvariables around, memory consumption is not at all a concern.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.h | 66 +++++++++++++++++++++++++++++-----------------------------\n 1 file changed, 33 insertions(+), 33 deletions(-)\n\ndiff --git a/diff.h b/diff.h\nindex c872a41344..8abe1649d0 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -64,39 +64,39 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data)\n \n #define DIFF_FLAGS_INIT { 0 }\n struct diff_flags {\n-\tunsigned recursive:1;\n-\tunsigned tree_in_recursive:1;\n-\tunsigned binary:1;\n-\tunsigned text:1;\n-\tunsigned full_index:1;\n-\tunsigned silent_on_remove:1;\n-\tunsigned find_copies_harder:1;\n-\tunsigned follow_renames:1;\n-\tunsigned rename_empty:1;\n-\tunsigned has_changes:1;\n-\tunsigned quick:1;\n-\tunsigned no_index:1;\n-\tunsigned allow_external:1;\n-\tunsigned exit_with_status:1;\n-\tunsigned reverse_diff:1;\n-\tunsigned check_failed:1;\n-\tunsigned relative_name:1;\n-\tunsigned ignore_submodules:1;\n-\tunsigned dirstat_cumulative:1;\n-\tunsigned dirstat_by_file:1;\n-\tunsigned allow_textconv:1;\n-\tunsigned textconv_set_via_cmdline:1;\n-\tunsigned diff_from_contents:1;\n-\tunsigned dirty_submodules:1;\n-\tunsigned ignore_untracked_in_submodules:1;\n-\tunsigned ignore_dirty_submodules:1;\n-\tunsigned override_submodule_config:1;\n-\tunsigned dirstat_by_line:1;\n-\tunsigned funccontext:1;\n-\tunsigned default_follow_renames:1;\n-\tunsigned stat_with_summary:1;\n-\tunsigned suppress_diff_headers:1;\n-\tunsigned dual_color_diffed_diffs:1;\n+\tunsigned recursive;\n+\tunsigned tree_in_recursive;\n+\tunsigned binary;\n+\tunsigned text;\n+\tunsigned full_index;\n+\tunsigned silent_on_remove;\n+\tunsigned find_copies_harder;\n+\tunsigned follow_renames;\n+\tunsigned rename_empty;\n+\tunsigned has_changes;\n+\tunsigned quick;\n+\tunsigned no_index;\n+\tunsigned allow_external;\n+\tunsigned exit_with_status;\n+\tunsigned reverse_diff;\n+\tunsigned check_failed;\n+\tunsigned relative_name;\n+\tunsigned ignore_submodules;\n+\tunsigned dirstat_cumulative;\n+\tunsigned dirstat_by_file;\n+\tunsigned allow_textconv;\n+\tunsigned textconv_set_via_cmdline;\n+\tunsigned diff_from_contents;\n+\tunsigned dirty_submodules;\n+\tunsigned ignore_untracked_in_submodules;\n+\tunsigned ignore_dirty_submodules;\n+\tunsigned override_submodule_config;\n+\tunsigned dirstat_by_line;\n+\tunsigned funccontext;\n+\tunsigned default_follow_renames;\n+\tunsigned stat_with_summary;\n+\tunsigned suppress_diff_headers;\n+\tunsigned dual_color_diffed_diffs;\n };\n \n static inline void diff_flags_or(struct diff_flags *a,\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366922","messageId":"20190117130615.18732-12-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 11/76] diff.c: prepare to use parse_options() for parsing","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:10Z","receivedAt":"2019-01-17T13:07:29Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This is a preparation step to start using parse_options() to parse\ndiff/revision options instead of what we have now. There are a couple\nof good things from using parse_options():\n\n- better help usage\n- easier to add new options\n- better completion support\n- help usage generation\n- better integration with main command option parser. We can just\n  concat the main command's option array and diffopt's together and\n  parse all in one go.\n- detect colidding options (e.g. --reverse is used by revision code,\n  so diff code can't use it as long name for -R)\n- consistent syntax, e.g. option that takes mandatory argument will\n  now accept both \"--option=value\" and \"--option value\".\n\nThe plan is migrate all diff/rev options to parse_options(). Then we\ncould get rid of diff_opt_parse() and expose parseopts[] directly to\nthe caller.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 27 +++++++++++++++++++++++++++\n diff.h |  2 ++\n 2 files changed, 29 insertions(+)\n\ndiff --git a/diff.c b/diff.c\nindex f1e901a5fc..60f46052a4 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -23,6 +23,7 @@\n #include \"argv-array.h\"\n #include \"graph.h\"\n #include \"packfile.h\"\n+#include \"parse-options.h\"\n #include \"help.h\"\n \n #ifdef NO_FAST_WORKING_DIRECTORY\n@@ -4424,6 +4425,8 @@ static void run_checkdiff(struct diff_filepair *p, struct diff_options *o)\n \tbuiltin_checkdiff(name, other, attr_path, p->one, p->two, o);\n }\n \n+static void prep_parse_options(struct diff_options *options);\n+\n void repo_diff_setup(struct repository *r, struct diff_options *options)\n {\n \tmemcpy(options, &default_diff_options, sizeof(*options));\n@@ -4465,6 +4468,8 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)\n \n \toptions->color_moved = diff_color_moved_default;\n \toptions->color_moved_ws_handling = diff_color_moved_ws_default;\n+\n+\tprep_parse_options(options);\n }\n \n void diff_setup_done(struct diff_options *options)\n@@ -4568,6 +4573,8 @@ void diff_setup_done(struct diff_options *options)\n \n \tif (!options->use_color || external_diff())\n \t\toptions->color_moved = 0;\n+\n+\tFREE_AND_NULL(options->parseopts);\n }\n \n static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *val)\n@@ -4858,6 +4865,16 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)\n \treturn 1;\n }\n \n+static void prep_parse_options(struct diff_options *options)\n+{\n+\tstruct option parseopts[] = {\n+\t\tOPT_END()\n+\t};\n+\n+\tALLOC_ARRAY(options->parseopts, ARRAY_SIZE(parseopts));\n+\tmemcpy(options->parseopts, parseopts, sizeof(parseopts));\n+}\n+\n int diff_opt_parse(struct diff_options *options,\n \t\t   const char **av, int ac, const char *prefix)\n {\n@@ -4868,6 +4885,16 @@ int diff_opt_parse(struct diff_options *options,\n \tif (!prefix)\n \t\tprefix = \"\";\n \n+\tac = parse_options(ac, av, prefix, options->parseopts, NULL,\n+\t\t\t   PARSE_OPT_KEEP_DASHDASH |\n+\t\t\t   PARSE_OPT_KEEP_UNKNOWN |\n+\t\t\t   PARSE_OPT_NO_INTERNAL_HELP |\n+\t\t\t   PARSE_OPT_ONE_SHOT |\n+\t\t\t   PARSE_OPT_STOP_AT_NON_OPTION);\n+\n+\tif (ac)\n+\t\treturn ac;\n+\n \t/* Output format options */\n \tif (!strcmp(arg, \"-p\") || !strcmp(arg, \"-u\") || !strcmp(arg, \"--patch\")\n \t    || opt_arg(arg, 'U', \"unified\", &options->context))\ndiff --git a/diff.h b/diff.h\nindex 8abe1649d0..d9ad73f0e1 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -15,6 +15,7 @@ struct diff_filespec;\n struct diff_options;\n struct diff_queue_struct;\n struct oid_array;\n+struct option;\n struct repository;\n struct rev_info;\n struct strbuf;\n@@ -229,6 +230,7 @@ struct diff_options {\n \tunsigned color_moved_ws_handling;\n \n \tstruct repository *repo;\n+\tstruct option *parseopts;\n };\n \n void diff_emit_submodule_del(struct diff_options *o, const char *line);\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366923","messageId":"20190117130615.18732-13-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 12/76] diff.c: convert -u|-p|--patch","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:11Z","receivedAt":"2019-01-17T13:07:34Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 10 ++++++++--\n 1 file changed, 8 insertions(+), 2 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 60f46052a4..7b78af623b 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4868,6 +4868,13 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)\n static void prep_parse_options(struct diff_options *options)\n {\n \tstruct option parseopts[] = {\n+\t\tOPT_GROUP(N_(\"Diff output format options\")),\n+\t\tOPT_BITOP('p', \"patch\", &options->output_format,\n+\t\t\t  N_(\"generate patch\"),\n+\t\t\t  DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT),\n+\t\tOPT_BITOP('u', NULL, &options->output_format,\n+\t\t\t  N_(\"generate patch\"),\n+\t\t\t  DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT),\n \t\tOPT_END()\n \t};\n \n@@ -4896,8 +4903,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* Output format options */\n-\tif (!strcmp(arg, \"-p\") || !strcmp(arg, \"-u\") || !strcmp(arg, \"--patch\")\n-\t    || opt_arg(arg, 'U', \"unified\", &options->context))\n+\tif (opt_arg(arg, 'U', \"unified\", &options->context))\n \t\tenable_patch_output(&options->output_format);\n \telse if (!strcmp(arg, \"--raw\"))\n \t\toptions->output_format |= DIFF_FORMAT_RAW;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366924","messageId":"20190117130615.18732-14-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 13/76] diff.c: convert -U|--unified","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:12Z","receivedAt":"2019-01-17T13:07:39Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n Documentation/diff-options.txt |  2 +-\n diff.c                         | 23 ++++++++++++++++++++---\n parse-options.h                |  5 +++--\n 3 files changed, 24 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex b94d332f71..0711734b12 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -36,7 +36,7 @@ endif::git-format-patch[]\n -U<n>::\n --unified=<n>::\n \tGenerate diffs with <n> lines of context instead of\n-\tthe usual three.\n+\tthe usual three. Implies `--patch`.\n ifndef::git-format-patch[]\n \tImplies `-p`.\n endif::git-format-patch[]\ndiff --git a/diff.c b/diff.c\nindex 7b78af623b..5e31b95426 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4865,6 +4865,22 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)\n \treturn 1;\n }\n \n+static int diff_opt_unified(const struct option *opt,\n+\t\t\t    const char *arg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\tchar *s;\n+\n+\tBUG_ON_OPT_NEG(unset);\n+\n+\toptions->context = strtol(arg, &s, 10);\n+\tif (*s)\n+\t\treturn error(_(\"%s expects a numerical value\"), \"--unified\");\n+\tenable_patch_output(&options->output_format);\n+\n+\treturn 0;\n+}\n+\n static void prep_parse_options(struct diff_options *options)\n {\n \tstruct option parseopts[] = {\n@@ -4875,6 +4891,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_BITOP('u', NULL, &options->output_format,\n \t\t\t  N_(\"generate patch\"),\n \t\t\t  DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT),\n+\t\tOPT_CALLBACK_F('U', \"unified\", options, N_(\"<n>\"),\n+\t\t\t       N_(\"generate diffs with <n> lines context\"),\n+\t\t\t       PARSE_OPT_NONEG, diff_opt_unified),\n \t\tOPT_END()\n \t};\n \n@@ -4903,9 +4922,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* Output format options */\n-\tif (opt_arg(arg, 'U', \"unified\", &options->context))\n-\t\tenable_patch_output(&options->output_format);\n-\telse if (!strcmp(arg, \"--raw\"))\n+\tif (!strcmp(arg, \"--raw\"))\n \t\toptions->output_format |= DIFF_FORMAT_RAW;\n \telse if (!strcmp(arg, \"--patch-with-raw\")) {\n \t\tenable_patch_output(&options->output_format);\ndiff --git a/parse-options.h b/parse-options.h\nindex ce75278804..7d83e2971d 100644\n--- a/parse-options.h\n+++ b/parse-options.h\n@@ -134,6 +134,8 @@ struct option {\n #define OPT_SET_INT_F(s, l, v, h, i, f) { OPTION_SET_INT, (s), (l), (v), NULL, \\\n \t\t\t\t\t  (h), PARSE_OPT_NOARG | (f), NULL, (i) }\n #define OPT_BOOL_F(s, l, v, h, f)   OPT_SET_INT_F(s, l, v, h, 1, f)\n+#define OPT_CALLBACK_F(s, l, v, a, h, f, cb)\t\t\t\\\n+\t{ OPTION_CALLBACK, (s), (l), (v), (a), (h), (f), (cb) }\n \n #define OPT_END()                   { OPTION_END }\n #define OPT_ARGUMENT(l, h)          { OPTION_ARGUMENT, 0, (l), NULL, NULL, \\\n@@ -164,8 +166,7 @@ struct option {\n #define OPT_EXPIRY_DATE(s, l, v, h) \\\n \t{ OPTION_CALLBACK, (s), (l), (v), N_(\"expiry-date\"),(h), 0,\t\\\n \t  parse_opt_expiry_date_cb }\n-#define OPT_CALLBACK(s, l, v, a, h, f) \\\n-\t{ OPTION_CALLBACK, (s), (l), (v), (a), (h), 0, (f) }\n+#define OPT_CALLBACK(s, l, v, a, h, f) OPT_CALLBACK_F(s, l, v, a, h, 0, f)\n #define OPT_NUMBER_CALLBACK(v, h, f) \\\n \t{ OPTION_NUMBER, 0, NULL, (v), NULL, (h), \\\n \t  PARSE_OPT_NOARG | PARSE_OPT_NONEG, (f) }\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366925","messageId":"20190117130615.18732-15-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 14/76] diff.c: convert -W|--[no-]function-context","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:13Z","receivedAt":"2019-01-17T13:07:45Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 8 ++------\n 1 file changed, 2 insertions(+), 6 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 5e31b95426..db8cf7df87 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4894,6 +4894,8 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_CALLBACK_F('U', \"unified\", options, N_(\"<n>\"),\n \t\t\t       N_(\"generate diffs with <n> lines context\"),\n \t\t\t       PARSE_OPT_NONEG, diff_opt_unified),\n+\t\tOPT_BOOL('W', \"function-context\", &options->flags.funccontext,\n+\t\t\t N_(\"generate diffs with <n> lines context\")),\n \t\tOPT_END()\n \t};\n \n@@ -5210,12 +5212,6 @@ int diff_opt_parse(struct diff_options *options,\n \telse if (opt_arg(arg, '\\0', \"inter-hunk-context\",\n \t\t\t &options->interhunkcontext))\n \t\t;\n-\telse if (!strcmp(arg, \"-W\"))\n-\t\toptions->flags.funccontext = 1;\n-\telse if (!strcmp(arg, \"--function-context\"))\n-\t\toptions->flags.funccontext = 1;\n-\telse if (!strcmp(arg, \"--no-function-context\"))\n-\t\toptions->flags.funccontext = 0;\n \telse if ((argcount = parse_long_opt(\"output\", av, &optarg))) {\n \t\tchar *path = prefix_filename(prefix, optarg);\n \t\toptions->file = xfopen(path, \"w\");\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366926","messageId":"20190117130615.18732-16-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 15/76] diff.c: convert --raw","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:14Z","receivedAt":"2019-01-17T13:07:50Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex db8cf7df87..2ebe9b23c5 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4896,6 +4896,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t       PARSE_OPT_NONEG, diff_opt_unified),\n \t\tOPT_BOOL('W', \"function-context\", &options->flags.funccontext,\n \t\t\t N_(\"generate diffs with <n> lines context\")),\n+\t\tOPT_BIT_F(0, \"raw\", &options->output_format,\n+\t\t\t  N_(\"generate the diff in raw format\"),\n+\t\t\t  DIFF_FORMAT_RAW, PARSE_OPT_NONEG),\n \t\tOPT_END()\n \t};\n \n@@ -4924,9 +4927,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* Output format options */\n-\tif (!strcmp(arg, \"--raw\"))\n-\t\toptions->output_format |= DIFF_FORMAT_RAW;\n-\telse if (!strcmp(arg, \"--patch-with-raw\")) {\n+\tif (!strcmp(arg, \"--patch-with-raw\")) {\n \t\tenable_patch_output(&options->output_format);\n \t\toptions->output_format |= DIFF_FORMAT_RAW;\n \t} else if (!strcmp(arg, \"--numstat\"))\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366927","messageId":"20190117130615.18732-17-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 16/76] diff.c: convert --patch-with-raw","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:15Z","receivedAt":"2019-01-17T13:07:55Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 9 +++++----\n 1 file changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 2ebe9b23c5..07796d2b3c 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4899,6 +4899,10 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_BIT_F(0, \"raw\", &options->output_format,\n \t\t\t  N_(\"generate the diff in raw format\"),\n \t\t\t  DIFF_FORMAT_RAW, PARSE_OPT_NONEG),\n+\t\tOPT_BITOP(0, \"patch-with-raw\", &options->output_format,\n+\t\t\t  N_(\"synonym for '-p --raw'\"),\n+\t\t\t  DIFF_FORMAT_PATCH | DIFF_FORMAT_RAW,\n+\t\t\t  DIFF_FORMAT_NO_OUTPUT),\n \t\tOPT_END()\n \t};\n \n@@ -4927,10 +4931,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* Output format options */\n-\tif (!strcmp(arg, \"--patch-with-raw\")) {\n-\t\tenable_patch_output(&options->output_format);\n-\t\toptions->output_format |= DIFF_FORMAT_RAW;\n-\t} else if (!strcmp(arg, \"--numstat\"))\n+\tif (!strcmp(arg, \"--numstat\"))\n \t\toptions->output_format |= DIFF_FORMAT_NUMSTAT;\n \telse if (!strcmp(arg, \"--shortstat\"))\n \t\toptions->output_format |= DIFF_FORMAT_SHORTSTAT;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366928","messageId":"20190117130615.18732-18-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 17/76] diff.c: convert --numstat and --shortstat","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:16Z","receivedAt":"2019-01-17T13:08:00Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 12 +++++++-----\n 1 file changed, 7 insertions(+), 5 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 07796d2b3c..69a4d55e38 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4903,6 +4903,12 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t  N_(\"synonym for '-p --raw'\"),\n \t\t\t  DIFF_FORMAT_PATCH | DIFF_FORMAT_RAW,\n \t\t\t  DIFF_FORMAT_NO_OUTPUT),\n+\t\tOPT_BIT_F(0, \"numstat\", &options->output_format,\n+\t\t\t  N_(\"machine friendly --stat\"),\n+\t\t\t  DIFF_FORMAT_NUMSTAT, PARSE_OPT_NONEG),\n+\t\tOPT_BIT_F(0, \"shortstat\", &options->output_format,\n+\t\t\t  N_(\"output only the last line of --stat\"),\n+\t\t\t  DIFF_FORMAT_SHORTSTAT, PARSE_OPT_NONEG),\n \t\tOPT_END()\n \t};\n \n@@ -4931,11 +4937,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* Output format options */\n-\tif (!strcmp(arg, \"--numstat\"))\n-\t\toptions->output_format |= DIFF_FORMAT_NUMSTAT;\n-\telse if (!strcmp(arg, \"--shortstat\"))\n-\t\toptions->output_format |= DIFF_FORMAT_SHORTSTAT;\n-\telse if (skip_prefix(arg, \"-X\", &arg) ||\n+\tif (skip_prefix(arg, \"-X\", &arg) ||\n \t\t skip_to_optional_arg(arg, \"--dirstat\", &arg))\n \t\treturn parse_dirstat_opt(options, arg);\n \telse if (!strcmp(arg, \"--cumulative\"))\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366929","messageId":"20190117130615.18732-19-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 18/76] diff.c: convert --dirstat and friends","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:17Z","receivedAt":"2019-01-17T13:08:06Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n Documentation/diff-options.txt |  7 ++++++\n diff.c                         | 39 +++++++++++++++++++++++++---------\n 2 files changed, 36 insertions(+), 10 deletions(-)\n\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex 0711734b12..058d93ec4f 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -148,6 +148,7 @@ These parameters can also be set individually with `--stat-width=<width>`,\n \tnumber of modified files, as well as number of added and deleted\n \tlines.\n \n+-X<param1,param2,...>::\n --dirstat[=<param1,param2,...>]::\n \tOutput the distribution of relative amount of changes for each\n \tsub-directory. The behavior of `--dirstat` can be customized by\n@@ -192,6 +193,12 @@ directories with less than 10% of the total amount of changed files,\n and accumulating child directory counts in the parent directories:\n `--dirstat=files,10,cumulative`.\n \n+--cumulative::\n+\tSynonym for --dirstat=cumulative\n+\n+--dirstat-by-file[=<param1,param2>...]::\n+\tSynonym for --dirstat=files,param1,param2...\n+\n --summary::\n \tOutput a condensed summary of extended header information\n \tsuch as creations, renames and mode changes.\ndiff --git a/diff.c b/diff.c\nindex 69a4d55e38..1cb410ed3a 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4865,6 +4865,22 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)\n \treturn 1;\n }\n \n+static int diff_opt_dirstat(const struct option *opt,\n+\t\t\t    const char *arg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\n+\tBUG_ON_OPT_NEG(unset);\n+\tif (!strcmp(opt->long_name, \"cumulative\")) {\n+\t\tif (arg)\n+\t\t\tBUG(\"how come --cumulative take a value?\");\n+\t\targ = \"cumulative\";\n+\t} else if (!strcmp(opt->long_name, \"dirstat-by-file\"))\n+\t\tparse_dirstat_opt(options, \"files\");\n+\tparse_dirstat_opt(options, arg ? arg : \"\");\n+\treturn 0;\n+}\n+\n static int diff_opt_unified(const struct option *opt,\n \t\t\t    const char *arg, int unset)\n {\n@@ -4909,6 +4925,18 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_BIT_F(0, \"shortstat\", &options->output_format,\n \t\t\t  N_(\"output only the last line of --stat\"),\n \t\t\t  DIFF_FORMAT_SHORTSTAT, PARSE_OPT_NONEG),\n+\t\tOPT_CALLBACK_F('X', \"dirstat\", options, N_(\"<param1,param2>...\"),\n+\t\t\t       N_(\"output the distribution of relative amount of changes for each sub-directory\"),\n+\t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n+\t\t\t       diff_opt_dirstat),\n+\t\tOPT_CALLBACK_F(0, \"cumulative\", options, NULL,\n+\t\t\t       N_(\"synonym for --dirstat=cumulative\"),\n+\t\t\t       PARSE_OPT_NONEG | PARSE_OPT_NOARG,\n+\t\t\t       diff_opt_dirstat),\n+\t\tOPT_CALLBACK_F(0, \"dirstat-by-file\", options, N_(\"<param1,param2>...\"),\n+\t\t\t       N_(\"synonym for --dirstat=files,param1,param2...\"),\n+\t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n+\t\t\t       diff_opt_dirstat),\n \t\tOPT_END()\n \t};\n \n@@ -4937,16 +4965,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* Output format options */\n-\tif (skip_prefix(arg, \"-X\", &arg) ||\n-\t\t skip_to_optional_arg(arg, \"--dirstat\", &arg))\n-\t\treturn parse_dirstat_opt(options, arg);\n-\telse if (!strcmp(arg, \"--cumulative\"))\n-\t\treturn parse_dirstat_opt(options, \"cumulative\");\n-\telse if (skip_to_optional_arg(arg, \"--dirstat-by-file\", &arg)) {\n-\t\tparse_dirstat_opt(options, \"files\");\n-\t\treturn parse_dirstat_opt(options, arg);\n-\t}\n-\telse if (!strcmp(arg, \"--check\"))\n+\tif (!strcmp(arg, \"--check\"))\n \t\toptions->output_format |= DIFF_FORMAT_CHECKDIFF;\n \telse if (!strcmp(arg, \"--summary\"))\n \t\toptions->output_format |= DIFF_FORMAT_SUMMARY;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366930","messageId":"20190117130615.18732-20-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 19/76] diff.c: convert --check","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:18Z","receivedAt":"2019-01-17T13:08:10Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 1cb410ed3a..07b495b686 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4937,6 +4937,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t       N_(\"synonym for --dirstat=files,param1,param2...\"),\n \t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n \t\t\t       diff_opt_dirstat),\n+\t\tOPT_BIT_F(0, \"check\", &options->output_format,\n+\t\t\t  N_(\"warn if changes introduce conflict markers or whitespace errors\"),\n+\t\t\t  DIFF_FORMAT_CHECKDIFF, PARSE_OPT_NONEG),\n \t\tOPT_END()\n \t};\n \n@@ -4965,9 +4968,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* Output format options */\n-\tif (!strcmp(arg, \"--check\"))\n-\t\toptions->output_format |= DIFF_FORMAT_CHECKDIFF;\n-\telse if (!strcmp(arg, \"--summary\"))\n+\tif (!strcmp(arg, \"--summary\"))\n \t\toptions->output_format |= DIFF_FORMAT_SUMMARY;\n \telse if (!strcmp(arg, \"--patch-with-stat\")) {\n \t\tenable_patch_output(&options->output_format);\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366931","messageId":"20190117130615.18732-21-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 20/76] diff.c: convert --summary","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:19Z","receivedAt":"2019-01-17T13:08:15Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 07b495b686..73fbe5b265 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4940,6 +4940,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_BIT_F(0, \"check\", &options->output_format,\n \t\t\t  N_(\"warn if changes introduce conflict markers or whitespace errors\"),\n \t\t\t  DIFF_FORMAT_CHECKDIFF, PARSE_OPT_NONEG),\n+\t\tOPT_BIT_F(0, \"summary\", &options->output_format,\n+\t\t\t  N_(\"condensed summary such as creations, renames and mode changes\"),\n+\t\t\t  DIFF_FORMAT_SUMMARY, PARSE_OPT_NONEG),\n \t\tOPT_END()\n \t};\n \n@@ -4968,9 +4971,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* Output format options */\n-\tif (!strcmp(arg, \"--summary\"))\n-\t\toptions->output_format |= DIFF_FORMAT_SUMMARY;\n-\telse if (!strcmp(arg, \"--patch-with-stat\")) {\n+\tif (!strcmp(arg, \"--patch-with-stat\")) {\n \t\tenable_patch_output(&options->output_format);\n \t\toptions->output_format |= DIFF_FORMAT_DIFFSTAT;\n \t} else if (!strcmp(arg, \"--name-only\"))\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366932","messageId":"20190117130615.18732-22-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 21/76] diff.c: convert --patch-with-stat","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:20Z","receivedAt":"2019-01-17T13:08:20Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 9 +++++----\n 1 file changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 73fbe5b265..2ab3d68d9c 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4919,6 +4919,10 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t  N_(\"synonym for '-p --raw'\"),\n \t\t\t  DIFF_FORMAT_PATCH | DIFF_FORMAT_RAW,\n \t\t\t  DIFF_FORMAT_NO_OUTPUT),\n+\t\tOPT_BITOP(0, \"patch-with-stat\", &options->output_format,\n+\t\t\t  N_(\"synonym for '-p --stat'\"),\n+\t\t\t  DIFF_FORMAT_PATCH | DIFF_FORMAT_DIFFSTAT,\n+\t\t\t  DIFF_FORMAT_NO_OUTPUT),\n \t\tOPT_BIT_F(0, \"numstat\", &options->output_format,\n \t\t\t  N_(\"machine friendly --stat\"),\n \t\t\t  DIFF_FORMAT_NUMSTAT, PARSE_OPT_NONEG),\n@@ -4971,10 +4975,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* Output format options */\n-\tif (!strcmp(arg, \"--patch-with-stat\")) {\n-\t\tenable_patch_output(&options->output_format);\n-\t\toptions->output_format |= DIFF_FORMAT_DIFFSTAT;\n-\t} else if (!strcmp(arg, \"--name-only\"))\n+\tif (!strcmp(arg, \"--name-only\"))\n \t\toptions->output_format |= DIFF_FORMAT_NAME;\n \telse if (!strcmp(arg, \"--name-status\"))\n \t\toptions->output_format |= DIFF_FORMAT_NAME_STATUS;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366933","messageId":"20190117130615.18732-23-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 22/76] diff.c: convert --name-only","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:21Z","receivedAt":"2019-01-17T13:08:24Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 2ab3d68d9c..056b766264 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4947,6 +4947,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_BIT_F(0, \"summary\", &options->output_format,\n \t\t\t  N_(\"condensed summary such as creations, renames and mode changes\"),\n \t\t\t  DIFF_FORMAT_SUMMARY, PARSE_OPT_NONEG),\n+\t\tOPT_BIT_F(0, \"name-only\", &options->output_format,\n+\t\t\t  N_(\"show only names of changed files\"),\n+\t\t\t  DIFF_FORMAT_NAME, PARSE_OPT_NONEG),\n \t\tOPT_END()\n \t};\n \n@@ -4975,9 +4978,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* Output format options */\n-\tif (!strcmp(arg, \"--name-only\"))\n-\t\toptions->output_format |= DIFF_FORMAT_NAME;\n-\telse if (!strcmp(arg, \"--name-status\"))\n+\tif (!strcmp(arg, \"--name-status\"))\n \t\toptions->output_format |= DIFF_FORMAT_NAME_STATUS;\n \telse if (!strcmp(arg, \"-s\") || !strcmp(arg, \"--no-patch\"))\n \t\toptions->output_format |= DIFF_FORMAT_NO_OUTPUT;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366934","messageId":"20190117130615.18732-24-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 23/76] diff.c: convert --name-status","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:22Z","receivedAt":"2019-01-17T13:08:30Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 056b766264..e685356e3e 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4950,6 +4950,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_BIT_F(0, \"name-only\", &options->output_format,\n \t\t\t  N_(\"show only names of changed files\"),\n \t\t\t  DIFF_FORMAT_NAME, PARSE_OPT_NONEG),\n+\t\tOPT_BIT_F(0, \"name-status\", &options->output_format,\n+\t\t\t  N_(\"show only names and status of changed files\"),\n+\t\t\t  DIFF_FORMAT_NAME_STATUS, PARSE_OPT_NONEG),\n \t\tOPT_END()\n \t};\n \n@@ -4978,9 +4981,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* Output format options */\n-\tif (!strcmp(arg, \"--name-status\"))\n-\t\toptions->output_format |= DIFF_FORMAT_NAME_STATUS;\n-\telse if (!strcmp(arg, \"-s\") || !strcmp(arg, \"--no-patch\"))\n+\tif (!strcmp(arg, \"-s\") || !strcmp(arg, \"--no-patch\"))\n \t\toptions->output_format |= DIFF_FORMAT_NO_OUTPUT;\n \telse if (starts_with(arg, \"--stat\"))\n \t\t/* --stat, --stat-width, --stat-name-width, or --stat-count */\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366935","messageId":"20190117130615.18732-25-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 24/76] diff.c: convert -s|--no-patch","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:23Z","receivedAt":"2019-01-17T13:08:34Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex e685356e3e..4398b30f47 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4904,6 +4904,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_BITOP('p', \"patch\", &options->output_format,\n \t\t\t  N_(\"generate patch\"),\n \t\t\t  DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT),\n+\t\tOPT_BIT_F('s', \"no-patch\", &options->output_format,\n+\t\t\t  N_(\"suppress diff output\"),\n+\t\t\t  DIFF_FORMAT_NO_OUTPUT, PARSE_OPT_NONEG),\n \t\tOPT_BITOP('u', NULL, &options->output_format,\n \t\t\t  N_(\"generate patch\"),\n \t\t\t  DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT),\n@@ -4981,9 +4984,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* Output format options */\n-\tif (!strcmp(arg, \"-s\") || !strcmp(arg, \"--no-patch\"))\n-\t\toptions->output_format |= DIFF_FORMAT_NO_OUTPUT;\n-\telse if (starts_with(arg, \"--stat\"))\n+\tif (starts_with(arg, \"--stat\"))\n \t\t/* --stat, --stat-width, --stat-name-width, or --stat-count */\n \t\treturn stat_opt(options, av);\n \telse if (!strcmp(arg, \"--compact-summary\")) {\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366936","messageId":"20190117130615.18732-26-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 25/76] diff.c: convert --stat*","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:24Z","receivedAt":"2019-01-17T13:08:39Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 113 ++++++++++++++++++++++++++-------------------------------\n 1 file changed, 52 insertions(+), 61 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 4398b30f47..1b01b36507 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4660,77 +4660,56 @@ int parse_long_opt(const char *opt, const char **argv,\n \treturn 2;\n }\n \n-static int stat_opt(struct diff_options *options, const char **av)\n+static int diff_opt_stat(const struct option *opt, const char *value, int unset)\n {\n-\tconst char *arg = av[0];\n-\tchar *end;\n+\tstruct diff_options *options = opt->value;\n \tint width = options->stat_width;\n \tint name_width = options->stat_name_width;\n \tint graph_width = options->stat_graph_width;\n \tint count = options->stat_count;\n-\tint argcount = 1;\n+\tchar *end;\n \n-\tif (!skip_prefix(arg, \"--stat\", &arg))\n-\t\tBUG(\"stat option does not begin with --stat: %s\", arg);\n-\tend = (char *)arg;\n+\tBUG_ON_OPT_NEG(unset);\n \n-\tswitch (*arg) {\n-\tcase '-':\n-\t\tif (skip_prefix(arg, \"-width\", &arg)) {\n-\t\t\tif (*arg == '=')\n-\t\t\t\twidth = strtoul(arg + 1, &end, 10);\n-\t\t\telse if (!*arg && !av[1])\n-\t\t\t\tdie_want_option(\"--stat-width\");\n-\t\t\telse if (!*arg) {\n-\t\t\t\twidth = strtoul(av[1], &end, 10);\n-\t\t\t\targcount = 2;\n-\t\t\t}\n-\t\t} else if (skip_prefix(arg, \"-name-width\", &arg)) {\n-\t\t\tif (*arg == '=')\n-\t\t\t\tname_width = strtoul(arg + 1, &end, 10);\n-\t\t\telse if (!*arg && !av[1])\n-\t\t\t\tdie_want_option(\"--stat-name-width\");\n-\t\t\telse if (!*arg) {\n-\t\t\t\tname_width = strtoul(av[1], &end, 10);\n-\t\t\t\targcount = 2;\n-\t\t\t}\n-\t\t} else if (skip_prefix(arg, \"-graph-width\", &arg)) {\n-\t\t\tif (*arg == '=')\n-\t\t\t\tgraph_width = strtoul(arg + 1, &end, 10);\n-\t\t\telse if (!*arg && !av[1])\n-\t\t\t\tdie_want_option(\"--stat-graph-width\");\n-\t\t\telse if (!*arg) {\n-\t\t\t\tgraph_width = strtoul(av[1], &end, 10);\n-\t\t\t\targcount = 2;\n-\t\t\t}\n-\t\t} else if (skip_prefix(arg, \"-count\", &arg)) {\n-\t\t\tif (*arg == '=')\n-\t\t\t\tcount = strtoul(arg + 1, &end, 10);\n-\t\t\telse if (!*arg && !av[1])\n-\t\t\t\tdie_want_option(\"--stat-count\");\n-\t\t\telse if (!*arg) {\n-\t\t\t\tcount = strtoul(av[1], &end, 10);\n-\t\t\t\targcount = 2;\n-\t\t\t}\n+\tif (!strcmp(opt->long_name, \"stat\")) {\n+\t\tif (value) {\n+\t\t\twidth = strtoul(value, &end, 10);\n+\t\t\tif (*end == ',')\n+\t\t\t\tname_width = strtoul(end+1, &end, 10);\n+\t\t\tif (*end == ',')\n+\t\t\t\tcount = strtoul(end+1, &end, 10);\n+\t\t\tif (*end)\n+\t\t\t\treturn error(_(\"invalid --stat value: %s\"), value);\n \t\t}\n-\t\tbreak;\n-\tcase '=':\n-\t\twidth = strtoul(arg+1, &end, 10);\n-\t\tif (*end == ',')\n-\t\t\tname_width = strtoul(end+1, &end, 10);\n-\t\tif (*end == ',')\n-\t\t\tcount = strtoul(end+1, &end, 10);\n-\t}\n+\t} else if (!strcmp(opt->long_name, \"stat-width\")) {\n+\t\twidth = strtoul(value, &end, 10);\n+\t\tif (*end)\n+\t\t\treturn error(_(\"%s expects a numerical value\"),\n+\t\t\t\t     opt->long_name);\n+\t} else if (!strcmp(opt->long_name, \"stat-name-width\")) {\n+\t\tname_width = strtoul(value, &end, 10);\n+\t\tif (*end)\n+\t\t\treturn error(_(\"%s expects a numerical value\"),\n+\t\t\t\t     opt->long_name);\n+\t} else if (!strcmp(opt->long_name, \"stat-graph-width\")) {\n+\t\tgraph_width = strtoul(value, &end, 10);\n+\t\tif (*end)\n+\t\t\treturn error(_(\"%s expects a numerical value\"),\n+\t\t\t\t     opt->long_name);\n+\t} else if (!strcmp(opt->long_name, \"stat-count\")) {\n+\t\tcount = strtoul(value, &end, 10);\n+\t\tif (*end)\n+\t\t\treturn error(_(\"%s expects a numerical value\"),\n+\t\t\t\t     opt->long_name);\n+\t} else\n+\t\tBUG(\"%s should not get here\", opt->long_name);\n \n-\t/* Important! This checks all the error cases! */\n-\tif (*end)\n-\t\treturn 0;\n \toptions->output_format |= DIFF_FORMAT_DIFFSTAT;\n \toptions->stat_name_width = name_width;\n \toptions->stat_graph_width = graph_width;\n \toptions->stat_width = width;\n \toptions->stat_count = count;\n-\treturn argcount;\n+\treturn 0;\n }\n \n static int parse_dirstat_opt(struct diff_options *options, const char *params)\n@@ -4956,6 +4935,21 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_BIT_F(0, \"name-status\", &options->output_format,\n \t\t\t  N_(\"show only names and status of changed files\"),\n \t\t\t  DIFF_FORMAT_NAME_STATUS, PARSE_OPT_NONEG),\n+\t\tOPT_CALLBACK_F(0, \"stat\", options, N_(\"<width>[,<name-width>[,<count>]]\"),\n+\t\t\t       N_(\"generate diffstat\"),\n+\t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG, diff_opt_stat),\n+\t\tOPT_CALLBACK_F(0, \"stat-width\", options, N_(\"<width>\"),\n+\t\t\t       N_(\"generate diffstat with a given width\"),\n+\t\t\t       PARSE_OPT_NONEG, diff_opt_stat),\n+\t\tOPT_CALLBACK_F(0, \"stat-name-width\", options, N_(\"<width>\"),\n+\t\t\t       N_(\"generate diffstat with a given name width\"),\n+\t\t\t       PARSE_OPT_NONEG, diff_opt_stat),\n+\t\tOPT_CALLBACK_F(0, \"stat-graph-width\", options, N_(\"<width>\"),\n+\t\t\t       N_(\"generate diffstat with a given graph width\"),\n+\t\t\t       PARSE_OPT_NONEG, diff_opt_stat),\n+\t\tOPT_CALLBACK_F(0, \"stat-count\", options, N_(\"<count>\"),\n+\t\t\t       N_(\"generate diffstat with limited lines\"),\n+\t\t\t       PARSE_OPT_NONEG, diff_opt_stat),\n \t\tOPT_END()\n \t};\n \n@@ -4984,10 +4978,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* Output format options */\n-\tif (starts_with(arg, \"--stat\"))\n-\t\t/* --stat, --stat-width, --stat-name-width, or --stat-count */\n-\t\treturn stat_opt(options, av);\n-\telse if (!strcmp(arg, \"--compact-summary\")) {\n+\tif (!strcmp(arg, \"--compact-summary\")) {\n \t\t options->flags.stat_with_summary = 1;\n \t\t options->output_format |= DIFF_FORMAT_DIFFSTAT;\n \t} else if (!strcmp(arg, \"--no-compact-summary\"))\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366937","messageId":"20190117130615.18732-27-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 26/76] diff.c: convert --[no-]compact-summary","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:25Z","receivedAt":"2019-01-17T13:08:44Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 25 +++++++++++++++++++------\n 1 file changed, 19 insertions(+), 6 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 1b01b36507..48659a10c0 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4844,6 +4844,21 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)\n \treturn 1;\n }\n \n+static int diff_opt_compact_summary(const struct option *opt,\n+\t\t\t\t    const char *arg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\n+\tBUG_ON_OPT_ARG(arg);\n+\tif (unset) {\n+\t\toptions->flags.stat_with_summary = 0;\n+\t} else {\n+\t\toptions->flags.stat_with_summary = 1;\n+\t\toptions->output_format |= DIFF_FORMAT_DIFFSTAT;\n+\t}\n+\treturn 0;\n+}\n+\n static int diff_opt_dirstat(const struct option *opt,\n \t\t\t    const char *arg, int unset)\n {\n@@ -4950,6 +4965,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_CALLBACK_F(0, \"stat-count\", options, N_(\"<count>\"),\n \t\t\t       N_(\"generate diffstat with limited lines\"),\n \t\t\t       PARSE_OPT_NONEG, diff_opt_stat),\n+\t\tOPT_CALLBACK_F(0, \"compact-summary\", options, NULL,\n+\t\t\t       N_(\"generate compact summary in diffstat\"),\n+\t\t\t       PARSE_OPT_NOARG, diff_opt_compact_summary),\n \t\tOPT_END()\n \t};\n \n@@ -4978,12 +4996,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* Output format options */\n-\tif (!strcmp(arg, \"--compact-summary\")) {\n-\t\t options->flags.stat_with_summary = 1;\n-\t\t options->output_format |= DIFF_FORMAT_DIFFSTAT;\n-\t} else if (!strcmp(arg, \"--no-compact-summary\"))\n-\t\t options->flags.stat_with_summary = 0;\n-\telse if (skip_prefix(arg, \"--output-indicator-new=\", &arg))\n+\tif (skip_prefix(arg, \"--output-indicator-new=\", &arg))\n \t\toptions->output_indicators[OUTPUT_INDICATOR_NEW] = arg[0];\n \telse if (skip_prefix(arg, \"--output-indicator-old=\", &arg))\n \t\toptions->output_indicators[OUTPUT_INDICATOR_OLD] = arg[0];\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366938","messageId":"20190117130615.18732-28-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 27/76] diff.c: convert --output-*","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:26Z","receivedAt":"2019-01-17T13:08:49Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This also validates that the user specifies a single character in\n--output-indicator-*, not a string.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n Documentation/diff-options.txt | 10 +++++\n diff.c                         | 71 +++++++++++++++++++++++++---------\n 2 files changed, 63 insertions(+), 18 deletions(-)\n\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex 058d93ec4f..d3e8d634b2 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -41,6 +41,16 @@ ifndef::git-format-patch[]\n \tImplies `-p`.\n endif::git-format-patch[]\n \n+--output=<file>::\n+\tOutput to a specific file instead of stdout.\n+\n+--output-indicator-new=<char>::\n+--output-indicator-old=<char>::\n+--output-indicator-context=<char>::\n+\tSpecify the character used to indicate new, old or context\n+\tlines in the generated patch. Normally they are '+', '-' and\n+\t' ' respectively.\n+\n ifndef::git-format-patch[]\n --raw::\n ifndef::git-log[]\ndiff --git a/diff.c b/diff.c\nindex 48659a10c0..c70de7f358 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4844,6 +4844,19 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)\n \treturn 1;\n }\n \n+static int diff_opt_char(const struct option *opt,\n+\t\t\t const char *arg, int unset)\n+{\n+\tchar *value = opt->value;\n+\n+\tBUG_ON_OPT_NEG(unset);\n+\tif (arg[1])\n+\t\treturn error(_(\"%s expects a character, got '%s'\"),\n+\t\t\t     opt->long_name, arg);\n+\t*value = arg[0];\n+\treturn 0;\n+}\n+\n static int diff_opt_compact_summary(const struct option *opt,\n \t\t\t\t    const char *arg, int unset)\n {\n@@ -4875,6 +4888,23 @@ static int diff_opt_dirstat(const struct option *opt,\n \treturn 0;\n }\n \n+static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,\n+\t\t\t\t\t     const struct option *opt,\n+\t\t\t\t\t     const char *arg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\tchar *path;\n+\n+\tBUG_ON_OPT_NEG(unset);\n+\tpath = prefix_filename(ctx->prefix, arg);\n+\toptions->file = xfopen(path, \"w\");\n+\toptions->close_file = 1;\n+\tif (options->use_color != GIT_COLOR_ALWAYS)\n+\t\toptions->use_color = GIT_COLOR_NEVER;\n+\tfree(path);\n+\treturn 0;\n+}\n+\n static int diff_opt_unified(const struct option *opt,\n \t\t\t    const char *arg, int unset)\n {\n@@ -4968,6 +4998,27 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_CALLBACK_F(0, \"compact-summary\", options, NULL,\n \t\t\t       N_(\"generate compact summary in diffstat\"),\n \t\t\t       PARSE_OPT_NOARG, diff_opt_compact_summary),\n+\t\tOPT_CALLBACK_F(0, \"output-indicator-new\",\n+\t\t\t       &options->output_indicators[OUTPUT_INDICATOR_NEW],\n+\t\t\t       N_(\"<char>\"),\n+\t\t\t       N_(\"specify the character to indicate a new line instead of '+'\"),\n+\t\t\t       PARSE_OPT_NONEG, diff_opt_char),\n+\t\tOPT_CALLBACK_F(0, \"output-indicator-old\",\n+\t\t\t       &options->output_indicators[OUTPUT_INDICATOR_OLD],\n+\t\t\t       N_(\"<char>\"),\n+\t\t\t       N_(\"specify the character to indicate an old line instead of '-'\"),\n+\t\t\t       PARSE_OPT_NONEG, diff_opt_char),\n+\t\tOPT_CALLBACK_F(0, \"output-indicator-context\",\n+\t\t\t       &options->output_indicators[OUTPUT_INDICATOR_CONTEXT],\n+\t\t\t       N_(\"<char>\"),\n+\t\t\t       N_(\"specify the character to indicate a context instead of ' '\"),\n+\t\t\t       PARSE_OPT_NONEG, diff_opt_char),\n+\n+\t\tOPT_GROUP(N_(\"Diff other options\")),\n+\t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n+\t\t  N_(\"Output to a specific file\"),\n+\t\t  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },\n+\n \t\tOPT_END()\n \t};\n \n@@ -4995,16 +5046,8 @@ int diff_opt_parse(struct diff_options *options,\n \tif (ac)\n \t\treturn ac;\n \n-\t/* Output format options */\n-\tif (skip_prefix(arg, \"--output-indicator-new=\", &arg))\n-\t\toptions->output_indicators[OUTPUT_INDICATOR_NEW] = arg[0];\n-\telse if (skip_prefix(arg, \"--output-indicator-old=\", &arg))\n-\t\toptions->output_indicators[OUTPUT_INDICATOR_OLD] = arg[0];\n-\telse if (skip_prefix(arg, \"--output-indicator-context=\", &arg))\n-\t\toptions->output_indicators[OUTPUT_INDICATOR_CONTEXT] = arg[0];\n-\n \t/* renames options */\n-\telse if (starts_with(arg, \"-B\") ||\n+\tif (starts_with(arg, \"-B\") ||\n \t\t skip_to_optional_arg(arg, \"--break-rewrites\", NULL)) {\n \t\tif ((options->break_opt = diff_scoreopt_parse(arg)) == -1)\n \t\t\treturn error(\"invalid argument to -B: %s\", arg+2);\n@@ -5245,15 +5288,7 @@ int diff_opt_parse(struct diff_options *options,\n \telse if (opt_arg(arg, '\\0', \"inter-hunk-context\",\n \t\t\t &options->interhunkcontext))\n \t\t;\n-\telse if ((argcount = parse_long_opt(\"output\", av, &optarg))) {\n-\t\tchar *path = prefix_filename(prefix, optarg);\n-\t\toptions->file = xfopen(path, \"w\");\n-\t\toptions->close_file = 1;\n-\t\tif (options->use_color != GIT_COLOR_ALWAYS)\n-\t\t\toptions->use_color = GIT_COLOR_NEVER;\n-\t\tfree(path);\n-\t\treturn argcount;\n-\t} else\n+\telse\n \t\treturn 0;\n \treturn 1;\n }\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366939","messageId":"20190117130615.18732-29-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 28/76] diff.c: convert -B|--break-rewrites","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:27Z","receivedAt":"2019-01-17T13:08:53Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 63 ++++++++++++++++++++++++++++++++++------------------------\n 1 file changed, 37 insertions(+), 26 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex c70de7f358..d4c378e836 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4844,6 +4844,31 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)\n \treturn 1;\n }\n \n+static int diff_opt_break_rewrites(const struct option *opt,\n+\t\t\t\t   const char *arg, int unset)\n+{\n+\tint *break_opt = opt->value;\n+\tint opt1, opt2;\n+\n+\tBUG_ON_OPT_NEG(unset);\n+\tif (!arg)\n+\t\targ = \"\";\n+\topt1 = parse_rename_score(&arg);\n+\tswitch (*arg) {\n+\tcase '\\0':\n+\t\topt2 = 0;\n+\t\tbreak;\n+\tcase '/':\n+\t\targ++;\n+\t\topt2 = parse_rename_score(&arg);\n+\t\tbreak;\n+\t}\n+\tif (*arg != 0)\n+\t\treturn error(_(\"%s expects <n>/<m> form\"), opt->long_name);\n+\t*break_opt = opt1 | (opt2 << 16);\n+\treturn 0;\n+}\n+\n static int diff_opt_char(const struct option *opt,\n \t\t\t const char *arg, int unset)\n {\n@@ -5014,6 +5039,12 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t       N_(\"specify the character to indicate a context instead of ' '\"),\n \t\t\t       PARSE_OPT_NONEG, diff_opt_char),\n \n+\t\tOPT_GROUP(N_(\"Diff rename options\")),\n+\t\tOPT_CALLBACK_F('B', \"break-rewrites\", &options->break_opt, N_(\"<n>[/<m>]\"),\n+\t\t\t       N_(\"break complete rewrite changes into pairs of delete and create\"),\n+\t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n+\t\t\t       diff_opt_break_rewrites),\n+\n \t\tOPT_GROUP(N_(\"Diff other options\")),\n \t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n \t\t  N_(\"Output to a specific file\"),\n@@ -5047,12 +5078,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* renames options */\n-\tif (starts_with(arg, \"-B\") ||\n-\t\t skip_to_optional_arg(arg, \"--break-rewrites\", NULL)) {\n-\t\tif ((options->break_opt = diff_scoreopt_parse(arg)) == -1)\n-\t\t\treturn error(\"invalid argument to -B: %s\", arg+2);\n-\t}\n-\telse if (starts_with(arg, \"-M\") ||\n+\tif (starts_with(arg, \"-M\") ||\n \t\t skip_to_optional_arg(arg, \"--find-renames\", NULL)) {\n \t\tif ((options->rename_score = diff_scoreopt_parse(arg)) == -1)\n \t\t\treturn error(\"invalid argument to -M: %s\", arg+2);\n@@ -5331,17 +5357,14 @@ int parse_rename_score(const char **cp_p)\n \n static int diff_scoreopt_parse(const char *opt)\n {\n-\tint opt1, opt2, cmd;\n+\tint opt1, cmd;\n \n \tif (*opt++ != '-')\n \t\treturn -1;\n \tcmd = *opt++;\n \tif (cmd == '-') {\n \t\t/* convert the long-form arguments into short-form versions */\n-\t\tif (skip_prefix(opt, \"break-rewrites\", &opt)) {\n-\t\t\tif (*opt == 0 || *opt++ == '=')\n-\t\t\t\tcmd = 'B';\n-\t\t} else if (skip_prefix(opt, \"find-copies\", &opt)) {\n+\t\tif (skip_prefix(opt, \"find-copies\", &opt)) {\n \t\t\tif (*opt == 0 || *opt++ == '=')\n \t\t\t\tcmd = 'C';\n \t\t} else if (skip_prefix(opt, \"find-renames\", &opt)) {\n@@ -5349,25 +5372,13 @@ static int diff_scoreopt_parse(const char *opt)\n \t\t\t\tcmd = 'M';\n \t\t}\n \t}\n-\tif (cmd != 'M' && cmd != 'C' && cmd != 'B')\n-\t\treturn -1; /* that is not a -M, -C, or -B option */\n+\tif (cmd != 'M' && cmd != 'C')\n+\t\treturn -1; /* that is not a -M, or -C option */\n \n \topt1 = parse_rename_score(&opt);\n-\tif (cmd != 'B')\n-\t\topt2 = 0;\n-\telse {\n-\t\tif (*opt == 0)\n-\t\t\topt2 = 0;\n-\t\telse if (*opt != '/')\n-\t\t\treturn -1; /* we expect -B80/99 or -B80 */\n-\t\telse {\n-\t\t\topt++;\n-\t\t\topt2 = parse_rename_score(&opt);\n-\t\t}\n-\t}\n \tif (*opt != 0)\n \t\treturn -1;\n-\treturn opt1 | (opt2 << 16);\n+\treturn opt1;\n }\n \n struct diff_queue_struct diff_queued_diff;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366940","messageId":"20190117130615.18732-30-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 29/76] diff.c: convert -M|--find-renames","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:28Z","receivedAt":"2019-01-17T13:08:59Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 35 +++++++++++++++++++++++------------\n 1 file changed, 23 insertions(+), 12 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex d4c378e836..6397d7a606 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4913,6 +4913,22 @@ static int diff_opt_dirstat(const struct option *opt,\n \treturn 0;\n }\n \n+static int diff_opt_find_renames(const struct option *opt,\n+\t\t\t\t const char *arg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\n+\tBUG_ON_OPT_NEG(unset);\n+\tif (!arg)\n+\t\targ = \"\";\n+\toptions->rename_score = parse_rename_score(&arg);\n+\tif (*arg != 0)\n+\t\treturn error(_(\"invalid argument to %s\"), opt->long_name);\n+\n+\toptions->detect_rename = DIFF_DETECT_RENAME;\n+\treturn 0;\n+}\n+\n static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,\n \t\t\t\t\t     const struct option *opt,\n \t\t\t\t\t     const char *arg, int unset)\n@@ -5044,6 +5060,10 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t       N_(\"break complete rewrite changes into pairs of delete and create\"),\n \t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n \t\t\t       diff_opt_break_rewrites),\n+\t\tOPT_CALLBACK_F('M', \"find-renames\", options, N_(\"<n>\"),\n+\t\t\t       N_(\"detect renames\"),\n+\t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n+\t\t\t       diff_opt_find_renames),\n \n \t\tOPT_GROUP(N_(\"Diff other options\")),\n \t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n@@ -5078,13 +5098,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* renames options */\n-\tif (starts_with(arg, \"-M\") ||\n-\t\t skip_to_optional_arg(arg, \"--find-renames\", NULL)) {\n-\t\tif ((options->rename_score = diff_scoreopt_parse(arg)) == -1)\n-\t\t\treturn error(\"invalid argument to -M: %s\", arg+2);\n-\t\toptions->detect_rename = DIFF_DETECT_RENAME;\n-\t}\n-\telse if (!strcmp(arg, \"-D\") || !strcmp(arg, \"--irreversible-delete\")) {\n+\tif (!strcmp(arg, \"-D\") || !strcmp(arg, \"--irreversible-delete\")) {\n \t\toptions->irreversible_delete = 1;\n \t}\n \telse if (starts_with(arg, \"-C\") ||\n@@ -5367,13 +5381,10 @@ static int diff_scoreopt_parse(const char *opt)\n \t\tif (skip_prefix(opt, \"find-copies\", &opt)) {\n \t\t\tif (*opt == 0 || *opt++ == '=')\n \t\t\t\tcmd = 'C';\n-\t\t} else if (skip_prefix(opt, \"find-renames\", &opt)) {\n-\t\t\tif (*opt == 0 || *opt++ == '=')\n-\t\t\t\tcmd = 'M';\n \t\t}\n \t}\n-\tif (cmd != 'M' && cmd != 'C')\n-\t\treturn -1; /* that is not a -M, or -C option */\n+\tif (cmd != 'C')\n+\t\treturn -1; /* that is not a -M option */\n \n \topt1 = parse_rename_score(&opt);\n \tif (*opt != 0)\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366941","messageId":"20190117130615.18732-31-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 30/76] diff.c: convert -D|--irreversible-delete","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:29Z","receivedAt":"2019-01-17T13:09:03Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 6397d7a606..e12b7ae101 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5064,6 +5064,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t       N_(\"detect renames\"),\n \t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n \t\t\t       diff_opt_find_renames),\n+\t\tOPT_SET_INT_F('D', \"irreversible-delete\", &options->irreversible_delete,\n+\t\t\t      N_(\"omit the preimage for deletes\"),\n+\t\t\t      1, PARSE_OPT_NONEG),\n \n \t\tOPT_GROUP(N_(\"Diff other options\")),\n \t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n@@ -5098,10 +5101,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* renames options */\n-\tif (!strcmp(arg, \"-D\") || !strcmp(arg, \"--irreversible-delete\")) {\n-\t\toptions->irreversible_delete = 1;\n-\t}\n-\telse if (starts_with(arg, \"-C\") ||\n+\tif (starts_with(arg, \"-C\") ||\n \t\t skip_to_optional_arg(arg, \"--find-copies\", NULL)) {\n \t\tif (options->detect_rename == DIFF_DETECT_COPY)\n \t\t\toptions->flags.find_copies_harder = 1;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366942","messageId":"20190117130615.18732-32-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 31/76] diff.c: convert -C|--find-copies","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:30Z","receivedAt":"2019-01-17T13:09:08Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 59 +++++++++++++++++++++++++---------------------------------\n 1 file changed, 25 insertions(+), 34 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex e12b7ae101..3b05e03284 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4621,8 +4621,6 @@ static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *va\n \treturn 1;\n }\n \n-static int diff_scoreopt_parse(const char *opt);\n-\n static inline int short_opt(char opt, const char **argv,\n \t\t\t    const char **optarg)\n {\n@@ -4913,6 +4911,26 @@ static int diff_opt_dirstat(const struct option *opt,\n \treturn 0;\n }\n \n+static int diff_opt_find_copies(const struct option *opt,\n+\t\t\t\tconst char *arg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\n+\tBUG_ON_OPT_NEG(unset);\n+\tif (!arg)\n+\t\targ = \"\";\n+\toptions->rename_score = parse_rename_score(&arg);\n+\tif (*arg != 0)\n+\t\treturn error(_(\"invalid argument to %s\"), opt->long_name);\n+\n+\tif (options->detect_rename == DIFF_DETECT_COPY)\n+\t\toptions->flags.find_copies_harder = 1;\n+\telse\n+\t\toptions->detect_rename = DIFF_DETECT_COPY;\n+\n+\treturn 0;\n+}\n+\n static int diff_opt_find_renames(const struct option *opt,\n \t\t\t\t const char *arg, int unset)\n {\n@@ -5067,6 +5085,10 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_SET_INT_F('D', \"irreversible-delete\", &options->irreversible_delete,\n \t\t\t      N_(\"omit the preimage for deletes\"),\n \t\t\t      1, PARSE_OPT_NONEG),\n+\t\tOPT_CALLBACK_F('C', \"find-copies\", options, N_(\"<n>\"),\n+\t\t\t       N_(\"detect copies\"),\n+\t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n+\t\t\t       diff_opt_find_copies),\n \n \t\tOPT_GROUP(N_(\"Diff other options\")),\n \t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n@@ -5101,15 +5123,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* renames options */\n-\tif (starts_with(arg, \"-C\") ||\n-\t\t skip_to_optional_arg(arg, \"--find-copies\", NULL)) {\n-\t\tif (options->detect_rename == DIFF_DETECT_COPY)\n-\t\t\toptions->flags.find_copies_harder = 1;\n-\t\tif ((options->rename_score = diff_scoreopt_parse(arg)) == -1)\n-\t\t\treturn error(\"invalid argument to -C: %s\", arg+2);\n-\t\toptions->detect_rename = DIFF_DETECT_COPY;\n-\t}\n-\telse if (!strcmp(arg, \"--no-renames\"))\n+\tif (!strcmp(arg, \"--no-renames\"))\n \t\toptions->detect_rename = 0;\n \telse if (!strcmp(arg, \"--rename-empty\"))\n \t\toptions->flags.rename_empty = 1;\n@@ -5369,29 +5383,6 @@ int parse_rename_score(const char **cp_p)\n \treturn (int)((num >= scale) ? MAX_SCORE : (MAX_SCORE * num / scale));\n }\n \n-static int diff_scoreopt_parse(const char *opt)\n-{\n-\tint opt1, cmd;\n-\n-\tif (*opt++ != '-')\n-\t\treturn -1;\n-\tcmd = *opt++;\n-\tif (cmd == '-') {\n-\t\t/* convert the long-form arguments into short-form versions */\n-\t\tif (skip_prefix(opt, \"find-copies\", &opt)) {\n-\t\t\tif (*opt == 0 || *opt++ == '=')\n-\t\t\t\tcmd = 'C';\n-\t\t}\n-\t}\n-\tif (cmd != 'C')\n-\t\treturn -1; /* that is not a -M option */\n-\n-\topt1 = parse_rename_score(&opt);\n-\tif (*opt != 0)\n-\t\treturn -1;\n-\treturn opt1;\n-}\n-\n struct diff_queue_struct diff_queued_diff;\n \n void diff_q(struct diff_queue_struct *queue, struct diff_filepair *dp)\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366943","messageId":"20190117130615.18732-33-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 32/76] diff.c: convert --find-copies-harder","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:31Z","receivedAt":"2019-01-17T13:09:13Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"--no-find-copies-harder is also added on purpose (because I don't see\nwhy we should not have the --no- version for this)\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 3b05e03284..0756612eb0 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5089,6 +5089,8 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t       N_(\"detect copies\"),\n \t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n \t\t\t       diff_opt_find_copies),\n+\t\tOPT_BOOL(0, \"find-copies-harder\", &options->flags.find_copies_harder,\n+\t\t\t N_(\"use unmodified files as source to find copies\")),\n \n \t\tOPT_GROUP(N_(\"Diff other options\")),\n \t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n@@ -5195,8 +5197,6 @@ int diff_opt_parse(struct diff_options *options,\n \t\toptions->flags.text = 1;\n \telse if (!strcmp(arg, \"-R\"))\n \t\toptions->flags.reverse_diff = 1;\n-\telse if (!strcmp(arg, \"--find-copies-harder\"))\n-\t\toptions->flags.find_copies_harder = 1;\n \telse if (!strcmp(arg, \"--follow\"))\n \t\toptions->flags.follow_renames = 1;\n \telse if (!strcmp(arg, \"--no-follow\")) {\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366944","messageId":"20190117130615.18732-34-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 33/76] diff.c: convert --no-renames|--[no--rename-empty","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:32Z","receivedAt":"2019-01-17T13:09:18Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"For --rename-empty, see 90d43b0768 (teach diffcore-rename to\noptionally ignore empty content - 2012-03-22) for more information.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n Documentation/diff-options.txt |  3 +++\n diff.c                         | 13 ++++++-------\n 2 files changed, 9 insertions(+), 7 deletions(-)\n\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex d3e8d634b2..4c0d40881b 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -392,6 +392,9 @@ endif::git-format-patch[]\n \tTurn off rename detection, even when the configuration\n \tfile gives the default to do so.\n \n+--[no-]rename-empty::\n+\tWhether to use empty blobs as rename source.\n+\n ifndef::git-format-patch[]\n --check::\n \tWarn if changes introduce conflict markers or whitespace errors.\ndiff --git a/diff.c b/diff.c\nindex 0756612eb0..fa666ced61 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5091,6 +5091,11 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t       diff_opt_find_copies),\n \t\tOPT_BOOL(0, \"find-copies-harder\", &options->flags.find_copies_harder,\n \t\t\t N_(\"use unmodified files as source to find copies\")),\n+\t\tOPT_SET_INT_F(0, \"no-renames\", &options->detect_rename,\n+\t\t\t      N_(\"disable rename detection\"),\n+\t\t\t      0, PARSE_OPT_NONEG),\n+\t\tOPT_BOOL(0, \"rename-empty\", &options->flags.rename_empty,\n+\t\t\t N_(\"use empty blobs as rename source\")),\n \n \t\tOPT_GROUP(N_(\"Diff other options\")),\n \t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n@@ -5125,13 +5130,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* renames options */\n-\tif (!strcmp(arg, \"--no-renames\"))\n-\t\toptions->detect_rename = 0;\n-\telse if (!strcmp(arg, \"--rename-empty\"))\n-\t\toptions->flags.rename_empty = 1;\n-\telse if (!strcmp(arg, \"--no-rename-empty\"))\n-\t\toptions->flags.rename_empty = 0;\n-\telse if (skip_to_optional_arg_default(arg, \"--relative\", &arg, NULL)) {\n+\tif (skip_to_optional_arg_default(arg, \"--relative\", &arg, NULL)) {\n \t\toptions->flags.relative_name = 1;\n \t\tif (arg)\n \t\t\toptions->prefix = arg;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366945","messageId":"20190117130615.18732-35-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 34/76] diff.c: convert --relative","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:33Z","receivedAt":"2019-01-17T13:09:22Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 25 +++++++++++++++++--------\n 1 file changed, 17 insertions(+), 8 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex fa666ced61..66a9f2ef48 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4964,6 +4964,18 @@ static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,\n \treturn 0;\n }\n \n+static int diff_opt_relative(const struct option *opt,\n+\t\t\t     const char *arg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\n+\tBUG_ON_OPT_NEG(unset);\n+\toptions->flags.relative_name = 1;\n+\tif (arg)\n+\t\toptions->prefix = arg;\n+\treturn 0;\n+}\n+\n static int diff_opt_unified(const struct option *opt,\n \t\t\t    const char *arg, int unset)\n {\n@@ -5098,6 +5110,10 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t N_(\"use empty blobs as rename source\")),\n \n \t\tOPT_GROUP(N_(\"Diff other options\")),\n+\t\tOPT_CALLBACK_F(0, \"relative\", options, N_(\"<prefix>\"),\n+\t\t\t       N_(\"when run from subdir, exclude changes outside and show relative paths\"),\n+\t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n+\t\t\t       diff_opt_relative),\n \t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n \t\t  N_(\"Output to a specific file\"),\n \t\t  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },\n@@ -5129,15 +5145,8 @@ int diff_opt_parse(struct diff_options *options,\n \tif (ac)\n \t\treturn ac;\n \n-\t/* renames options */\n-\tif (skip_to_optional_arg_default(arg, \"--relative\", &arg, NULL)) {\n-\t\toptions->flags.relative_name = 1;\n-\t\tif (arg)\n-\t\t\toptions->prefix = arg;\n-\t}\n-\n \t/* xdiff options */\n-\telse if (!strcmp(arg, \"--minimal\"))\n+\tif (!strcmp(arg, \"--minimal\"))\n \t\tDIFF_XDL_SET(options, NEED_MINIMAL);\n \telse if (!strcmp(arg, \"--no-minimal\"))\n \t\tDIFF_XDL_CLR(options, NEED_MINIMAL);\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366946","messageId":"20190117130615.18732-36-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 35/76] diff.c: convert --[no-]minimal","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:34Z","receivedAt":"2019-01-17T13:09:27Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 11 ++++++-----\n 1 file changed, 6 insertions(+), 5 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 66a9f2ef48..67b701d522 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5109,6 +5109,11 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_BOOL(0, \"rename-empty\", &options->flags.rename_empty,\n \t\t\t N_(\"use empty blobs as rename source\")),\n \n+\t\tOPT_GROUP(N_(\"Diff algorithm options\")),\n+\t\tOPT_BIT(0, \"minimal\", &options->xdl_opts,\n+\t\t\tN_(\"produce the smallest possible diff\"),\n+\t\t\tXDF_NEED_MINIMAL),\n+\n \t\tOPT_GROUP(N_(\"Diff other options\")),\n \t\tOPT_CALLBACK_F(0, \"relative\", options, N_(\"<prefix>\"),\n \t\t\t       N_(\"when run from subdir, exclude changes outside and show relative paths\"),\n@@ -5146,11 +5151,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* xdiff options */\n-\tif (!strcmp(arg, \"--minimal\"))\n-\t\tDIFF_XDL_SET(options, NEED_MINIMAL);\n-\telse if (!strcmp(arg, \"--no-minimal\"))\n-\t\tDIFF_XDL_CLR(options, NEED_MINIMAL);\n-\telse if (!strcmp(arg, \"-w\") || !strcmp(arg, \"--ignore-all-space\"))\n+\tif (!strcmp(arg, \"-w\") || !strcmp(arg, \"--ignore-all-space\"))\n \t\tDIFF_XDL_SET(options, IGNORE_WHITESPACE);\n \telse if (!strcmp(arg, \"-b\") || !strcmp(arg, \"--ignore-space-change\"))\n \t\tDIFF_XDL_SET(options, IGNORE_WHITESPACE_CHANGE);\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366947","messageId":"20190117130615.18732-37-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 36/76] diff.c: convert --ignore-some-changes","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:35Z","receivedAt":"2019-01-17T13:09:32Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 27 ++++++++++++++++-----------\n 1 file changed, 16 insertions(+), 11 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 67b701d522..d8b5c7b7d8 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5113,6 +5113,21 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_BIT(0, \"minimal\", &options->xdl_opts,\n \t\t\tN_(\"produce the smallest possible diff\"),\n \t\t\tXDF_NEED_MINIMAL),\n+\t\tOPT_BIT_F('w', \"ignore-all-space\", &options->xdl_opts,\n+\t\t\t  N_(\"ignore whitespace when comparing lines\"),\n+\t\t\t  XDF_IGNORE_WHITESPACE, PARSE_OPT_NONEG),\n+\t\tOPT_BIT_F('b', \"ignore-space-change\", &options->xdl_opts,\n+\t\t\t  N_(\"ignore changes in amount of whitespace\"),\n+\t\t\t  XDF_IGNORE_WHITESPACE_CHANGE, PARSE_OPT_NONEG),\n+\t\tOPT_BIT_F(0, \"ignore-space-at-eol\", &options->xdl_opts,\n+\t\t\t  N_(\"ignore changes in whitespace at EOL\"),\n+\t\t\t  XDF_IGNORE_WHITESPACE_AT_EOL, PARSE_OPT_NONEG),\n+\t\tOPT_BIT_F(0, \"ignore-cr-at-eol\", &options->xdl_opts,\n+\t\t\t  N_(\"ignore carrier-return at the end of line\"),\n+\t\t\t  XDF_IGNORE_CR_AT_EOL, PARSE_OPT_NONEG),\n+\t\tOPT_BIT_F(0, \"ignore-blank-lines\", &options->xdl_opts,\n+\t\t\t  N_(\"ignore changes whose lines are all blank\"),\n+\t\t\t  XDF_IGNORE_BLANK_LINES, PARSE_OPT_NONEG),\n \n \t\tOPT_GROUP(N_(\"Diff other options\")),\n \t\tOPT_CALLBACK_F(0, \"relative\", options, N_(\"<prefix>\"),\n@@ -5151,17 +5166,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* xdiff options */\n-\tif (!strcmp(arg, \"-w\") || !strcmp(arg, \"--ignore-all-space\"))\n-\t\tDIFF_XDL_SET(options, IGNORE_WHITESPACE);\n-\telse if (!strcmp(arg, \"-b\") || !strcmp(arg, \"--ignore-space-change\"))\n-\t\tDIFF_XDL_SET(options, IGNORE_WHITESPACE_CHANGE);\n-\telse if (!strcmp(arg, \"--ignore-space-at-eol\"))\n-\t\tDIFF_XDL_SET(options, IGNORE_WHITESPACE_AT_EOL);\n-\telse if (!strcmp(arg, \"--ignore-cr-at-eol\"))\n-\t\tDIFF_XDL_SET(options, IGNORE_CR_AT_EOL);\n-\telse if (!strcmp(arg, \"--ignore-blank-lines\"))\n-\t\tDIFF_XDL_SET(options, IGNORE_BLANK_LINES);\n-\telse if (!strcmp(arg, \"--indent-heuristic\"))\n+\tif (!strcmp(arg, \"--indent-heuristic\"))\n \t\tDIFF_XDL_SET(options, INDENT_HEURISTIC);\n \telse if (!strcmp(arg, \"--no-indent-heuristic\"))\n \t\tDIFF_XDL_CLR(options, INDENT_HEURISTIC);\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366948","messageId":"20190117130615.18732-38-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 37/76] diff.c: convert --[no-]indent-heuristic","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:36Z","receivedAt":"2019-01-17T13:09:37Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 9 ++++-----\n 1 file changed, 4 insertions(+), 5 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex d8b5c7b7d8..166ac8b6e5 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5128,6 +5128,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_BIT_F(0, \"ignore-blank-lines\", &options->xdl_opts,\n \t\t\t  N_(\"ignore changes whose lines are all blank\"),\n \t\t\t  XDF_IGNORE_BLANK_LINES, PARSE_OPT_NONEG),\n+\t\tOPT_BIT(0, \"indent-heuristic\", &options->xdl_opts,\n+\t\t\tN_(\"heuristic to shift diff hunk boundaries for easy reading\"),\n+\t\t\tXDF_INDENT_HEURISTIC),\n \n \t\tOPT_GROUP(N_(\"Diff other options\")),\n \t\tOPT_CALLBACK_F(0, \"relative\", options, N_(\"<prefix>\"),\n@@ -5166,11 +5169,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* xdiff options */\n-\tif (!strcmp(arg, \"--indent-heuristic\"))\n-\t\tDIFF_XDL_SET(options, INDENT_HEURISTIC);\n-\telse if (!strcmp(arg, \"--no-indent-heuristic\"))\n-\t\tDIFF_XDL_CLR(options, INDENT_HEURISTIC);\n-\telse if (!strcmp(arg, \"--patience\")) {\n+\tif (!strcmp(arg, \"--patience\")) {\n \t\tint i;\n \t\toptions->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);\n \t\t/*\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366949","messageId":"20190117130615.18732-39-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 38/76] diff.c: convert --patience","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:37Z","receivedAt":"2019-01-17T13:09:41Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 37 +++++++++++++++++++++++++------------\n 1 file changed, 25 insertions(+), 12 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 166ac8b6e5..67a88dcbd1 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4964,6 +4964,26 @@ static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,\n \treturn 0;\n }\n \n+static int diff_opt_patience(const struct option *opt,\n+\t\t\t     const char *arg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\tint i;\n+\n+\tBUG_ON_OPT_NEG(unset);\n+\tBUG_ON_OPT_ARG(arg);\n+\toptions->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);\n+\t/*\n+\t * Both --patience and --anchored use PATIENCE_DIFF\n+\t * internally, so remove any anchors previously\n+\t * specified.\n+\t */\n+\tfor (i = 0; i < options->anchors_nr; i++)\n+\t\tfree(options->anchors[i]);\n+\toptions->anchors_nr = 0;\n+\treturn 0;\n+}\n+\n static int diff_opt_relative(const struct option *opt,\n \t\t\t     const char *arg, int unset)\n {\n@@ -5131,6 +5151,10 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_BIT(0, \"indent-heuristic\", &options->xdl_opts,\n \t\t\tN_(\"heuristic to shift diff hunk boundaries for easy reading\"),\n \t\t\tXDF_INDENT_HEURISTIC),\n+\t\tOPT_CALLBACK_F(0, \"patience\", options, NULL,\n+\t\t\t       N_(\"generate diff using the \\\"patience diff\\\" algorithm\"),\n+\t\t\t       PARSE_OPT_NONEG | PARSE_OPT_NOARG,\n+\t\t\t       diff_opt_patience),\n \n \t\tOPT_GROUP(N_(\"Diff other options\")),\n \t\tOPT_CALLBACK_F(0, \"relative\", options, N_(\"<prefix>\"),\n@@ -5169,18 +5193,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* xdiff options */\n-\tif (!strcmp(arg, \"--patience\")) {\n-\t\tint i;\n-\t\toptions->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);\n-\t\t/*\n-\t\t * Both --patience and --anchored use PATIENCE_DIFF\n-\t\t * internally, so remove any anchors previously\n-\t\t * specified.\n-\t\t */\n-\t\tfor (i = 0; i < options->anchors_nr; i++)\n-\t\t\tfree(options->anchors[i]);\n-\t\toptions->anchors_nr = 0;\n-\t} else if (!strcmp(arg, \"--histogram\"))\n+\tif (!strcmp(arg, \"--histogram\"))\n \t\toptions->xdl_opts = DIFF_WITH_ALG(options, HISTOGRAM_DIFF);\n \telse if ((argcount = parse_long_opt(\"diff-algorithm\", av, &optarg))) {\n \t\tlong value = parse_algorithm_value(optarg);\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366950","messageId":"20190117130615.18732-40-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 39/76] diff.c: convert --histogram","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:38Z","receivedAt":"2019-01-17T13:09:47Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 67a88dcbd1..ca3f448a8d 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5155,6 +5155,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t       N_(\"generate diff using the \\\"patience diff\\\" algorithm\"),\n \t\t\t       PARSE_OPT_NONEG | PARSE_OPT_NOARG,\n \t\t\t       diff_opt_patience),\n+\t\tOPT_BITOP(0, \"histogram\", &options->xdl_opts,\n+\t\t\t  N_(\"generate diff using the \\\"histogram diff\\\" algorithm\"),\n+\t\t\t  XDF_HISTOGRAM_DIFF, XDF_DIFF_ALGORITHM_MASK),\n \n \t\tOPT_GROUP(N_(\"Diff other options\")),\n \t\tOPT_CALLBACK_F(0, \"relative\", options, N_(\"<prefix>\"),\n@@ -5193,9 +5196,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* xdiff options */\n-\tif (!strcmp(arg, \"--histogram\"))\n-\t\toptions->xdl_opts = DIFF_WITH_ALG(options, HISTOGRAM_DIFF);\n-\telse if ((argcount = parse_long_opt(\"diff-algorithm\", av, &optarg))) {\n+\tif ((argcount = parse_long_opt(\"diff-algorithm\", av, &optarg))) {\n \t\tlong value = parse_algorithm_value(optarg);\n \t\tif (value < 0)\n \t\t\treturn error(\"option diff-algorithm accepts \\\"myers\\\", \"\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366951","messageId":"20190117130615.18732-41-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 40/76] diff.c: convert --diff-algorithm","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:39Z","receivedAt":"2019-01-17T13:09:54Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 33 ++++++++++++++++++++++-----------\n 1 file changed, 22 insertions(+), 11 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex ca3f448a8d..2b93f08958 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4895,6 +4895,24 @@ static int diff_opt_compact_summary(const struct option *opt,\n \treturn 0;\n }\n \n+static int diff_opt_diff_algorithm(const struct option *opt,\n+\t\t\t\t   const char *arg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\tlong value = parse_algorithm_value(arg);\n+\n+\tBUG_ON_OPT_NEG(unset);\n+\tif (value < 0)\n+\t\treturn error(_(\"option diff-algorithm accepts \\\"myers\\\", \"\n+\t\t\t       \"\\\"minimal\\\", \\\"patience\\\" and \\\"histogram\\\"\"));\n+\n+\t/* clear out previous settings */\n+\tDIFF_XDL_CLR(options, NEED_MINIMAL);\n+\toptions->xdl_opts &= ~XDF_DIFF_ALGORITHM_MASK;\n+\toptions->xdl_opts |= value;\n+\treturn 0;\n+}\n+\n static int diff_opt_dirstat(const struct option *opt,\n \t\t\t    const char *arg, int unset)\n {\n@@ -5158,6 +5176,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_BITOP(0, \"histogram\", &options->xdl_opts,\n \t\t\t  N_(\"generate diff using the \\\"histogram diff\\\" algorithm\"),\n \t\t\t  XDF_HISTOGRAM_DIFF, XDF_DIFF_ALGORITHM_MASK),\n+\t\tOPT_CALLBACK_F(0, \"diff-algorithm\", options, N_(\"<algorithm>\"),\n+\t\t\t       N_(\"choose a diff algorithm\"),\n+\t\t\t       PARSE_OPT_NONEG, diff_opt_diff_algorithm),\n \n \t\tOPT_GROUP(N_(\"Diff other options\")),\n \t\tOPT_CALLBACK_F(0, \"relative\", options, N_(\"<prefix>\"),\n@@ -5196,17 +5217,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* xdiff options */\n-\tif ((argcount = parse_long_opt(\"diff-algorithm\", av, &optarg))) {\n-\t\tlong value = parse_algorithm_value(optarg);\n-\t\tif (value < 0)\n-\t\t\treturn error(\"option diff-algorithm accepts \\\"myers\\\", \"\n-\t\t\t\t     \"\\\"minimal\\\", \\\"patience\\\" and \\\"histogram\\\"\");\n-\t\t/* clear out previous settings */\n-\t\tDIFF_XDL_CLR(options, NEED_MINIMAL);\n-\t\toptions->xdl_opts &= ~XDF_DIFF_ALGORITHM_MASK;\n-\t\toptions->xdl_opts |= value;\n-\t\treturn argcount;\n-\t} else if (skip_prefix(arg, \"--anchored=\", &arg)) {\n+\tif (skip_prefix(arg, \"--anchored=\", &arg)) {\n \t\toptions->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);\n \t\tALLOC_GROW(options->anchors, options->anchors_nr + 1,\n \t\t\t   options->anchors_alloc);\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366952","messageId":"20190117130615.18732-42-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 41/76] diff.c: convert --anchored","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:40Z","receivedAt":"2019-01-17T13:09:58Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 26 +++++++++++++++++---------\n 1 file changed, 17 insertions(+), 9 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 2b93f08958..bee36fb276 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4842,6 +4842,19 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)\n \treturn 1;\n }\n \n+static int diff_opt_anchored(const struct option *opt,\n+\t\t\t     const char *arg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\n+\tBUG_ON_OPT_NEG(unset);\n+\toptions->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);\n+\tALLOC_GROW(options->anchors, options->anchors_nr + 1,\n+\t\t   options->anchors_alloc);\n+\toptions->anchors[options->anchors_nr++] = xstrdup(arg);\n+\treturn 0;\n+}\n+\n static int diff_opt_break_rewrites(const struct option *opt,\n \t\t\t\t   const char *arg, int unset)\n {\n@@ -5179,6 +5192,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_CALLBACK_F(0, \"diff-algorithm\", options, N_(\"<algorithm>\"),\n \t\t\t       N_(\"choose a diff algorithm\"),\n \t\t\t       PARSE_OPT_NONEG, diff_opt_diff_algorithm),\n+\t\tOPT_CALLBACK_F(0, \"anchored\", options, N_(\"<text>\"),\n+\t\t\t       N_(\"generate diff using the \\\"anchored diff\\\" algorithm\"),\n+\t\t\t       PARSE_OPT_NONEG, diff_opt_anchored),\n \n \t\tOPT_GROUP(N_(\"Diff other options\")),\n \t\tOPT_CALLBACK_F(0, \"relative\", options, N_(\"<prefix>\"),\n@@ -5216,16 +5232,8 @@ int diff_opt_parse(struct diff_options *options,\n \tif (ac)\n \t\treturn ac;\n \n-\t/* xdiff options */\n-\tif (skip_prefix(arg, \"--anchored=\", &arg)) {\n-\t\toptions->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);\n-\t\tALLOC_GROW(options->anchors, options->anchors_nr + 1,\n-\t\t\t   options->anchors_alloc);\n-\t\toptions->anchors[options->anchors_nr++] = xstrdup(arg);\n-\t}\n-\n \t/* flags options */\n-\telse if (!strcmp(arg, \"--binary\")) {\n+\tif (!strcmp(arg, \"--binary\")) {\n \t\tenable_patch_output(&options->output_format);\n \t\toptions->flags.binary = 1;\n \t}\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366953","messageId":"20190117130615.18732-43-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 42/76] diff.c: convert --binary","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:41Z","receivedAt":"2019-01-17T13:10:04Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n Documentation/diff-options.txt |  2 +-\n diff.c                         | 21 ++++++++++++++++-----\n 2 files changed, 17 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex 4c0d40881b..08edbff503 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -425,7 +425,7 @@ endif::git-format-patch[]\n \n --binary::\n \tIn addition to `--full-index`, output a binary diff that\n-\tcan be applied with `git-apply`.\n+\tcan be applied with `git-apply`. Implies `--patch`.\n \n --abbrev[=<n>]::\n \tInstead of showing the full 40-byte hexadecimal object\ndiff --git a/diff.c b/diff.c\nindex bee36fb276..0e93025af4 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4855,6 +4855,18 @@ static int diff_opt_anchored(const struct option *opt,\n \treturn 0;\n }\n \n+static int diff_opt_binary(const struct option *opt,\n+\t\t\t   const char *arg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\n+\tBUG_ON_OPT_NEG(unset);\n+\tBUG_ON_OPT_ARG(arg);\n+\tenable_patch_output(&options->output_format);\n+\toptions->flags.binary = 1;\n+\treturn 0;\n+}\n+\n static int diff_opt_break_rewrites(const struct option *opt,\n \t\t\t\t   const char *arg, int unset)\n {\n@@ -5120,6 +5132,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_CALLBACK_F(0, \"compact-summary\", options, NULL,\n \t\t\t       N_(\"generate compact summary in diffstat\"),\n \t\t\t       PARSE_OPT_NOARG, diff_opt_compact_summary),\n+\t\tOPT_CALLBACK_F(0, \"binary\", options, NULL,\n+\t\t\t       N_(\"output a binary diff that can be applied\"),\n+\t\t\t       PARSE_OPT_NONEG | PARSE_OPT_NOARG, diff_opt_binary),\n \t\tOPT_CALLBACK_F(0, \"output-indicator-new\",\n \t\t\t       &options->output_indicators[OUTPUT_INDICATOR_NEW],\n \t\t\t       N_(\"<char>\"),\n@@ -5233,11 +5248,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* flags options */\n-\tif (!strcmp(arg, \"--binary\")) {\n-\t\tenable_patch_output(&options->output_format);\n-\t\toptions->flags.binary = 1;\n-\t}\n-\telse if (!strcmp(arg, \"--full-index\"))\n+\tif (!strcmp(arg, \"--full-index\"))\n \t\toptions->flags.full_index = 1;\n \telse if (!strcmp(arg, \"-a\") || !strcmp(arg, \"--text\"))\n \t\toptions->flags.text = 1;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366954","messageId":"20190117130615.18732-44-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 43/76] diff.c: convert --full-index","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:42Z","receivedAt":"2019-01-17T13:10:07Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 0e93025af4..0b70def840 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5135,6 +5135,8 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_CALLBACK_F(0, \"binary\", options, NULL,\n \t\t\t       N_(\"output a binary diff that can be applied\"),\n \t\t\t       PARSE_OPT_NONEG | PARSE_OPT_NOARG, diff_opt_binary),\n+\t\tOPT_BOOL(0, \"full-index\", &options->flags.full_index,\n+\t\t\t N_(\"show full pre- and post-image object names on the \\\"index\\\" lines\")),\n \t\tOPT_CALLBACK_F(0, \"output-indicator-new\",\n \t\t\t       &options->output_indicators[OUTPUT_INDICATOR_NEW],\n \t\t\t       N_(\"<char>\"),\n@@ -5248,9 +5250,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* flags options */\n-\tif (!strcmp(arg, \"--full-index\"))\n-\t\toptions->flags.full_index = 1;\n-\telse if (!strcmp(arg, \"-a\") || !strcmp(arg, \"--text\"))\n+\tif (!strcmp(arg, \"-a\") || !strcmp(arg, \"--text\"))\n \t\toptions->flags.text = 1;\n \telse if (!strcmp(arg, \"-R\"))\n \t\toptions->flags.reverse_diff = 1;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366955","messageId":"20190117130615.18732-45-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 44/76] diff.c: convert -a|--text","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:43Z","receivedAt":"2019-01-17T13:10:12Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 0b70def840..d342d06399 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5218,6 +5218,8 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t       N_(\"when run from subdir, exclude changes outside and show relative paths\"),\n \t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n \t\t\t       diff_opt_relative),\n+\t\tOPT_BOOL('a', \"text\", &options->flags.text,\n+\t\t\t N_(\"treat all files as text\")),\n \t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n \t\t  N_(\"Output to a specific file\"),\n \t\t  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },\n@@ -5250,9 +5252,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* flags options */\n-\tif (!strcmp(arg, \"-a\") || !strcmp(arg, \"--text\"))\n-\t\toptions->flags.text = 1;\n-\telse if (!strcmp(arg, \"-R\"))\n+\tif (!strcmp(arg, \"-R\"))\n \t\toptions->flags.reverse_diff = 1;\n \telse if (!strcmp(arg, \"--follow\"))\n \t\toptions->flags.follow_renames = 1;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366956","messageId":"20190117130615.18732-46-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 45/76] diff.c: convert -R","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:44Z","receivedAt":"2019-01-17T13:10:17Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex d342d06399..13de6ea35c 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5220,6 +5220,8 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t       diff_opt_relative),\n \t\tOPT_BOOL('a', \"text\", &options->flags.text,\n \t\t\t N_(\"treat all files as text\")),\n+\t\tOPT_BOOL('R', NULL, &options->flags.reverse_diff,\n+\t\t\t N_(\"swap two inputs, reverse the diff\")),\n \t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n \t\t  N_(\"Output to a specific file\"),\n \t\t  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },\n@@ -5252,9 +5254,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* flags options */\n-\tif (!strcmp(arg, \"-R\"))\n-\t\toptions->flags.reverse_diff = 1;\n-\telse if (!strcmp(arg, \"--follow\"))\n+\tif (!strcmp(arg, \"--follow\"))\n \t\toptions->flags.follow_renames = 1;\n \telse if (!strcmp(arg, \"--no-follow\")) {\n \t\toptions->flags.follow_renames = 0;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366957","messageId":"20190117130615.18732-47-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 46/76] diff.c: convert --[no-]follow","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:45Z","receivedAt":"2019-01-17T13:10:22Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 25 +++++++++++++++++++------\n 1 file changed, 19 insertions(+), 6 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 13de6ea35c..13d9e5eb05 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4990,6 +4990,21 @@ static int diff_opt_find_renames(const struct option *opt,\n \treturn 0;\n }\n \n+static int diff_opt_follow(const struct option *opt,\n+\t\t\t   const char *arg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\n+\tBUG_ON_OPT_ARG(arg);\n+\tif (unset) {\n+\t\toptions->flags.follow_renames = 0;\n+\t\toptions->flags.default_follow_renames = 0;\n+\t} else {\n+\t\toptions->flags.follow_renames = 1;\n+\t}\n+\treturn 0;\n+}\n+\n static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,\n \t\t\t\t\t     const struct option *opt,\n \t\t\t\t\t     const char *arg, int unset)\n@@ -5176,6 +5191,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t      0, PARSE_OPT_NONEG),\n \t\tOPT_BOOL(0, \"rename-empty\", &options->flags.rename_empty,\n \t\t\t N_(\"use empty blobs as rename source\")),\n+\t\tOPT_CALLBACK_F(0, \"follow\", options, NULL,\n+\t\t\t       N_(\"continue listing the history of a file beyond renames\"),\n+\t\t\t       PARSE_OPT_NOARG, diff_opt_follow),\n \n \t\tOPT_GROUP(N_(\"Diff algorithm options\")),\n \t\tOPT_BIT(0, \"minimal\", &options->xdl_opts,\n@@ -5254,12 +5272,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* flags options */\n-\tif (!strcmp(arg, \"--follow\"))\n-\t\toptions->flags.follow_renames = 1;\n-\telse if (!strcmp(arg, \"--no-follow\")) {\n-\t\toptions->flags.follow_renames = 0;\n-\t\toptions->flags.default_follow_renames = 0;\n-\t} else if (skip_to_optional_arg_default(arg, \"--color\", &arg, \"always\")) {\n+\tif (skip_to_optional_arg_default(arg, \"--color\", &arg, \"always\")) {\n \t\tint value = git_config_colorbool(NULL, arg);\n \t\tif (value < 0)\n \t\t\treturn error(\"option `color' expects \\\"always\\\", \\\"auto\\\", or \\\"never\\\"\");\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366958","messageId":"20190117130615.18732-48-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 47/76] diff.c: convert --[no-]color","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:46Z","receivedAt":"2019-01-17T13:10:27Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 12 +++---------\n 1 file changed, 3 insertions(+), 9 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 13d9e5eb05..0c7a100f84 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5152,6 +5152,8 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t       PARSE_OPT_NONEG | PARSE_OPT_NOARG, diff_opt_binary),\n \t\tOPT_BOOL(0, \"full-index\", &options->flags.full_index,\n \t\t\t N_(\"show full pre- and post-image object names on the \\\"index\\\" lines\")),\n+\t\tOPT_COLOR_FLAG(0, \"color\", &options->use_color,\n+\t\t\t       N_(\"show colored diff\")),\n \t\tOPT_CALLBACK_F(0, \"output-indicator-new\",\n \t\t\t       &options->output_indicators[OUTPUT_INDICATOR_NEW],\n \t\t\t       N_(\"<char>\"),\n@@ -5272,15 +5274,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* flags options */\n-\tif (skip_to_optional_arg_default(arg, \"--color\", &arg, \"always\")) {\n-\t\tint value = git_config_colorbool(NULL, arg);\n-\t\tif (value < 0)\n-\t\t\treturn error(\"option `color' expects \\\"always\\\", \\\"auto\\\", or \\\"never\\\"\");\n-\t\toptions->use_color = value;\n-\t}\n-\telse if (!strcmp(arg, \"--no-color\"))\n-\t\toptions->use_color = 0;\n-\telse if (!strcmp(arg, \"--color-moved\")) {\n+\tif (!strcmp(arg, \"--color-moved\")) {\n \t\tif (diff_color_moved_default)\n \t\t\toptions->color_moved = diff_color_moved_default;\n \t\tif (options->color_moved == COLOR_MOVED_NO)\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366959","messageId":"20190117130615.18732-49-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 48/76] diff.c: convert --word-diff","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:47Z","receivedAt":"2019-01-17T13:10:31Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 47 +++++++++++++++++++++++++++++------------------\n 1 file changed, 29 insertions(+), 18 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 0c7a100f84..b80eefe9bc 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5070,6 +5070,32 @@ static int diff_opt_unified(const struct option *opt,\n \treturn 0;\n }\n \n+static int diff_opt_word_diff(const struct option *opt,\n+\t\t\t      const char *arg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\n+\tBUG_ON_OPT_NEG(unset);\n+\tif (arg) {\n+\t\tif (!strcmp(arg, \"plain\"))\n+\t\t\toptions->word_diff = DIFF_WORDS_PLAIN;\n+\t\telse if (!strcmp(arg, \"color\")) {\n+\t\t\toptions->use_color = 1;\n+\t\t\toptions->word_diff = DIFF_WORDS_COLOR;\n+\t\t}\n+\t\telse if (!strcmp(arg, \"porcelain\"))\n+\t\t\toptions->word_diff = DIFF_WORDS_PORCELAIN;\n+\t\telse if (!strcmp(arg, \"none\"))\n+\t\t\toptions->word_diff = DIFF_WORDS_NONE;\n+\t\telse\n+\t\t\treturn error(_(\"bad --word-diff argument: %s\"), arg);\n+\t} else {\n+\t\tif (options->word_diff == DIFF_WORDS_NONE)\n+\t\t\toptions->word_diff = DIFF_WORDS_PLAIN;\n+\t}\n+\treturn 0;\n+}\n+\n static void prep_parse_options(struct diff_options *options)\n {\n \tstruct option parseopts[] = {\n@@ -5232,6 +5258,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_CALLBACK_F(0, \"anchored\", options, N_(\"<text>\"),\n \t\t\t       N_(\"generate diff using the \\\"anchored diff\\\" algorithm\"),\n \t\t\t       PARSE_OPT_NONEG, diff_opt_anchored),\n+\t\tOPT_CALLBACK_F(0, \"word-diff\", options, N_(\"<mode>\"),\n+\t\t\t       N_(\"show word diff, using <mode> to delimit changed words\"),\n+\t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG, diff_opt_word_diff),\n \n \t\tOPT_GROUP(N_(\"Diff other options\")),\n \t\tOPT_CALLBACK_F(0, \"relative\", options, N_(\"<prefix>\"),\n@@ -5295,24 +5324,6 @@ int diff_opt_parse(struct diff_options *options,\n \t\toptions->use_color = 1;\n \t\toptions->word_diff = DIFF_WORDS_COLOR;\n \t}\n-\telse if (!strcmp(arg, \"--word-diff\")) {\n-\t\tif (options->word_diff == DIFF_WORDS_NONE)\n-\t\t\toptions->word_diff = DIFF_WORDS_PLAIN;\n-\t}\n-\telse if (skip_prefix(arg, \"--word-diff=\", &arg)) {\n-\t\tif (!strcmp(arg, \"plain\"))\n-\t\t\toptions->word_diff = DIFF_WORDS_PLAIN;\n-\t\telse if (!strcmp(arg, \"color\")) {\n-\t\t\toptions->use_color = 1;\n-\t\t\toptions->word_diff = DIFF_WORDS_COLOR;\n-\t\t}\n-\t\telse if (!strcmp(arg, \"porcelain\"))\n-\t\t\toptions->word_diff = DIFF_WORDS_PORCELAIN;\n-\t\telse if (!strcmp(arg, \"none\"))\n-\t\t\toptions->word_diff = DIFF_WORDS_NONE;\n-\t\telse\n-\t\t\tdie(\"bad --word-diff argument: %s\", arg);\n-\t}\n \telse if ((argcount = parse_long_opt(\"word-diff-regex\", av, &optarg))) {\n \t\tif (options->word_diff == DIFF_WORDS_NONE)\n \t\t\toptions->word_diff = DIFF_WORDS_PLAIN;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366960","messageId":"20190117130615.18732-50-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 49/76] diff.c: convert --word-diff-regex","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:48Z","receivedAt":"2019-01-17T13:10:36Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 21 +++++++++++++++------\n 1 file changed, 15 insertions(+), 6 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex b80eefe9bc..3e55c2fd1f 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5096,6 +5096,18 @@ static int diff_opt_word_diff(const struct option *opt,\n \treturn 0;\n }\n \n+static int diff_opt_word_diff_regex(const struct option *opt,\n+\t\t\t\t    const char *arg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\n+\tBUG_ON_OPT_NEG(unset);\n+\tif (options->word_diff == DIFF_WORDS_NONE)\n+\t\toptions->word_diff = DIFF_WORDS_PLAIN;\n+\toptions->word_regex = arg;\n+\treturn 0;\n+}\n+\n static void prep_parse_options(struct diff_options *options)\n {\n \tstruct option parseopts[] = {\n@@ -5261,6 +5273,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_CALLBACK_F(0, \"word-diff\", options, N_(\"<mode>\"),\n \t\t\t       N_(\"show word diff, using <mode> to delimit changed words\"),\n \t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG, diff_opt_word_diff),\n+\t\tOPT_CALLBACK_F(0, \"word-diff-regex\", options, N_(\"<regex>\"),\n+\t\t\t       N_(\"use <regex> to decide what a word is\"),\n+\t\t\t       PARSE_OPT_NONEG, diff_opt_word_diff_regex),\n \n \t\tOPT_GROUP(N_(\"Diff other options\")),\n \t\tOPT_CALLBACK_F(0, \"relative\", options, N_(\"<prefix>\"),\n@@ -5324,12 +5339,6 @@ int diff_opt_parse(struct diff_options *options,\n \t\toptions->use_color = 1;\n \t\toptions->word_diff = DIFF_WORDS_COLOR;\n \t}\n-\telse if ((argcount = parse_long_opt(\"word-diff-regex\", av, &optarg))) {\n-\t\tif (options->word_diff == DIFF_WORDS_NONE)\n-\t\t\toptions->word_diff = DIFF_WORDS_PLAIN;\n-\t\toptions->word_regex = optarg;\n-\t\treturn argcount;\n-\t}\n \telse if (!strcmp(arg, \"--exit-code\"))\n \t\toptions->flags.exit_with_status = 1;\n \telse if (!strcmp(arg, \"--quiet\"))\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366961","messageId":"20190117130615.18732-51-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 50/76] diff.c: convert --color-words","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:49Z","receivedAt":"2019-01-17T13:10:41Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 21 ++++++++++++++++-----\n 1 file changed, 16 insertions(+), 5 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 3e55c2fd1f..49cbf14417 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4905,6 +4905,18 @@ static int diff_opt_char(const struct option *opt,\n \treturn 0;\n }\n \n+static int diff_opt_color_words(const struct option *opt,\n+\t\t\t\tconst char *arg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\n+\tBUG_ON_OPT_NEG(unset);\n+\toptions->use_color = 1;\n+\toptions->word_diff = DIFF_WORDS_COLOR;\n+\toptions->word_regex = arg;\n+\treturn 0;\n+}\n+\n static int diff_opt_compact_summary(const struct option *opt,\n \t\t\t\t    const char *arg, int unset)\n {\n@@ -5276,6 +5288,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_CALLBACK_F(0, \"word-diff-regex\", options, N_(\"<regex>\"),\n \t\t\t       N_(\"use <regex> to decide what a word is\"),\n \t\t\t       PARSE_OPT_NONEG, diff_opt_word_diff_regex),\n+\t\tOPT_CALLBACK_F(0, \"color-words\", options, N_(\"<regex>\"),\n+\t\t\t       N_(\"equivalent to --word-diff=color --word-diff-regex=<regex>\"),\n+\t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG, diff_opt_color_words),\n \n \t\tOPT_GROUP(N_(\"Diff other options\")),\n \t\tOPT_CALLBACK_F(0, \"relative\", options, N_(\"<prefix>\"),\n@@ -5335,11 +5350,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\tif (cm & COLOR_MOVED_WS_ERROR)\n \t\t\treturn -1;\n \t\toptions->color_moved_ws_handling = cm;\n-\t} else if (skip_to_optional_arg_default(arg, \"--color-words\", &options->word_regex, NULL)) {\n-\t\toptions->use_color = 1;\n-\t\toptions->word_diff = DIFF_WORDS_COLOR;\n-\t}\n-\telse if (!strcmp(arg, \"--exit-code\"))\n+\t} else if (!strcmp(arg, \"--exit-code\"))\n \t\toptions->flags.exit_with_status = 1;\n \telse if (!strcmp(arg, \"--quiet\"))\n \t\toptions->flags.quick = 1;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366962","messageId":"20190117130615.18732-52-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 51/76] diff.c: convert --exit-code","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:50Z","receivedAt":"2019-01-17T13:10:46Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 49cbf14417..888a4a4975 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5301,6 +5301,8 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t N_(\"treat all files as text\")),\n \t\tOPT_BOOL('R', NULL, &options->flags.reverse_diff,\n \t\t\t N_(\"swap two inputs, reverse the diff\")),\n+\t\tOPT_BOOL(0, \"exit-code\", &options->flags.exit_with_status,\n+\t\t\t N_(\"exit with 1 if there were differences, 0 otherwise\")),\n \t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n \t\t  N_(\"Output to a specific file\"),\n \t\t  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },\n@@ -5350,9 +5352,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\tif (cm & COLOR_MOVED_WS_ERROR)\n \t\t\treturn -1;\n \t\toptions->color_moved_ws_handling = cm;\n-\t} else if (!strcmp(arg, \"--exit-code\"))\n-\t\toptions->flags.exit_with_status = 1;\n-\telse if (!strcmp(arg, \"--quiet\"))\n+\t} else if (!strcmp(arg, \"--quiet\"))\n \t\toptions->flags.quick = 1;\n \telse if (!strcmp(arg, \"--ext-diff\"))\n \t\toptions->flags.allow_external = 1;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366963","messageId":"20190117130615.18732-53-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 52/76] diff.c: convert --quiet","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:51Z","receivedAt":"2019-01-17T13:10:51Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 888a4a4975..eb81a95e89 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5303,6 +5303,8 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t N_(\"swap two inputs, reverse the diff\")),\n \t\tOPT_BOOL(0, \"exit-code\", &options->flags.exit_with_status,\n \t\t\t N_(\"exit with 1 if there were differences, 0 otherwise\")),\n+\t\tOPT_BOOL(0, \"quiet\", &options->flags.quick,\n+\t\t\t N_(\"disable all output of the program\")),\n \t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n \t\t  N_(\"Output to a specific file\"),\n \t\t  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },\n@@ -5352,9 +5354,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\tif (cm & COLOR_MOVED_WS_ERROR)\n \t\t\treturn -1;\n \t\toptions->color_moved_ws_handling = cm;\n-\t} else if (!strcmp(arg, \"--quiet\"))\n-\t\toptions->flags.quick = 1;\n-\telse if (!strcmp(arg, \"--ext-diff\"))\n+\t} else if (!strcmp(arg, \"--ext-diff\"))\n \t\toptions->flags.allow_external = 1;\n \telse if (!strcmp(arg, \"--no-ext-diff\"))\n \t\toptions->flags.allow_external = 0;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366964","messageId":"20190117130615.18732-54-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 53/76] diff.c: convert --ext-diff","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:52Z","receivedAt":"2019-01-17T13:10:56Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 8 +++-----\n 1 file changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex eb81a95e89..78b5d93fa5 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5305,6 +5305,8 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t N_(\"exit with 1 if there were differences, 0 otherwise\")),\n \t\tOPT_BOOL(0, \"quiet\", &options->flags.quick,\n \t\t\t N_(\"disable all output of the program\")),\n+\t\tOPT_BOOL(0, \"ext-diff\", &options->flags.allow_external,\n+\t\t\t N_(\"allow an external diff helper to be executed\")),\n \t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n \t\t  N_(\"Output to a specific file\"),\n \t\t  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },\n@@ -5354,11 +5356,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\tif (cm & COLOR_MOVED_WS_ERROR)\n \t\t\treturn -1;\n \t\toptions->color_moved_ws_handling = cm;\n-\t} else if (!strcmp(arg, \"--ext-diff\"))\n-\t\toptions->flags.allow_external = 1;\n-\telse if (!strcmp(arg, \"--no-ext-diff\"))\n-\t\toptions->flags.allow_external = 0;\n-\telse if (!strcmp(arg, \"--textconv\")) {\n+\t} else if (!strcmp(arg, \"--textconv\")) {\n \t\toptions->flags.allow_textconv = 1;\n \t\toptions->flags.textconv_set_via_cmdline = 1;\n \t} else if (!strcmp(arg, \"--no-textconv\"))\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366965","messageId":"20190117130615.18732-55-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 54/76] diff.c: convert --textconv","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:53Z","receivedAt":"2019-01-17T13:11:02Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 25 +++++++++++++++++++------\n 1 file changed, 19 insertions(+), 6 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 78b5d93fa5..611b73d06a 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5066,6 +5066,21 @@ static int diff_opt_relative(const struct option *opt,\n \treturn 0;\n }\n \n+static int diff_opt_textconv(const struct option *opt,\n+\t\t\t     const char *arg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\n+\tBUG_ON_OPT_ARG(arg);\n+\tif (unset) {\n+\t\toptions->flags.allow_textconv = 0;\n+\t} else {\n+\t\toptions->flags.allow_textconv = 1;\n+\t\toptions->flags.textconv_set_via_cmdline = 1;\n+\t}\n+\treturn 0;\n+}\n+\n static int diff_opt_unified(const struct option *opt,\n \t\t\t    const char *arg, int unset)\n {\n@@ -5307,6 +5322,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t N_(\"disable all output of the program\")),\n \t\tOPT_BOOL(0, \"ext-diff\", &options->flags.allow_external,\n \t\t\t N_(\"allow an external diff helper to be executed\")),\n+\t\tOPT_CALLBACK_F(0, \"textconv\", options, NULL,\n+\t\t\t       N_(\"run external text conversion filters when comparing binary files\"),\n+\t\t\t       PARSE_OPT_NOARG, diff_opt_textconv),\n \t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n \t\t  N_(\"Output to a specific file\"),\n \t\t  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },\n@@ -5356,12 +5374,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\tif (cm & COLOR_MOVED_WS_ERROR)\n \t\t\treturn -1;\n \t\toptions->color_moved_ws_handling = cm;\n-\t} else if (!strcmp(arg, \"--textconv\")) {\n-\t\toptions->flags.allow_textconv = 1;\n-\t\toptions->flags.textconv_set_via_cmdline = 1;\n-\t} else if (!strcmp(arg, \"--no-textconv\"))\n-\t\toptions->flags.allow_textconv = 0;\n-\telse if (skip_to_optional_arg_default(arg, \"--ignore-submodules\", &arg, \"all\")) {\n+\t} else if (skip_to_optional_arg_default(arg, \"--ignore-submodules\", &arg, \"all\")) {\n \t\toptions->flags.override_submodule_config = 1;\n \t\thandle_ignore_submodules_arg(options, arg);\n \t} else if (skip_to_optional_arg_default(arg, \"--submodule\", &arg, \"log\"))\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366966","messageId":"20190117130615.18732-56-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 55/76] diff.c: convert --ignore-submodules","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:54Z","receivedAt":"2019-01-17T13:11:06Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 20 +++++++++++++++++---\n 1 file changed, 17 insertions(+), 3 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 611b73d06a..bf7d2afcce 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5017,6 +5017,19 @@ static int diff_opt_follow(const struct option *opt,\n \treturn 0;\n }\n \n+static int diff_opt_ignore_submodules(const struct option *opt,\n+\t\t\t\t      const char *arg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\n+\tBUG_ON_OPT_NEG(unset);\n+\tif (!arg)\n+\t\targ = \"all\";\n+\toptions->flags.override_submodule_config = 1;\n+\thandle_ignore_submodules_arg(options, arg);\n+\treturn 0;\n+}\n+\n static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,\n \t\t\t\t\t     const struct option *opt,\n \t\t\t\t\t     const char *arg, int unset)\n@@ -5325,6 +5338,10 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_CALLBACK_F(0, \"textconv\", options, NULL,\n \t\t\t       N_(\"run external text conversion filters when comparing binary files\"),\n \t\t\t       PARSE_OPT_NOARG, diff_opt_textconv),\n+\t\tOPT_CALLBACK_F(0, \"ignore-submodules\", options, N_(\"<when>\"),\n+\t\t\t       N_(\"ignore changes to submodules in the diff generation\"),\n+\t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n+\t\t\t       diff_opt_ignore_submodules),\n \t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n \t\t  N_(\"Output to a specific file\"),\n \t\t  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },\n@@ -5374,9 +5391,6 @@ int diff_opt_parse(struct diff_options *options,\n \t\tif (cm & COLOR_MOVED_WS_ERROR)\n \t\t\treturn -1;\n \t\toptions->color_moved_ws_handling = cm;\n-\t} else if (skip_to_optional_arg_default(arg, \"--ignore-submodules\", &arg, \"all\")) {\n-\t\toptions->flags.override_submodule_config = 1;\n-\t\thandle_ignore_submodules_arg(options, arg);\n \t} else if (skip_to_optional_arg_default(arg, \"--submodule\", &arg, \"log\"))\n \t\treturn parse_submodule_opt(options, arg);\n \telse if (skip_prefix(arg, \"--ws-error-highlight=\", &arg))\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366967","messageId":"20190117130615.18732-57-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 56/76] diff.c: convert --submodule","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:55Z","receivedAt":"2019-01-17T13:11:10Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 30 +++++++++++++++++++-----------\n 1 file changed, 19 insertions(+), 11 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex bf7d2afcce..4d3eababe3 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4725,14 +4725,6 @@ static int parse_dirstat_opt(struct diff_options *options, const char *params)\n \treturn 1;\n }\n \n-static int parse_submodule_opt(struct diff_options *options, const char *value)\n-{\n-\tif (parse_submodule_params(options, value))\n-\t\tdie(_(\"Failed to parse --submodule option parameter: '%s'\"),\n-\t\t\tvalue);\n-\treturn 1;\n-}\n-\n static const char diff_status_letters[] = {\n \tDIFF_STATUS_ADDED,\n \tDIFF_STATUS_COPIED,\n@@ -5079,6 +5071,20 @@ static int diff_opt_relative(const struct option *opt,\n \treturn 0;\n }\n \n+static int diff_opt_submodule(const struct option *opt,\n+\t\t\t      const char *arg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\n+\tBUG_ON_OPT_NEG(unset);\n+\tif (!arg)\n+\t\targ = \"log\";\n+\tif (parse_submodule_params(options, arg))\n+\t\treturn error(_(\"failed to parse --submodule option parameter: '%s'\"),\n+\t\t\t     arg);\n+\treturn 0;\n+}\n+\n static int diff_opt_textconv(const struct option *opt,\n \t\t\t     const char *arg, int unset)\n {\n@@ -5342,6 +5348,10 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t       N_(\"ignore changes to submodules in the diff generation\"),\n \t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n \t\t\t       diff_opt_ignore_submodules),\n+\t\tOPT_CALLBACK_F(0, \"submodule\", options, N_(\"<format>\"),\n+\t\t\t       N_(\"specify how differences in submodules are shown\"),\n+\t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n+\t\t\t       diff_opt_submodule),\n \t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n \t\t  N_(\"Output to a specific file\"),\n \t\t  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },\n@@ -5391,9 +5401,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\tif (cm & COLOR_MOVED_WS_ERROR)\n \t\t\treturn -1;\n \t\toptions->color_moved_ws_handling = cm;\n-\t} else if (skip_to_optional_arg_default(arg, \"--submodule\", &arg, \"log\"))\n-\t\treturn parse_submodule_opt(options, arg);\n-\telse if (skip_prefix(arg, \"--ws-error-highlight=\", &arg))\n+\t} else if (skip_prefix(arg, \"--ws-error-highlight=\", &arg))\n \t\treturn parse_ws_error_highlight_opt(options, arg);\n \telse if (!strcmp(arg, \"--ita-invisible-in-index\"))\n \t\toptions->ita_invisible_in_index = 1;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366968","messageId":"20190117130615.18732-58-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 57/76] diff.c: convert --ws-error-highlight","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:56Z","receivedAt":"2019-01-17T13:11:15Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 22 ++++++++++++----------\n 1 file changed, 12 insertions(+), 10 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 4d3eababe3..c60cfc80a4 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4804,17 +4804,18 @@ static void enable_patch_output(int *fmt) {\n \t*fmt |= DIFF_FORMAT_PATCH;\n }\n \n-static int parse_ws_error_highlight_opt(struct diff_options *opt, const char *arg)\n+static int diff_opt_ws_error_highlight(const struct option *option,\n+\t\t\t\t       const char *arg, int unset)\n {\n+\tstruct diff_options *opt = option->value;\n \tint val = parse_ws_error_highlight(arg);\n \n-\tif (val < 0) {\n-\t\terror(\"unknown value after ws-error-highlight=%.*s\",\n-\t\t      -1 - val, arg);\n-\t\treturn 0;\n-\t}\n+\tBUG_ON_OPT_NEG(unset);\n+\tif (val < 0)\n+\t\treturn error(\"unknown value after ws-error-highlight=%.*s\",\n+\t\t\t     -1 - val, arg);\n \topt->ws_error_highlight = val;\n-\treturn 1;\n+\treturn 0;\n }\n \n static int parse_objfind_opt(struct diff_options *opt, const char *arg)\n@@ -5238,6 +5239,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t N_(\"show full pre- and post-image object names on the \\\"index\\\" lines\")),\n \t\tOPT_COLOR_FLAG(0, \"color\", &options->use_color,\n \t\t\t       N_(\"show colored diff\")),\n+\t\tOPT_CALLBACK_F(0, \"ws-error-highlight\", options, N_(\"<kind>\"),\n+\t\t\t       N_(\"highlight whitespaces errors in the context, old or new lines in the diff\"),\n+\t\t\t       PARSE_OPT_NONEG, diff_opt_ws_error_highlight),\n \t\tOPT_CALLBACK_F(0, \"output-indicator-new\",\n \t\t\t       &options->output_indicators[OUTPUT_INDICATOR_NEW],\n \t\t\t       N_(\"<char>\"),\n@@ -5401,9 +5405,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\tif (cm & COLOR_MOVED_WS_ERROR)\n \t\t\treturn -1;\n \t\toptions->color_moved_ws_handling = cm;\n-\t} else if (skip_prefix(arg, \"--ws-error-highlight=\", &arg))\n-\t\treturn parse_ws_error_highlight_opt(options, arg);\n-\telse if (!strcmp(arg, \"--ita-invisible-in-index\"))\n+\t} else if (!strcmp(arg, \"--ita-invisible-in-index\"))\n \t\toptions->ita_invisible_in_index = 1;\n \telse if (!strcmp(arg, \"--ita-visible-in-index\"))\n \t\toptions->ita_invisible_in_index = 0;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366969","messageId":"20190117130615.18732-59-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 58/76] diff.c: convert --ita-[in]visible-in-index","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:57Z","receivedAt":"2019-01-17T13:11:20Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 11 +++++++----\n 1 file changed, 7 insertions(+), 4 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex c60cfc80a4..0922937bab 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5356,6 +5356,12 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t       N_(\"specify how differences in submodules are shown\"),\n \t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n \t\t\t       diff_opt_submodule),\n+\t\tOPT_SET_INT_F(0, \"ita-invisible-in-index\", &options->ita_invisible_in_index,\n+\t\t\t      N_(\"hide 'git add -N' entries from the index\"),\n+\t\t\t      1, PARSE_OPT_NONEG),\n+\t\tOPT_SET_INT_F(0, \"ita-visible-in-index\", &options->ita_invisible_in_index,\n+\t\t\t      N_(\"treat 'git add -N' entries as real in the index\"),\n+\t\t\t      0, PARSE_OPT_NONEG),\n \t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n \t\t  N_(\"Output to a specific file\"),\n \t\t  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },\n@@ -5405,10 +5411,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\tif (cm & COLOR_MOVED_WS_ERROR)\n \t\t\treturn -1;\n \t\toptions->color_moved_ws_handling = cm;\n-\t} else if (!strcmp(arg, \"--ita-invisible-in-index\"))\n-\t\toptions->ita_invisible_in_index = 1;\n-\telse if (!strcmp(arg, \"--ita-visible-in-index\"))\n-\t\toptions->ita_invisible_in_index = 0;\n+\t}\n \n \t/* misc options */\n \telse if (!strcmp(arg, \"-z\"))\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366970","messageId":"20190117130615.18732-60-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 59/76] diff.c: convert -z","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:58Z","receivedAt":"2019-01-17T13:11:25Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 0922937bab..e4495194d3 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5242,6 +5242,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_CALLBACK_F(0, \"ws-error-highlight\", options, N_(\"<kind>\"),\n \t\t\t       N_(\"highlight whitespaces errors in the context, old or new lines in the diff\"),\n \t\t\t       PARSE_OPT_NONEG, diff_opt_ws_error_highlight),\n+\t\tOPT_SET_INT('z', NULL, &options->line_termination,\n+\t\t\t    N_(\"do not munge pathnames and use NULs as output field terminators in --raw or --numstat\"),\n+\t\t\t    0),\n \t\tOPT_CALLBACK_F(0, \"output-indicator-new\",\n \t\t\t       &options->output_indicators[OUTPUT_INDICATOR_NEW],\n \t\t\t       N_(\"<char>\"),\n@@ -5414,8 +5417,6 @@ int diff_opt_parse(struct diff_options *options,\n \t}\n \n \t/* misc options */\n-\telse if (!strcmp(arg, \"-z\"))\n-\t\toptions->line_termination = 0;\n \telse if ((argcount = short_opt('l', av, &optarg))) {\n \t\toptions->rename_limit = strtoul(optarg, NULL, 10);\n \t\treturn argcount;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366971","messageId":"20190117130615.18732-61-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 60/76] diff.c: convert -l","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:05:59Z","receivedAt":"2019-01-17T13:11:29Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 6 ++----\n 1 file changed, 2 insertions(+), 4 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex e4495194d3..00a56a25e0 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5287,6 +5287,8 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_CALLBACK_F(0, \"follow\", options, NULL,\n \t\t\t       N_(\"continue listing the history of a file beyond renames\"),\n \t\t\t       PARSE_OPT_NOARG, diff_opt_follow),\n+\t\tOPT_INTEGER('l', NULL, &options->rename_limit,\n+\t\t\t    N_(\"prevent rename/copy detection if the number of rename/copy targets exceeds given limit\")),\n \n \t\tOPT_GROUP(N_(\"Diff algorithm options\")),\n \t\tOPT_BIT(0, \"minimal\", &options->xdl_opts,\n@@ -5417,10 +5419,6 @@ int diff_opt_parse(struct diff_options *options,\n \t}\n \n \t/* misc options */\n-\telse if ((argcount = short_opt('l', av, &optarg))) {\n-\t\toptions->rename_limit = strtoul(optarg, NULL, 10);\n-\t\treturn argcount;\n-\t}\n \telse if ((argcount = short_opt('S', av, &optarg))) {\n \t\toptions->pickaxe = optarg;\n \t\toptions->pickaxe_opts |= DIFF_PICKAXE_KIND_S;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366972","messageId":"20190117130615.18732-62-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 61/76] diff.c: convert -S|-G","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:06:00Z","receivedAt":"2019-01-17T13:11:35Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 37 ++++++++++++++++++++++++++++---------\n 1 file changed, 28 insertions(+), 9 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 00a56a25e0..832a5bcd31 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5060,6 +5060,28 @@ static int diff_opt_patience(const struct option *opt,\n \treturn 0;\n }\n \n+static int diff_opt_pickaxe_regex(const struct option *opt,\n+\t\t\t\t  const char *arg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\n+\tBUG_ON_OPT_NEG(unset);\n+\toptions->pickaxe = arg;\n+\toptions->pickaxe_opts |= DIFF_PICKAXE_KIND_G;\n+\treturn 0;\n+}\n+\n+static int diff_opt_pickaxe_string(const struct option *opt,\n+\t\t\t\t   const char *arg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\n+\tBUG_ON_OPT_NEG(unset);\n+\toptions->pickaxe = arg;\n+\toptions->pickaxe_opts |= DIFF_PICKAXE_KIND_S;\n+\treturn 0;\n+}\n+\n static int diff_opt_relative(const struct option *opt,\n \t\t\t     const char *arg, int unset)\n {\n@@ -5367,6 +5389,12 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_SET_INT_F(0, \"ita-visible-in-index\", &options->ita_invisible_in_index,\n \t\t\t      N_(\"treat 'git add -N' entries as real in the index\"),\n \t\t\t      0, PARSE_OPT_NONEG),\n+\t\tOPT_CALLBACK_F('S', NULL, options, N_(\"<string>\"),\n+\t\t\t       N_(\"look for differences that change the number of occurrences of the specified string\"),\n+\t\t\t       0, diff_opt_pickaxe_string),\n+\t\tOPT_CALLBACK_F('G', NULL, options, N_(\"<regex>\"),\n+\t\t\t       N_(\"look for differences that change the number of occurrences of the specified regex\"),\n+\t\t\t       0, diff_opt_pickaxe_regex),\n \t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n \t\t  N_(\"Output to a specific file\"),\n \t\t  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },\n@@ -5419,15 +5447,6 @@ int diff_opt_parse(struct diff_options *options,\n \t}\n \n \t/* misc options */\n-\telse if ((argcount = short_opt('S', av, &optarg))) {\n-\t\toptions->pickaxe = optarg;\n-\t\toptions->pickaxe_opts |= DIFF_PICKAXE_KIND_S;\n-\t\treturn argcount;\n-\t} else if ((argcount = short_opt('G', av, &optarg))) {\n-\t\toptions->pickaxe = optarg;\n-\t\toptions->pickaxe_opts |= DIFF_PICKAXE_KIND_G;\n-\t\treturn argcount;\n-\t}\n \telse if (!strcmp(arg, \"--pickaxe-all\"))\n \t\toptions->pickaxe_opts |= DIFF_PICKAXE_ALL;\n \telse if (!strcmp(arg, \"--pickaxe-regex\"))\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366973","messageId":"20190117130615.18732-63-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 62/76] diff.c: convert --pickaxe-all|--pickaxe-regex","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:06:01Z","receivedAt":"2019-01-17T13:11:39Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 10 ++++++----\n 1 file changed, 6 insertions(+), 4 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 832a5bcd31..ae993f5551 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5395,6 +5395,12 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_CALLBACK_F('G', NULL, options, N_(\"<regex>\"),\n \t\t\t       N_(\"look for differences that change the number of occurrences of the specified regex\"),\n \t\t\t       0, diff_opt_pickaxe_regex),\n+\t\tOPT_BIT_F(0, \"pickaxe-all\", &options->pickaxe_opts,\n+\t\t\t  N_(\"show all changes in the changeset with -S or -G\"),\n+\t\t\t  DIFF_PICKAXE_ALL, PARSE_OPT_NONEG),\n+\t\tOPT_BIT_F(0, \"pickaxe-regex\", &options->pickaxe_opts,\n+\t\t\t  N_(\"treat <string> in -S as extended POSIX regular expression\"),\n+\t\t\t  DIFF_PICKAXE_REGEX, PARSE_OPT_NONEG),\n \t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n \t\t  N_(\"Output to a specific file\"),\n \t\t  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },\n@@ -5447,10 +5453,6 @@ int diff_opt_parse(struct diff_options *options,\n \t}\n \n \t/* misc options */\n-\telse if (!strcmp(arg, \"--pickaxe-all\"))\n-\t\toptions->pickaxe_opts |= DIFF_PICKAXE_ALL;\n-\telse if (!strcmp(arg, \"--pickaxe-regex\"))\n-\t\toptions->pickaxe_opts |= DIFF_PICKAXE_REGEX;\n \telse if ((argcount = short_opt('O', av, &optarg))) {\n \t\toptions->orderfile = prefix_filename(prefix, optarg);\n \t\treturn argcount;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366974","messageId":"20190117130615.18732-64-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 63/76] diff.c: convert -O","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:06:02Z","receivedAt":"2019-01-17T13:11:45Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 7 +++----\n 1 file changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex ae993f5551..4e004a2195 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5401,6 +5401,8 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_BIT_F(0, \"pickaxe-regex\", &options->pickaxe_opts,\n \t\t\t  N_(\"treat <string> in -S as extended POSIX regular expression\"),\n \t\t\t  DIFF_PICKAXE_REGEX, PARSE_OPT_NONEG),\n+\t\tOPT_FILENAME('O', NULL, &options->orderfile,\n+\t\t\t     N_(\"override diff.orderFile configuration variable\")),\n \t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n \t\t  N_(\"Output to a specific file\"),\n \t\t  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },\n@@ -5453,10 +5455,7 @@ int diff_opt_parse(struct diff_options *options,\n \t}\n \n \t/* misc options */\n-\telse if ((argcount = short_opt('O', av, &optarg))) {\n-\t\toptions->orderfile = prefix_filename(prefix, optarg);\n-\t\treturn argcount;\n-\t} else if (skip_prefix(arg, \"--find-object=\", &arg))\n+\telse if (skip_prefix(arg, \"--find-object=\", &arg))\n \t\treturn parse_objfind_opt(options, arg);\n \telse if ((argcount = parse_long_opt(\"diff-filter\", av, &optarg))) {\n \t\tint offending = parse_diff_filter_opt(optarg, options);\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366975","messageId":"20190117130615.18732-65-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 64/76] diff.c: convert --find-object","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:06:03Z","receivedAt":"2019-01-17T13:11:51Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 14 +++++++++-----\n 1 file changed, 9 insertions(+), 5 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 4e004a2195..2a943d47fd 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4818,12 +4818,15 @@ static int diff_opt_ws_error_highlight(const struct option *option,\n \treturn 0;\n }\n \n-static int parse_objfind_opt(struct diff_options *opt, const char *arg)\n+static int diff_opt_find_object(const struct option *option,\n+\t\t\t\tconst char *arg, int unset)\n {\n+\tstruct diff_options *opt = option->value;\n \tstruct object_id oid;\n \n+\tBUG_ON_OPT_NEG(unset);\n \tif (get_oid(arg, &oid))\n-\t\treturn error(\"unable to resolve '%s'\", arg);\n+\t\treturn error(_(\"unable to resolve '%s'\"), arg);\n \n \tif (!opt->objfind)\n \t\topt->objfind = xcalloc(1, sizeof(*opt->objfind));\n@@ -4832,7 +4835,7 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)\n \topt->flags.recursive = 1;\n \topt->flags.tree_in_recursive = 1;\n \toidset_insert(opt->objfind, &oid);\n-\treturn 1;\n+\treturn 0;\n }\n \n static int diff_opt_anchored(const struct option *opt,\n@@ -5403,6 +5406,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t  DIFF_PICKAXE_REGEX, PARSE_OPT_NONEG),\n \t\tOPT_FILENAME('O', NULL, &options->orderfile,\n \t\t\t     N_(\"override diff.orderFile configuration variable\")),\n+\t\tOPT_CALLBACK_F(0, \"find-object\", options, N_(\"<object-id>\"),\n+\t\t\t       N_(\"look for differences that change the number of occurrences of the specified object\"),\n+\t\t\t       PARSE_OPT_NONEG, diff_opt_find_object),\n \t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n \t\t  N_(\"Output to a specific file\"),\n \t\t  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },\n@@ -5455,8 +5461,6 @@ int diff_opt_parse(struct diff_options *options,\n \t}\n \n \t/* misc options */\n-\telse if (skip_prefix(arg, \"--find-object=\", &arg))\n-\t\treturn parse_objfind_opt(options, arg);\n \telse if ((argcount = parse_long_opt(\"diff-filter\", av, &optarg))) {\n \t\tint offending = parse_diff_filter_opt(optarg, options);\n \t\tif (offending)\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366976","messageId":"20190117130615.18732-66-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 65/76] diff.c: convert --diff-filter","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:06:04Z","receivedAt":"2019-01-17T13:11:56Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 18 +++++++++---------\n 1 file changed, 9 insertions(+), 9 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 2a943d47fd..fee45c5066 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4756,10 +4756,13 @@ static unsigned filter_bit_tst(char status, const struct diff_options *opt)\n \treturn opt->filter & filter_bit[(int) status];\n }\n \n-static int parse_diff_filter_opt(const char *optarg, struct diff_options *opt)\n+static int diff_opt_diff_filter(const struct option *option,\n+\t\t\t\tconst char *optarg, int unset)\n {\n+\tstruct diff_options *opt = option->value;\n \tint i, optch;\n \n+\tBUG_ON_OPT_NEG(unset);\n \tprepare_filter_bits();\n \n \t/*\n@@ -4790,7 +4793,8 @@ static int parse_diff_filter_opt(const char *optarg, struct diff_options *opt)\n \n \t\tbit = (0 <= optch && optch <= 'Z') ? filter_bit[optch] : 0;\n \t\tif (!bit)\n-\t\t\treturn optarg[i];\n+\t\t\treturn error(_(\"unknown change class '%c' in --diff-filter=%s\"),\n+\t\t\t\t     optarg[i], optarg);\n \t\tif (negate)\n \t\t\topt->filter &= ~bit;\n \t\telse\n@@ -5409,6 +5413,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_CALLBACK_F(0, \"find-object\", options, N_(\"<object-id>\"),\n \t\t\t       N_(\"look for differences that change the number of occurrences of the specified object\"),\n \t\t\t       PARSE_OPT_NONEG, diff_opt_find_object),\n+\t\tOPT_CALLBACK_F(0, \"diff-filter\", options, N_(\"[(A|C|D|M|R|T|U|X|B)...[*]]\"),\n+\t\t\t       N_(\"select files by diff type\"),\n+\t\t\t       PARSE_OPT_NONEG, diff_opt_diff_filter),\n \t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n \t\t  N_(\"Output to a specific file\"),\n \t\t  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },\n@@ -5461,13 +5468,6 @@ int diff_opt_parse(struct diff_options *options,\n \t}\n \n \t/* misc options */\n-\telse if ((argcount = parse_long_opt(\"diff-filter\", av, &optarg))) {\n-\t\tint offending = parse_diff_filter_opt(optarg, options);\n-\t\tif (offending)\n-\t\t\tdie(\"unknown change class '%c' in --diff-filter=%s\",\n-\t\t\t    offending, optarg);\n-\t\treturn argcount;\n-\t}\n \telse if (!strcmp(arg, \"--no-abbrev\"))\n \t\toptions->abbrev = 0;\n \telse if (!strcmp(arg, \"--abbrev\"))\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366977","messageId":"20190117130615.18732-67-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 66/76] diff.c: convert --[no-]abbrev","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:06:05Z","receivedAt":"2019-01-17T13:12:01Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c             | 12 +-----------\n parse-options-cb.c |  4 ++--\n 2 files changed, 3 insertions(+), 13 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex fee45c5066..f137b7f442 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5274,6 +5274,7 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_SET_INT('z', NULL, &options->line_termination,\n \t\t\t    N_(\"do not munge pathnames and use NULs as output field terminators in --raw or --numstat\"),\n \t\t\t    0),\n+\t\tOPT__ABBREV(&options->abbrev),\n \t\tOPT_CALLBACK_F(0, \"output-indicator-new\",\n \t\t\t       &options->output_indicators[OUTPUT_INDICATOR_NEW],\n \t\t\t       N_(\"<char>\"),\n@@ -5468,17 +5469,6 @@ int diff_opt_parse(struct diff_options *options,\n \t}\n \n \t/* misc options */\n-\telse if (!strcmp(arg, \"--no-abbrev\"))\n-\t\toptions->abbrev = 0;\n-\telse if (!strcmp(arg, \"--abbrev\"))\n-\t\toptions->abbrev = DEFAULT_ABBREV;\n-\telse if (skip_prefix(arg, \"--abbrev=\", &arg)) {\n-\t\toptions->abbrev = strtoul(arg, NULL, 10);\n-\t\tif (options->abbrev < MINIMUM_ABBREV)\n-\t\t\toptions->abbrev = MINIMUM_ABBREV;\n-\t\telse if (the_hash_algo->hexsz < options->abbrev)\n-\t\t\toptions->abbrev = the_hash_algo->hexsz;\n-\t}\n \telse if ((argcount = parse_long_opt(\"src-prefix\", av, &optarg))) {\n \t\toptions->a_prefix = optarg;\n \t\treturn argcount;\ndiff --git a/parse-options-cb.c b/parse-options-cb.c\nindex 2733393546..6e2e8d6273 100644\n--- a/parse-options-cb.c\n+++ b/parse-options-cb.c\n@@ -22,8 +22,8 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)\n \t\t\t\t     opt->long_name);\n \t\tif (v && v < MINIMUM_ABBREV)\n \t\t\tv = MINIMUM_ABBREV;\n-\t\telse if (v > 40)\n-\t\t\tv = 40;\n+\t\telse if (v > the_hash_algo->hexsz)\n+\t\t\tv = the_hash_algo->hexsz;\n \t}\n \t*(int *)(opt->value) = v;\n \treturn 0;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366978","messageId":"20190117130615.18732-68-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 67/76] diff.c: convert --[src|dst]-prefix","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:06:06Z","receivedAt":"2019-01-17T13:12:08Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c          | 14 ++++++--------\n parse-options.h |  3 ++-\n 2 files changed, 8 insertions(+), 9 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex f137b7f442..0d66497851 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5275,6 +5275,12 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t    N_(\"do not munge pathnames and use NULs as output field terminators in --raw or --numstat\"),\n \t\t\t    0),\n \t\tOPT__ABBREV(&options->abbrev),\n+\t\tOPT_STRING_F(0, \"src-prefix\", &options->a_prefix, N_(\"<prefix>\"),\n+\t\t\t     N_(\"show the given source prefix instead of \\\"a/\\\"\"),\n+\t\t\t     PARSE_OPT_NONEG),\n+\t\tOPT_STRING_F(0, \"dst-prefix\", &options->b_prefix, N_(\"<prefix>\"),\n+\t\t\t     N_(\"show the given source prefix instead of \\\"b/\\\"\"),\n+\t\t\t     PARSE_OPT_NONEG),\n \t\tOPT_CALLBACK_F(0, \"output-indicator-new\",\n \t\t\t       &options->output_indicators[OUTPUT_INDICATOR_NEW],\n \t\t\t       N_(\"<char>\"),\n@@ -5469,20 +5475,12 @@ int diff_opt_parse(struct diff_options *options,\n \t}\n \n \t/* misc options */\n-\telse if ((argcount = parse_long_opt(\"src-prefix\", av, &optarg))) {\n-\t\toptions->a_prefix = optarg;\n-\t\treturn argcount;\n-\t}\n \telse if ((argcount = parse_long_opt(\"line-prefix\", av, &optarg))) {\n \t\toptions->line_prefix = optarg;\n \t\toptions->line_prefix_length = strlen(options->line_prefix);\n \t\tgraph_setup_line_prefix(options);\n \t\treturn argcount;\n \t}\n-\telse if ((argcount = parse_long_opt(\"dst-prefix\", av, &optarg))) {\n-\t\toptions->b_prefix = optarg;\n-\t\treturn argcount;\n-\t}\n \telse if (!strcmp(arg, \"--no-prefix\"))\n \t\toptions->a_prefix = options->b_prefix = \"\";\n \telse if (opt_arg(arg, '\\0', \"inter-hunk-context\",\ndiff --git a/parse-options.h b/parse-options.h\nindex 7d83e2971d..c95cbe26f0 100644\n--- a/parse-options.h\n+++ b/parse-options.h\n@@ -136,6 +136,7 @@ struct option {\n #define OPT_BOOL_F(s, l, v, h, f)   OPT_SET_INT_F(s, l, v, h, 1, f)\n #define OPT_CALLBACK_F(s, l, v, a, h, f, cb)\t\t\t\\\n \t{ OPTION_CALLBACK, (s), (l), (v), (a), (h), (f), (cb) }\n+#define OPT_STRING_F(s, l, v, a, h, f)   { OPTION_STRING,  (s), (l), (v), (a), (h), (f) }\n \n #define OPT_END()                   { OPTION_END }\n #define OPT_ARGUMENT(l, h)          { OPTION_ARGUMENT, 0, (l), NULL, NULL, \\\n@@ -157,7 +158,7 @@ struct option {\n #define OPT_INTEGER(s, l, v, h)     { OPTION_INTEGER, (s), (l), (v), N_(\"n\"), (h) }\n #define OPT_MAGNITUDE(s, l, v, h)   { OPTION_MAGNITUDE, (s), (l), (v), \\\n \t\t\t\t      N_(\"n\"), (h), PARSE_OPT_NONEG }\n-#define OPT_STRING(s, l, v, a, h)   { OPTION_STRING,  (s), (l), (v), (a), (h) }\n+#define OPT_STRING(s, l, v, a, h)   OPT_STRING_F(s, l, v, a, h, 0)\n #define OPT_STRING_LIST(s, l, v, a, h) \\\n \t\t\t\t    { OPTION_CALLBACK, (s), (l), (v), (a), \\\n \t\t\t\t      (h), 0, &parse_opt_string_list }\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366979","messageId":"20190117130615.18732-69-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 68/76] diff.c: convert --line-prefix","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:06:07Z","receivedAt":"2019-01-17T13:12:11Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 23 +++++++++++++++--------\n 1 file changed, 15 insertions(+), 8 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 0d66497851..25c386b04c 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5030,6 +5030,18 @@ static int diff_opt_ignore_submodules(const struct option *opt,\n \treturn 0;\n }\n \n+static int diff_opt_line_prefix(const struct option *opt,\n+\t\t\t\tconst char *optarg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\n+\tBUG_ON_OPT_NEG(unset);\n+\toptions->line_prefix = optarg;\n+\toptions->line_prefix_length = strlen(options->line_prefix);\n+\tgraph_setup_line_prefix(options);\n+\treturn 0;\n+}\n+\n static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,\n \t\t\t\t\t     const struct option *opt,\n \t\t\t\t\t     const char *arg, int unset)\n@@ -5281,6 +5293,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_STRING_F(0, \"dst-prefix\", &options->b_prefix, N_(\"<prefix>\"),\n \t\t\t     N_(\"show the given source prefix instead of \\\"b/\\\"\"),\n \t\t\t     PARSE_OPT_NONEG),\n+\t\tOPT_CALLBACK_F(0, \"line-prefix\", options, N_(\"<prefix>\"),\n+\t\t\t       N_(\"prepend an additional prefix to every line of output\"),\n+\t\t\t       PARSE_OPT_NONEG, diff_opt_line_prefix),\n \t\tOPT_CALLBACK_F(0, \"output-indicator-new\",\n \t\t\t       &options->output_indicators[OUTPUT_INDICATOR_NEW],\n \t\t\t       N_(\"<char>\"),\n@@ -5438,8 +5453,6 @@ int diff_opt_parse(struct diff_options *options,\n \t\t   const char **av, int ac, const char *prefix)\n {\n \tconst char *arg = av[0];\n-\tconst char *optarg;\n-\tint argcount;\n \n \tif (!prefix)\n \t\tprefix = \"\";\n@@ -5475,12 +5488,6 @@ int diff_opt_parse(struct diff_options *options,\n \t}\n \n \t/* misc options */\n-\telse if ((argcount = parse_long_opt(\"line-prefix\", av, &optarg))) {\n-\t\toptions->line_prefix = optarg;\n-\t\toptions->line_prefix_length = strlen(options->line_prefix);\n-\t\tgraph_setup_line_prefix(options);\n-\t\treturn argcount;\n-\t}\n \telse if (!strcmp(arg, \"--no-prefix\"))\n \t\toptions->a_prefix = options->b_prefix = \"\";\n \telse if (opt_arg(arg, '\\0', \"inter-hunk-context\",\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366980","messageId":"20190117130615.18732-70-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 69/76] diff.c: convert --no-prefix","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:06:08Z","receivedAt":"2019-01-17T13:12:15Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 17 +++++++++++++++--\n 1 file changed, 15 insertions(+), 2 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 25c386b04c..3e7c36524d 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5042,6 +5042,18 @@ static int diff_opt_line_prefix(const struct option *opt,\n \treturn 0;\n }\n \n+static int diff_opt_no_prefix(const struct option *opt,\n+\t\t\t      const char *optarg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\n+\tBUG_ON_OPT_NEG(unset);\n+\tBUG_ON_OPT_ARG(optarg);\n+\toptions->a_prefix = \"\";\n+\toptions->b_prefix = \"\";\n+\treturn 0;\n+}\n+\n static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,\n \t\t\t\t\t     const struct option *opt,\n \t\t\t\t\t     const char *arg, int unset)\n@@ -5296,6 +5308,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_CALLBACK_F(0, \"line-prefix\", options, N_(\"<prefix>\"),\n \t\t\t       N_(\"prepend an additional prefix to every line of output\"),\n \t\t\t       PARSE_OPT_NONEG, diff_opt_line_prefix),\n+\t\tOPT_CALLBACK_F(0, \"no-prefix\", options, NULL,\n+\t\t\t       N_(\"no not show any source or destination prefix\"),\n+\t\t\t       PARSE_OPT_NONEG | PARSE_OPT_NOARG, diff_opt_no_prefix),\n \t\tOPT_CALLBACK_F(0, \"output-indicator-new\",\n \t\t\t       &options->output_indicators[OUTPUT_INDICATOR_NEW],\n \t\t\t       N_(\"<char>\"),\n@@ -5488,8 +5503,6 @@ int diff_opt_parse(struct diff_options *options,\n \t}\n \n \t/* misc options */\n-\telse if (!strcmp(arg, \"--no-prefix\"))\n-\t\toptions->a_prefix = options->b_prefix = \"\";\n \telse if (opt_arg(arg, '\\0', \"inter-hunk-context\",\n \t\t\t &options->interhunkcontext))\n \t\t;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366981","messageId":"20190117130615.18732-71-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 70/76] diff.c: convert --inter-hunk-context","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:06:09Z","receivedAt":"2019-01-17T13:12:20Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c          | 6 +++---\n parse-options.h | 3 ++-\n 2 files changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 3e7c36524d..cc10b27df0 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5311,6 +5311,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_CALLBACK_F(0, \"no-prefix\", options, NULL,\n \t\t\t       N_(\"no not show any source or destination prefix\"),\n \t\t\t       PARSE_OPT_NONEG | PARSE_OPT_NOARG, diff_opt_no_prefix),\n+\t\tOPT_INTEGER_F(0, \"inter-hunk-context\", &options->interhunkcontext,\n+\t\t\t      N_(\"show context between diff hunks up to the specified number of lines\"),\n+\t\t\t      PARSE_OPT_NONEG),\n \t\tOPT_CALLBACK_F(0, \"output-indicator-new\",\n \t\t\t       &options->output_indicators[OUTPUT_INDICATOR_NEW],\n \t\t\t       N_(\"<char>\"),\n@@ -5503,9 +5506,6 @@ int diff_opt_parse(struct diff_options *options,\n \t}\n \n \t/* misc options */\n-\telse if (opt_arg(arg, '\\0', \"inter-hunk-context\",\n-\t\t\t &options->interhunkcontext))\n-\t\t;\n \telse\n \t\treturn 0;\n \treturn 1;\ndiff --git a/parse-options.h b/parse-options.h\nindex c95cbe26f0..cca64d04cb 100644\n--- a/parse-options.h\n+++ b/parse-options.h\n@@ -137,6 +137,7 @@ struct option {\n #define OPT_CALLBACK_F(s, l, v, a, h, f, cb)\t\t\t\\\n \t{ OPTION_CALLBACK, (s), (l), (v), (a), (h), (f), (cb) }\n #define OPT_STRING_F(s, l, v, a, h, f)   { OPTION_STRING,  (s), (l), (v), (a), (h), (f) }\n+#define OPT_INTEGER_F(s, l, v, h, f)     { OPTION_INTEGER, (s), (l), (v), N_(\"n\"), (h), (f) }\n \n #define OPT_END()                   { OPTION_END }\n #define OPT_ARGUMENT(l, h)          { OPTION_ARGUMENT, 0, (l), NULL, NULL, \\\n@@ -155,7 +156,7 @@ struct option {\n \t\t\t\t      (h), PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1}\n #define OPT_CMDMODE(s, l, v, h, i)  { OPTION_CMDMODE, (s), (l), (v), NULL, \\\n \t\t\t\t      (h), PARSE_OPT_NOARG|PARSE_OPT_NONEG, NULL, (i) }\n-#define OPT_INTEGER(s, l, v, h)     { OPTION_INTEGER, (s), (l), (v), N_(\"n\"), (h) }\n+#define OPT_INTEGER(s, l, v, h)     OPT_INTEGER_F(s, l, v, h, 0)\n #define OPT_MAGNITUDE(s, l, v, h)   { OPTION_MAGNITUDE, (s), (l), (v), \\\n \t\t\t\t      N_(\"n\"), (h), PARSE_OPT_NONEG }\n #define OPT_STRING(s, l, v, a, h)   OPT_STRING_F(s, l, v, a, h, 0)\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366982","messageId":"20190117130615.18732-72-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 71/76] diff.c: convert --color-moved","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:06:10Z","receivedAt":"2019-01-17T13:12:25Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 38 +++++++++++++++++++++++++-------------\n 1 file changed, 25 insertions(+), 13 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex cc10b27df0..5403351466 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4905,6 +4905,27 @@ static int diff_opt_char(const struct option *opt,\n \treturn 0;\n }\n \n+static int diff_opt_color_moved(const struct option *opt,\n+\t\t\t\tconst char *arg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\n+\tif (unset) {\n+\t\toptions->color_moved = COLOR_MOVED_NO;\n+\t} else if (!arg) {\n+\t\tif (diff_color_moved_default)\n+\t\t\toptions->color_moved = diff_color_moved_default;\n+\t\tif (options->color_moved == COLOR_MOVED_NO)\n+\t\t\toptions->color_moved = COLOR_MOVED_DEFAULT;\n+\t} else {\n+\t\tint cm = parse_color_moved(arg);\n+\t\tif (cm < 0)\n+\t\t\treturn error(\"bad --color-moved argument: %s\", arg);\n+\t\toptions->color_moved = cm;\n+\t}\n+\treturn 0;\n+}\n+\n static int diff_opt_color_words(const struct option *opt,\n \t\t\t\tconst char *arg, int unset)\n {\n@@ -5403,6 +5424,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_CALLBACK_F(0, \"color-words\", options, N_(\"<regex>\"),\n \t\t\t       N_(\"equivalent to --word-diff=color --word-diff-regex=<regex>\"),\n \t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG, diff_opt_color_words),\n+\t\tOPT_CALLBACK_F(0, \"color-moved\", options, N_(\"<mode>\"),\n+\t\t\t       N_(\"move lines of code are colored differently\"),\n+\t\t\t       PARSE_OPT_OPTARG, diff_opt_color_moved),\n \n \t\tOPT_GROUP(N_(\"Diff other options\")),\n \t\tOPT_CALLBACK_F(0, \"relative\", options, N_(\"<prefix>\"),\n@@ -5486,19 +5510,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\treturn ac;\n \n \t/* flags options */\n-\tif (!strcmp(arg, \"--color-moved\")) {\n-\t\tif (diff_color_moved_default)\n-\t\t\toptions->color_moved = diff_color_moved_default;\n-\t\tif (options->color_moved == COLOR_MOVED_NO)\n-\t\t\toptions->color_moved = COLOR_MOVED_DEFAULT;\n-\t} else if (!strcmp(arg, \"--no-color-moved\"))\n-\t\toptions->color_moved = COLOR_MOVED_NO;\n-\telse if (skip_prefix(arg, \"--color-moved=\", &arg)) {\n-\t\tint cm = parse_color_moved(arg);\n-\t\tif (cm < 0)\n-\t\t\treturn error(\"bad --color-moved argument: %s\", arg);\n-\t\toptions->color_moved = cm;\n-\t} else if (skip_prefix(arg, \"--color-moved-ws=\", &arg)) {\n+\tif (skip_prefix(arg, \"--color-moved-ws=\", &arg)) {\n \t\tunsigned cm = parse_color_moved_ws(arg);\n \t\tif (cm & COLOR_MOVED_WS_ERROR)\n \t\t\treturn -1;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366983","messageId":"20190117130615.18732-73-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 72/76] diff.c: convert --color-moved-ws","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:06:11Z","receivedAt":"2019-01-17T13:12:30Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 35 ++++++++++++++++++-----------------\n 1 file changed, 18 insertions(+), 17 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 5403351466..e79a72cde9 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4926,6 +4926,20 @@ static int diff_opt_color_moved(const struct option *opt,\n \treturn 0;\n }\n \n+static int diff_opt_color_moved_ws(const struct option *opt,\n+\t\t\t\t   const char *arg, int unset)\n+{\n+\tstruct diff_options *options = opt->value;\n+\tunsigned cm;\n+\n+\tBUG_ON_OPT_NEG(unset);\n+\tcm = parse_color_moved_ws(arg);\n+\tif (cm & COLOR_MOVED_WS_ERROR)\n+\t\treturn error(_(\"invalid mode '%s' in --color-moved-ws\"), arg);\n+\toptions->color_moved_ws_handling = cm;\n+\treturn 0;\n+}\n+\n static int diff_opt_color_words(const struct option *opt,\n \t\t\t\tconst char *arg, int unset)\n {\n@@ -5427,6 +5441,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_CALLBACK_F(0, \"color-moved\", options, N_(\"<mode>\"),\n \t\t\t       N_(\"move lines of code are colored differently\"),\n \t\t\t       PARSE_OPT_OPTARG, diff_opt_color_moved),\n+\t\tOPT_CALLBACK_F(0, \"color-moved-ws\", options, N_(\"<mode>\"),\n+\t\t\t       N_(\"how white spaces are ignored in --color-moved\"),\n+\t\t\t       PARSE_OPT_NONEG, diff_opt_color_moved_ws),\n \n \t\tOPT_GROUP(N_(\"Diff other options\")),\n \t\tOPT_CALLBACK_F(0, \"relative\", options, N_(\"<prefix>\"),\n@@ -5494,8 +5511,6 @@ static void prep_parse_options(struct diff_options *options)\n int diff_opt_parse(struct diff_options *options,\n \t\t   const char **av, int ac, const char *prefix)\n {\n-\tconst char *arg = av[0];\n-\n \tif (!prefix)\n \t\tprefix = \"\";\n \n@@ -5506,21 +5521,7 @@ int diff_opt_parse(struct diff_options *options,\n \t\t\t   PARSE_OPT_ONE_SHOT |\n \t\t\t   PARSE_OPT_STOP_AT_NON_OPTION);\n \n-\tif (ac)\n-\t\treturn ac;\n-\n-\t/* flags options */\n-\tif (skip_prefix(arg, \"--color-moved-ws=\", &arg)) {\n-\t\tunsigned cm = parse_color_moved_ws(arg);\n-\t\tif (cm & COLOR_MOVED_WS_ERROR)\n-\t\t\treturn -1;\n-\t\toptions->color_moved_ws_handling = cm;\n-\t}\n-\n-\t/* misc options */\n-\telse\n-\t\treturn 0;\n-\treturn 1;\n+\treturn ac;\n }\n \n int parse_rename_score(const char **cp_p)\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366984","messageId":"20190117130615.18732-74-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 73/76] diff.c: allow --no-color-moved-ws","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:06:12Z","receivedAt":"2019-01-17T13:12:35Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This option is added in commit b73bcbac4a (diff: allow\n--no-color-moved-ws - 2018-11-23) in pw/diff-color-moved-ws-fix. To ease\nmerge conflict resolution, re-implement the option handling here so that\nthe conflict could be resolved by taking this side of change.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 8 ++++++--\n 1 file changed, 6 insertions(+), 2 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex e79a72cde9..daccc8226f 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4932,7 +4932,11 @@ static int diff_opt_color_moved_ws(const struct option *opt,\n \tstruct diff_options *options = opt->value;\n \tunsigned cm;\n \n-\tBUG_ON_OPT_NEG(unset);\n+\tif (unset) {\n+\t\toptions->color_moved_ws_handling = 0;\n+\t\treturn 0;\n+\t}\n+\n \tcm = parse_color_moved_ws(arg);\n \tif (cm & COLOR_MOVED_WS_ERROR)\n \t\treturn error(_(\"invalid mode '%s' in --color-moved-ws\"), arg);\n@@ -5443,7 +5447,7 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t       PARSE_OPT_OPTARG, diff_opt_color_moved),\n \t\tOPT_CALLBACK_F(0, \"color-moved-ws\", options, N_(\"<mode>\"),\n \t\t\t       N_(\"how white spaces are ignored in --color-moved\"),\n-\t\t\t       PARSE_OPT_NONEG, diff_opt_color_moved_ws),\n+\t\t\t       0, diff_opt_color_moved_ws),\n \n \t\tOPT_GROUP(N_(\"Diff other options\")),\n \t\tOPT_CALLBACK_F(0, \"relative\", options, N_(\"<prefix>\"),\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366985","messageId":"20190117130615.18732-75-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 74/76] range-diff: use parse_options() instead of diff_opt_parse()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:06:13Z","receivedAt":"2019-01-17T13:12:40Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Diff's internal option parsing is now done with 'struct option', which\nmakes it possible to combine all diff options to range-diff and parse\neverything all at once. Parsing code becomes simpler, and we get a\nlooong 'git range-diff -h'\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/range-diff.c | 26 ++++++--------------------\n 1 file changed, 6 insertions(+), 20 deletions(-)\n\ndiff --git a/builtin/range-diff.c b/builtin/range-diff.c\nindex f01a0be851..784bd19321 100644\n--- a/builtin/range-diff.c\n+++ b/builtin/range-diff.c\n@@ -16,42 +16,27 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)\n \tint creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT;\n \tstruct diff_options diffopt = { NULL };\n \tint simple_color = -1;\n-\tstruct option options[] = {\n+\tstruct option range_diff_options[] = {\n \t\tOPT_INTEGER(0, \"creation-factor\", &creation_factor,\n \t\t\t    N_(\"Percentage by which creation is weighted\")),\n \t\tOPT_BOOL(0, \"no-dual-color\", &simple_color,\n \t\t\t    N_(\"use simple diff colors\")),\n \t\tOPT_END()\n \t};\n-\tint i, j, res = 0;\n+\tstruct option *options;\n+\tint res = 0;\n \tstruct strbuf range1 = STRBUF_INIT, range2 = STRBUF_INIT;\n \n \tgit_config(git_diff_ui_config, NULL);\n \n \trepo_diff_setup(the_repository, &diffopt);\n \n+\toptions = parse_options_concat(range_diff_options, diffopt.parseopts);\n \targc = parse_options(argc, argv, NULL, options,\n-\t\t\t     builtin_range_diff_usage, PARSE_OPT_KEEP_UNKNOWN |\n-\t\t\t     PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0);\n-\n-\tfor (i = j = 1; i < argc && strcmp(\"--\", argv[i]); ) {\n-\t\tint c = diff_opt_parse(&diffopt, argv + i, argc - i, prefix);\n+\t\t\t     builtin_range_diff_usage, 0);\n \n-\t\tif (!c)\n-\t\t\targv[j++] = argv[i++];\n-\t\telse\n-\t\t\ti += c;\n-\t}\n-\twhile (i < argc)\n-\t\targv[j++] = argv[i++];\n-\targc = j;\n \tdiff_setup_done(&diffopt);\n \n-\t/* Make sure that there are no unparsed options */\n-\targc = parse_options(argc, argv, NULL,\n-\t\t\t     options + ARRAY_SIZE(options) - 1, /* OPT_END */\n-\t\t\t     builtin_range_diff_usage, 0);\n-\n \t/* force color when --dual-color was used */\n \tif (!simple_color)\n \t\tdiffopt.use_color = 1;\n@@ -90,6 +75,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)\n \t\terror(_(\"need two commit ranges\"));\n \t\tusage_with_options(builtin_range_diff_usage, options);\n \t}\n+\tFREE_AND_NULL(options);\n \n \tres = show_range_diff(range1.buf, range2.buf, creation_factor,\n \t\t\t      simple_color < 1, &diffopt);\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366986","messageId":"20190117130615.18732-76-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 75/76] diff --no-index: use parse_options() instead of diff_opt_parse()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:06:14Z","receivedAt":"2019-01-17T13:12:45Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"While at there, move exit() back to the caller. It's easier to see the\nflow that way than burying it in diff-no-index.c\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/diff.c           | 21 +++--------------\n diff-no-index.c          | 49 ++++++++++++++++++++++++----------------\n diff.h                   |  3 ++-\n t/t4053-diff-no-index.sh |  3 +--\n 4 files changed, 35 insertions(+), 41 deletions(-)\n\ndiff --git a/builtin/diff.c b/builtin/diff.c\nindex f0393bba23..52dc3e136f 100644\n--- a/builtin/diff.c\n+++ b/builtin/diff.c\n@@ -320,26 +320,11 @@ int cmd_diff(int argc, const char **argv, const char *prefix)\n \n \trepo_init_revisions(the_repository, &rev, prefix);\n \n-\tif (no_index && argc != i + 2) {\n-\t\tif (no_index == DIFF_NO_INDEX_IMPLICIT) {\n-\t\t\t/*\n-\t\t\t * There was no --no-index and there were not two\n-\t\t\t * paths. It is possible that the user intended\n-\t\t\t * to do an inside-repository operation.\n-\t\t\t */\n-\t\t\tfprintf(stderr, \"Not a git repository\\n\");\n-\t\t\tfprintf(stderr,\n-\t\t\t\t\"To compare two paths outside a working tree:\\n\");\n-\t\t}\n-\t\t/* Give the usage message for non-repository usage and exit. */\n-\t\tusagef(\"git diff %s <path> <path>\",\n-\t\t       no_index == DIFF_NO_INDEX_EXPLICIT ?\n-\t\t       \"--no-index\" : \"[--no-index]\");\n-\n-\t}\n \tif (no_index)\n \t\t/* If this is a no-index diff, just run it and exit there. */\n-\t\tdiff_no_index(the_repository, &rev, argc, argv);\n+\t\texit(diff_no_index(the_repository, &rev,\n+\t\t\t\t   no_index == DIFF_NO_INDEX_IMPLICIT,\n+\t\t\t\t   argc, argv));\n \n \t/* Otherwise, we are doing the usual \"git\" diff */\n \trev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;\ndiff --git a/diff-no-index.c b/diff-no-index.c\nindex 9414e922d1..a879f45862 100644\n--- a/diff-no-index.c\n+++ b/diff-no-index.c\n@@ -14,6 +14,7 @@\n #include \"revision.h\"\n #include \"log-tree.h\"\n #include \"builtin.h\"\n+#include \"parse-options.h\"\n #include \"string-list.h\"\n #include \"dir.h\"\n \n@@ -233,35 +234,43 @@ static void fixup_paths(const char **path, struct strbuf *replacement)\n \t}\n }\n \n-void diff_no_index(struct repository *r,\n-\t\t   struct rev_info *revs,\n-\t\t   int argc, const char **argv)\n+static const char * const diff_no_index_usage[] = {\n+\tN_(\"git diff --no-index [<options>] <path> <path>\"),\n+\tNULL\n+};\n+\n+int diff_no_index(struct repository *r,\n+\t\t  struct rev_info *revs,\n+\t\t  int implicit_no_index,\n+\t\t  int argc, const char **argv)\n {\n-\tint i;\n+\tint i, no_index;\n \tconst char *paths[2];\n \tstruct strbuf replacement = STRBUF_INIT;\n \tconst char *prefix = revs->prefix;\n+\tstruct option no_index_options[] = {\n+\t\tOPT_BOOL_F(0, \"no-index\", &no_index, \"\",\n+\t\t\t   PARSE_OPT_NONEG | PARSE_OPT_HIDDEN),\n+\t\tOPT_END(),\n+\t};\n+\tstruct option *options;\n \n \t/*\n \t * FIXME: --no-index should not look at index and we should be\n \t * able to pass NULL repo. Maybe later.\n \t */\n \trepo_diff_setup(r, &revs->diffopt);\n-\tfor (i = 1; i < argc - 2; ) {\n-\t\tint j;\n-\t\tif (!strcmp(argv[i], \"--no-index\"))\n-\t\t\ti++;\n-\t\telse if (!strcmp(argv[i], \"--\"))\n-\t\t\ti++;\n-\t\telse {\n-\t\t\tj = diff_opt_parse(&revs->diffopt, argv + i, argc - i,\n-\t\t\t\t\t   revs->prefix);\n-\t\t\tif (j <= 0)\n-\t\t\t\tdie(\"invalid diff option/value: %s\", argv[i]);\n-\t\t\ti += j;\n-\t\t}\n+\toptions = parse_options_concat(no_index_options,\n+\t\t\t\t       revs->diffopt.parseopts);\n+\targc = parse_options(argc, argv, revs->prefix, options,\n+\t\t\t     diff_no_index_usage, 0);\n+\tif (argc != 2) {\n+\t\tif (implicit_no_index)\n+\t\t\twarning(_(\"Not a git repository. Use --no-index to \"\n+\t\t\t\t  \"compare two paths outside a working tree\"));\n+\t\tusage_with_options(diff_no_index_usage, options);\n \t}\n-\n+\tFREE_AND_NULL(options);\n \tfor (i = 0; i < 2; i++) {\n \t\tconst char *p = argv[argc - 2 + i];\n \t\tif (!strcmp(p, \"-\"))\n@@ -293,7 +302,7 @@ void diff_no_index(struct repository *r,\n \trevs->diffopt.flags.exit_with_status = 1;\n \n \tif (queue_diff(&revs->diffopt, paths[0], paths[1]))\n-\t\texit(1);\n+\t\treturn 1;\n \tdiff_set_mnemonic_prefix(&revs->diffopt, \"1/\", \"2/\");\n \tdiffcore_std(&revs->diffopt);\n \tdiff_flush(&revs->diffopt);\n@@ -304,5 +313,5 @@ void diff_no_index(struct repository *r,\n \t * The return code for --no-index imitates diff(1):\n \t * 0 = no changes, 1 = changes, else error\n \t */\n-\texit(diff_result_code(&revs->diffopt, 0));\n+\treturn diff_result_code(&revs->diffopt, 0);\n }\ndiff --git a/diff.h b/diff.h\nindex d9ad73f0e1..03c6afda22 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -437,7 +437,8 @@ int diff_flush_patch_id(struct diff_options *, struct object_id *, int);\n \n int diff_result_code(struct diff_options *, int);\n \n-void diff_no_index(struct repository *, struct rev_info *, int, const char **);\n+int diff_no_index(struct repository *, struct rev_info *,\n+\t\t  int implicit_no_index, int, const char **);\n \n int index_differs_from(struct repository *r, const char *def,\n \t\t       const struct diff_flags *flags,\ndiff --git a/t/t4053-diff-no-index.sh b/t/t4053-diff-no-index.sh\nindex 6e0dd6f9e5..fb25cdb789 100755\n--- a/t/t4053-diff-no-index.sh\n+++ b/t/t4053-diff-no-index.sh\n@@ -50,8 +50,7 @@ test_expect_success 'git diff --no-index executed outside repo gives correct err\n \t\texport GIT_CEILING_DIRECTORIES &&\n \t\tcd non/git &&\n \t\ttest_must_fail git diff --no-index a 2>actual.err &&\n-\t\techo \"usage: git diff --no-index <path> <path>\" >expect.err &&\n-\t\ttest_cmp expect.err actual.err\n+\t\ttest_i18ngrep \"usage: git diff --no-index\" actual.err\n \t)\n '\n \n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366987","messageId":"20190117130615.18732-77-pclouds@gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"[PATCH 76/76] am: avoid diff_opt_parse()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-17T13:06:15Z","receivedAt":"2019-01-17T13:12:49Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"diff_opt_parse() is a heavy hammer to just set diff filter. But it's\nthe only way because of the diff_status_letters[] mapping. Add a new\nAPI to set diff filter and use it in git-am. diff_opt_parse()'s only\nremaining call site in revision.c will be gone soon and having it here\njust because of git-am does not make sense.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/am.c | 4 ++--\n diff.c       | 6 ++++++\n diff.h       | 2 ++\n 3 files changed, 10 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 95370313b6..0cbf285459 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -1515,11 +1515,11 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa\n \t\t * review them with extra care to spot mismerges.\n \t\t */\n \t\tstruct rev_info rev_info;\n-\t\tconst char *diff_filter_str = \"--diff-filter=AM\";\n \n \t\trepo_init_revisions(the_repository, &rev_info, NULL);\n \t\trev_info.diffopt.output_format = DIFF_FORMAT_NAME_STATUS;\n-\t\tdiff_opt_parse(&rev_info.diffopt, &diff_filter_str, 1, rev_info.prefix);\n+\t\trev_info.diffopt.filter |= diff_filter_bit('A');\n+\t\trev_info.diffopt.filter |= diff_filter_bit('M');\n \t\tadd_pending_oid(&rev_info, \"HEAD\", &our_tree, 0);\n \t\tdiff_setup_done(&rev_info.diffopt);\n \t\trun_diff_index(&rev_info, 1);\ndiff --git a/diff.c b/diff.c\nindex daccc8226f..b8e58e817b 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4756,6 +4756,12 @@ static unsigned filter_bit_tst(char status, const struct diff_options *opt)\n \treturn opt->filter & filter_bit[(int) status];\n }\n \n+unsigned diff_filter_bit(char status)\n+{\n+\tprepare_filter_bits();\n+\treturn filter_bit[(int) status];\n+}\n+\n static int diff_opt_diff_filter(const struct option *option,\n \t\t\t\tconst char *optarg, int unset)\n {\ndiff --git a/diff.h b/diff.h\nindex 03c6afda22..f88482705c 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -233,6 +233,8 @@ struct diff_options {\n \tstruct option *parseopts;\n };\n \n+unsigned diff_filter_bit(char status);\n+\n void diff_emit_submodule_del(struct diff_options *o, const char *line);\n void diff_emit_submodule_add(struct diff_options *o, const char *line);\n void diff_emit_submodule_untracked(struct diff_options *o, const char *path);\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366993","messageId":"87munz4ani.fsf@evledraar.gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-1-pclouds@gmail.com","subject":"Re: [PATCH 00/76] Convert diff opt parser to parse_options()","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2019-01-17T14:32:49Z","receivedAt":"2019-01-17T14:32:57Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Thu, Jan 17 2019, Nguyễn Thái Ngọc Duy wrote:\n\n> This series converts diff option parsing to using parse-options. There\n> are a couple benefits of using parse-options, including \"git <cmd> -h\"\n> output, completion and less duplicate work.\n>\n> This is the first half. The second one would be converting the option\n> parser in revision.c.  After that, the end game is, any command can\n> take a 'struct option[]' somewhere from diff/rev code, remove the\n> options they are not interested, then merge with their own options and\n> do parse_options() just once. There will be no separate parse phase\n> for revision/diff anymore.\n>\n> I sent a sneak peek [1] last year and got two good comments. I take it\n> people at least did not oppose to this. The most interesting parts are\n> at the top and bottom. The middle is just boring conversion, usually\n> one option per patch.\n\nI'm very much for this, and have skimmed it (but not stress tested) and\nit looks good to me. I have some WIP patches to --abbrev that conflict,\nbut which will be simpler as a result of this.\n"},{"id":"367007","messageId":"CAGZ79kZ0SvLs944z4N0r1rsJUpNaYyAdUv=L_kdvOJamxg0Riw@mail.gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-4-pclouds@gmail.com","subject":"Re: [PATCH 03/76] parse-options: allow keep-unknown + stop-at-non-opt combination","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2019-01-17T18:33:03Z","receivedAt":"2019-01-17T18:33:18Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Thu, Jan 17, 2019 at 5:06 AM Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:\n>\n> These two are orthogonal. One is about unknown _option_ while the\n> other non-option.\n\nThough 0d260f9a09 (\"parseopt: prevent KEEP_UNKNOWN and\nSTOP_AT_NON_OPTION from being used together\", 2009-03-09)\nseemed convincing to have this?\n\nMaybe we only need this BUG in case of !PARSE_OPT_ONE_SHOT?\n\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  parse-options.c | 3 ---\n>  1 file changed, 3 deletions(-)\n>\n> diff --git a/parse-options.c b/parse-options.c\n> index eb5de0da29..678b263897 100644\n> --- a/parse-options.c\n> +++ b/parse-options.c\n> @@ -427,9 +427,6 @@ void parse_options_start(struct parse_opt_ctx_t *ctx,\n>         ctx->prefix = prefix;\n>         ctx->cpidx = ((flags & PARSE_OPT_KEEP_ARGV0) != 0);\n>         ctx->flags = flags;\n> -       if ((flags & PARSE_OPT_KEEP_UNKNOWN) &&\n> -           (flags & PARSE_OPT_STOP_AT_NON_OPTION))\n> -               BUG(\"STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together\");\n>         if ((flags & PARSE_OPT_ONE_SHOT) &&\n>             (flags & PARSE_OPT_KEEP_ARGV0))\n>                 BUG(\"Can't keep argv0 if you don't have it\");\n> --\n> 2.20.0.482.g66447595a7\n>\n"},{"id":"367014","messageId":"CAGZ79kaAf7NytateigG_f6-UbeJKa2bno9+4zC7R4uqfFB77FA@mail.gmail.com","threadId":"50247","inReplyTo":"20190117130615.18732-75-pclouds@gmail.com","subject":"Re: [PATCH 74/76] range-diff: use parse_options() instead of diff_opt_parse()","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2019-01-17T19:46:46Z","receivedAt":"2019-01-17T19:47:01Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Thu, Jan 17, 2019 at 5:12 AM Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:\n>\n> Diff's internal option parsing is now done with 'struct option', which\n> makes it possible to combine all diff options to range-diff and parse\n> everything all at once. Parsing code becomes simpler,\n\nCool. I like the series up to here.\n\nI skipped most of the conversion\npatches, but looked at some and they seem to be very regularly\nconstructed, as a later step we might want to move all the diff parsing\nout of diff.c into diff-options.{c,h,} or such.\n\n> and we get a\n> looong 'git range-diff -h'\n\nThis is an interesting tidbit to put into the commit message.\n\nrange-diff is interesting in that in it is unclear where the options\nshould take effect. My mental model of range-diff is\n\n    diff --inner-options-1 <range1> >tmp1\n    diff --inner-options-2 <range2> >tmp2\n    diff --outer-options tmp 1 tmp2\n\nand for most operations we would want to have the inner\noptions to be the same. However there are cases of changing\none of the inner options, example at\nhttps://public-inbox.org/git/20180810001010.58870-1-sbeller@google.com/\n\nBut even when we assume this to be a corner case for\nweird research of our own options, it is unclear to me\nif the options should apply to the inner diffs or to the\nouter diff or both.\n\nAs far as I read the patch, the options are applied to both\ninner and outer, which may be ok?\n\nI would think that sometimes you want to control only the\ninner options, e.g. file copy/rename/move detection\nthresholds. And sometimes you want to control the outer\noptions only (white space error highlighting?)\n"},{"id":"367015","messageId":"CAGZ79kZqt+SgHVrhQjPrkcVD8dJcux-yeE6g9o=De6RLWNbydw@mail.gmail.com","threadId":"50247","inReplyTo":"87munz4ani.fsf@evledraar.gmail.com","subject":"Re: [PATCH 00/76] Convert diff opt parser to parse_options()","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2019-01-17T19:50:11Z","receivedAt":"2019-01-17T19:50:26Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Thu, Jan 17, 2019 at 6:33 AM Ævar Arnfjörð Bjarmason\n<avarab@gmail.com> wrote:\n\n> > I sent a sneak peek [1] last year and got two good comments. I take it\n> > people at least did not oppose to this. The most interesting parts are\n> > at the top and bottom. The middle is just boring conversion, usually\n> > one option per patch.\n>\n> I'm very much for this, and have skimmed it (but not stress tested) and\n> it looks good to me. I have some WIP patches to --abbrev that conflict,\n> but which will be simpler as a result of this.\n\nI like the series a lot.\n"},{"id":"367017","messageId":"nycvar.QRO.7.76.6.1901172104380.41@tvgsbejvaqbjf.bet","threadId":"50247","inReplyTo":"20190117130615.18732-77-pclouds@gmail.com","subject":"Re: [PATCH 76/76] am: avoid diff_opt_parse()","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2019-01-17T20:10:38Z","receivedAt":"2019-01-17T20:10:57Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Duy,\n\nthe change itself looks good, but...\n\nOn Thu, 17 Jan 2019, Nguyễn Thái Ngọc Duy wrote:\n\n> diff_opt_parse() is a heavy hammer to just set diff filter. But it's\n> the only way because of the diff_status_letters[] mapping. Add a new\n> API to set diff filter and use it in git-am. diff_opt_parse()'s only\n> remaining call site in revision.c will be gone soon and having it here\n\n... \"will be gone soon\"? Does that mean that you mail-bomb another mega\npatch series iteration once you did that, now sending 77 or 78 patches?\n\nI don't know about others, but I can only afford to spend a fraction of my\nwaking hours on reviews, and even back when Christian sent the built-in am\nas a loooong patch series it was *already* a big problem. Thankfully he\nseems to have decided to never do that again.\n\nIt would probably make sense to break your 76-strong patch series down\ninto at least four separate patch series, they would still be as long as\nmy Azure Pipelines one (which is longer than I am actually comfortable\nwith, but in my case, it was necessary, while your patch series consists\nof many, mostly independent patches that could even be wrapped into\nindividual patch series of 1 or 2). It's just way too much to review if\nyou present it in the current manner.\n\nCiao,\nJohannes\n\n> just because of git-am does not make sense.\n> \n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  builtin/am.c | 4 ++--\n>  diff.c       | 6 ++++++\n>  diff.h       | 2 ++\n>  3 files changed, 10 insertions(+), 2 deletions(-)\n> \n> diff --git a/builtin/am.c b/builtin/am.c\n> index 95370313b6..0cbf285459 100644\n> --- a/builtin/am.c\n> +++ b/builtin/am.c\n> @@ -1515,11 +1515,11 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa\n>  \t\t * review them with extra care to spot mismerges.\n>  \t\t */\n>  \t\tstruct rev_info rev_info;\n> -\t\tconst char *diff_filter_str = \"--diff-filter=AM\";\n>  \n>  \t\trepo_init_revisions(the_repository, &rev_info, NULL);\n>  \t\trev_info.diffopt.output_format = DIFF_FORMAT_NAME_STATUS;\n> -\t\tdiff_opt_parse(&rev_info.diffopt, &diff_filter_str, 1, rev_info.prefix);\n> +\t\trev_info.diffopt.filter |= diff_filter_bit('A');\n> +\t\trev_info.diffopt.filter |= diff_filter_bit('M');\n>  \t\tadd_pending_oid(&rev_info, \"HEAD\", &our_tree, 0);\n>  \t\tdiff_setup_done(&rev_info.diffopt);\n>  \t\trun_diff_index(&rev_info, 1);\n> diff --git a/diff.c b/diff.c\n> index daccc8226f..b8e58e817b 100644\n> --- a/diff.c\n> +++ b/diff.c\n> @@ -4756,6 +4756,12 @@ static unsigned filter_bit_tst(char status, const struct diff_options *opt)\n>  \treturn opt->filter & filter_bit[(int) status];\n>  }\n>  \n> +unsigned diff_filter_bit(char status)\n> +{\n> +\tprepare_filter_bits();\n> +\treturn filter_bit[(int) status];\n> +}\n> +\n>  static int diff_opt_diff_filter(const struct option *option,\n>  \t\t\t\tconst char *optarg, int unset)\n>  {\n> diff --git a/diff.h b/diff.h\n> index 03c6afda22..f88482705c 100644\n> --- a/diff.h\n> +++ b/diff.h\n> @@ -233,6 +233,8 @@ struct diff_options {\n>  \tstruct option *parseopts;\n>  };\n>  \n> +unsigned diff_filter_bit(char status);\n> +\n>  void diff_emit_submodule_del(struct diff_options *o, const char *line);\n>  void diff_emit_submodule_add(struct diff_options *o, const char *line);\n>  void diff_emit_submodule_untracked(struct diff_options *o, const char *path);\n> -- \n> 2.20.0.482.g66447595a7\n> \n> "},{"id":"367039","messageId":"CACsJy8Cd0ZU-s7-=5isyt3QTs+bnznC5ZGq_Tb0K2ajWrY=BbQ@mail.gmail.com","threadId":"50247","inReplyTo":"nycvar.QRO.7.76.6.1901172104380.41@tvgsbejvaqbjf.bet","subject":"Re: [PATCH 76/76] am: avoid diff_opt_parse()","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-18T00:19:50Z","receivedAt":"2019-01-18T00:20:19Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Fri, Jan 18, 2019 at 3:10 AM Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n>\n> Hi Duy,\n>\n> the change itself looks good, but...\n>\n> On Thu, 17 Jan 2019, Nguyễn Thái Ngọc Duy wrote:\n>\n> > diff_opt_parse() is a heavy hammer to just set diff filter. But it's\n> > the only way because of the diff_status_letters[] mapping. Add a new\n> > API to set diff filter and use it in git-am. diff_opt_parse()'s only\n> > remaining call site in revision.c will be gone soon and having it here\n>\n> ... \"will be gone soon\"? Does that mean that you mail-bomb another mega\n> patch series iteration once you did that, now sending 77 or 78 patches?\n\nThat's another 75 patches.\n\n> I don't know about others, but I can only afford to spend a fraction of my\n> waking hours on reviews, and even back when Christian sent the built-in am\n> as a loooong patch series it was *already* a big problem. Thankfully he\n> seems to have decided to never do that again.\n>\n> It would probably make sense to break your 76-strong patch series down\n> into at least four separate patch series, they would still be as long as\n> my Azure Pipelines one (which is longer than I am actually comfortable\n> with, but in my case, it was necessary, while your patch series consists\n> of many, mostly independent patches that could even be wrapped into\n> individual patch series of 1 or 2). It's just way too much to review if\n> you present it in the current manner.\n\nSorry somehow I forgot about breaking down the series. Part of the\nreason though was I wanted to show that we got somewhere in the end,\nit's not just random restructuring patches that may end up getting\nreverted.\n\nIf there are lots of changes in this series, I'll resend in smaller\nseries. For the revision.c conversion I'll make sure to send in small\nseries.\n\n> Ciao,\n> Johannes\n>\n\n\n-- \nDuy\n"},{"id":"367066","messageId":"CACsJy8A7SpCnXHfYg=Tx4kyUwONbAMufWkhuV4pfyu+BdFbWmQ@mail.gmail.com","threadId":"50247","inReplyTo":"CAGZ79kaAf7NytateigG_f6-UbeJKa2bno9+4zC7R4uqfFB77FA@mail.gmail.com","subject":"Re: [PATCH 74/76] range-diff: use parse_options() instead of diff_opt_parse()","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-18T09:30:51Z","receivedAt":"2019-01-18T09:31:20Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"nOn Fri, Jan 18, 2019 at 2:46 AM Stefan Beller <sbeller@google.com> wrote:\n> > and we get a\n> > looong 'git range-diff -h'\n>\n> This is an interesting tidbit to put into the commit message.\n>\n> range-diff is interesting in that in it is unclear where the options\n> should take effect. My mental model of range-diff is\n>\n>     diff --inner-options-1 <range1> >tmp1\n>     diff --inner-options-2 <range2> >tmp2\n>     diff --outer-options tmp 1 tmp2\n\nThis outer/inner refer to the first and second +/- column in\nrange-diff output, right?\n\n> and for most operations we would want to have the inner\n> options to be the same. However there are cases of changing\n> one of the inner options, example at\n> https://public-inbox.org/git/20180810001010.58870-1-sbeller@google.com/\n>\n> But even when we assume this to be a corner case for\n> weird research of our own options, it is unclear to me\n> if the options should apply to the inner diffs or to the\n> outer diff or both.\n>\n> As far as I read the patch, the options are applied to both\n> inner and outer, which may be ok?\n\nAs far as I can tell, I'm not changing the behavior of this command.\nWhatever options accepted before are accepted now. I'm simply exposing\nthe problem. So no I don't know if it's really ok.\n\nThis is not restricted to range-diff either. \"git diff\" uses\nrevision.c parser which accepts a whole lot of options that only make\nsense with \"git log\" and friends. Even the \"log-tree\" command family\nhas separate set of options for each command, see the \"ifdef\" in\nrev-list-options.txt.\n\nThat, I think, would be the next step. To somehow filter options by\ncommand, remove unused ones. Frankly I only have a vague idea how to\ndo it now ('struct option[]' manipulation).\n\n\n>\n> I would think that sometimes you want to control only the\n> inner options, e.g. file copy/rename/move detection\n> thresholds. And sometimes you want to control the outer\n> options only (white space error highlighting?)\n\n\n\n--\nDuy\n"},{"id":"367164","messageId":"20190119011834.GP840@szeder.dev","threadId":"50247","inReplyTo":"20190117130615.18732-71-pclouds@gmail.com","subject":"Re: [PATCH 70/76] diff.c: convert --inter-hunk-context","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2019-01-19T01:18:34Z","receivedAt":"2019-01-19T01:18:40Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Thu, Jan 17, 2019 at 08:06:09PM +0700, Nguyễn Thái Ngọc Duy wrote:\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  diff.c          | 6 +++---\n>  parse-options.h | 3 ++-\n>  2 files changed, 5 insertions(+), 4 deletions(-)\n> \n> diff --git a/diff.c b/diff.c\n> index 3e7c36524d..cc10b27df0 100644\n> --- a/diff.c\n> +++ b/diff.c\n\n> @@ -5503,9 +5506,6 @@ int diff_opt_parse(struct diff_options *options,\n>  \t}\n>  \n>  \t/* misc options */\n> -\telse if (opt_arg(arg, '\\0', \"inter-hunk-context\",\n> -\t\t\t &options->interhunkcontext))\n> -\t\t;\n\nThis hunk removes the last remaining callsite of the static opt_arg()\nfunction:\n\n  diff.c:4581:12: error: ‘opt_arg’ defined but not used [-Werror=unused-function]\n   static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *val)\n              ^\n  cc1: all warnings being treated as errors\n\n\n>  \telse\n>  \t\treturn 0;\n>  \treturn 1;\n"},{"id":"367165","messageId":"20190119012150.GQ840@szeder.dev","threadId":"50247","inReplyTo":"20190117130615.18732-26-pclouds@gmail.com","subject":"Re: [PATCH 25/76] diff.c: convert --stat*","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2019-01-19T01:21:50Z","receivedAt":"2019-01-19T01:21:56Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Thu, Jan 17, 2019 at 08:05:24PM +0700, Nguyễn Thái Ngọc Duy wrote:\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  diff.c | 113 ++++++++++++++++++++++++++-------------------------------\n>  1 file changed, 52 insertions(+), 61 deletions(-)\n> \n> diff --git a/diff.c b/diff.c\n> index 4398b30f47..1b01b36507 100644\n> --- a/diff.c\n> +++ b/diff.c\n> @@ -4660,77 +4660,56 @@ int parse_long_opt(const char *opt, const char **argv,\n>  \treturn 2;\n>  }\n>  \n> -static int stat_opt(struct diff_options *options, const char **av)\n> +static int diff_opt_stat(const struct option *opt, const char *value, int unset)\n>  {\n> -\tconst char *arg = av[0];\n> -\tchar *end;\n> +\tstruct diff_options *options = opt->value;\n>  \tint width = options->stat_width;\n>  \tint name_width = options->stat_name_width;\n>  \tint graph_width = options->stat_graph_width;\n>  \tint count = options->stat_count;\n> -\tint argcount = 1;\n> +\tchar *end;\n>  \n> -\tif (!skip_prefix(arg, \"--stat\", &arg))\n> -\t\tBUG(\"stat option does not begin with --stat: %s\", arg);\n> -\tend = (char *)arg;\n> +\tBUG_ON_OPT_NEG(unset);\n>  \n> -\tswitch (*arg) {\n> -\tcase '-':\n> -\t\tif (skip_prefix(arg, \"-width\", &arg)) {\n> -\t\t\tif (*arg == '=')\n> -\t\t\t\twidth = strtoul(arg + 1, &end, 10);\n> -\t\t\telse if (!*arg && !av[1])\n> -\t\t\t\tdie_want_option(\"--stat-width\");\n> -\t\t\telse if (!*arg) {\n> -\t\t\t\twidth = strtoul(av[1], &end, 10);\n> -\t\t\t\targcount = 2;\n> -\t\t\t}\n> -\t\t} else if (skip_prefix(arg, \"-name-width\", &arg)) {\n> -\t\t\tif (*arg == '=')\n> -\t\t\t\tname_width = strtoul(arg + 1, &end, 10);\n> -\t\t\telse if (!*arg && !av[1])\n> -\t\t\t\tdie_want_option(\"--stat-name-width\");\n> -\t\t\telse if (!*arg) {\n> -\t\t\t\tname_width = strtoul(av[1], &end, 10);\n> -\t\t\t\targcount = 2;\n> -\t\t\t}\n> -\t\t} else if (skip_prefix(arg, \"-graph-width\", &arg)) {\n> -\t\t\tif (*arg == '=')\n> -\t\t\t\tgraph_width = strtoul(arg + 1, &end, 10);\n> -\t\t\telse if (!*arg && !av[1])\n> -\t\t\t\tdie_want_option(\"--stat-graph-width\");\n> -\t\t\telse if (!*arg) {\n> -\t\t\t\tgraph_width = strtoul(av[1], &end, 10);\n> -\t\t\t\targcount = 2;\n> -\t\t\t}\n> -\t\t} else if (skip_prefix(arg, \"-count\", &arg)) {\n> -\t\t\tif (*arg == '=')\n> -\t\t\t\tcount = strtoul(arg + 1, &end, 10);\n> -\t\t\telse if (!*arg && !av[1])\n> -\t\t\t\tdie_want_option(\"--stat-count\");\n> -\t\t\telse if (!*arg) {\n> -\t\t\t\tcount = strtoul(av[1], &end, 10);\n> -\t\t\t\targcount = 2;\n> -\t\t\t}\n\nThis hunk removes the last couple of callsites of the static\ndie_want_option() function, and building this commit fails with:\n\n  diff.c:107:22: error: ‘die_want_option’ defined but not used [-Werror=unused-function]\n   static NORETURN void die_want_option(const char *option_name)\n                        ^~~~~~~~~~~~~~~\n  cc1: all warnings being treated as errors\n\n\n\n"},{"id":"367231","messageId":"nycvar.QRO.7.76.6.1901211259170.41@tvgsbejvaqbjf.bet","threadId":"50247","inReplyTo":"20190117130615.18732-29-pclouds@gmail.com","subject":"Re: [PATCH 28/76] diff.c: convert -B|--break-rewrites","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2019-01-21T12:07:08Z","receivedAt":"2019-01-21T12:07:27Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Duy,\n\nOn Thu, 17 Jan 2019, Nguyễn Thái Ngọc Duy wrote:\n\n> +static int diff_opt_break_rewrites(const struct option *opt,\n> +\t\t\t\t   const char *arg, int unset)\n> +{\n> +\tint *break_opt = opt->value;\n> +\tint opt1, opt2;\n> +\n> +\tBUG_ON_OPT_NEG(unset);\n> +\tif (!arg)\n> +\t\targ = \"\";\n> +\topt1 = parse_rename_score(&arg);\n> +\tswitch (*arg) {\n> +\tcase '\\0':\n> +\t\topt2 = 0;\n> +\t\tbreak;\n> +\tcase '/':\n> +\t\targ++;\n> +\t\topt2 = parse_rename_score(&arg);\n> +\t\tbreak;\n> +\t}\n\nThis code snippet is anywhere in the spectrum between smart, cute, clever,\nhard to reason about, and difficult to validate. Granted, Git for Windows\nSDK's GCC v7.3.0 seems to be able to figure out (somehow...) that this\ndoes not leave `opt2` uninitialized. But Ubuntu 16.04's default GCC\nversion (which I believe is v5.3.1) is not.\n\nAnd likewise, human readers have to spend way too much time thinking about\nthis. So I would strongly suggest to save everybody and their compiler\nsome time by squashing this in:\n\n-- snip --\nt a/diff.c b/diff.c\nindex 381259e987a5..855e6ddcb2b9 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4949,16 +4949,13 @@ static int diff_opt_break_rewrites(const struct option *opt,\n \t\t\t\t   const char *arg, int unset)\n {\n \tint *break_opt = opt->value;\n-\tint opt1, opt2;\n+\tint opt1, opt2 = 0;\n \n \tBUG_ON_OPT_NEG(unset);\n \tif (!arg)\n \t\targ = \"\";\n \topt1 = parse_rename_score(&arg);\n \tswitch (*arg) {\n-\tcase '\\0':\n-\t\topt2 = 0;\n-\t\tbreak;\n \tcase '/':\n \t\targ++;\n \t\topt2 = parse_rename_score(&arg);\n-- snap --\n\nNot only is the result a lot easier to understand and to reason about, it also\nsaves 3 lines.\n\nCiao,\nJohannes\n\nP.S.: Please do not send the entire 78 \"re-rolled\" patches my way, should\nyou choose to send another iteration of this unsplit patch series, but\njust this one. TIA\n\n> +\tif (*arg != 0)\n> +\t\treturn error(_(\"%s expects <n>/<m> form\"), opt->long_name);\n> +\t*break_opt = opt1 | (opt2 << 16);\n> +\treturn 0;\n> +}\n> +\n>  static int diff_opt_char(const struct option *opt,\n>  \t\t\t const char *arg, int unset)\n>  {\n> @@ -5014,6 +5039,12 @@ static void prep_parse_options(struct diff_options *options)\n>  \t\t\t       N_(\"specify the character to indicate a context instead of ' '\"),\n>  \t\t\t       PARSE_OPT_NONEG, diff_opt_char),\n>  \n> +\t\tOPT_GROUP(N_(\"Diff rename options\")),\n> +\t\tOPT_CALLBACK_F('B', \"break-rewrites\", &options->break_opt, N_(\"<n>[/<m>]\"),\n> +\t\t\t       N_(\"break complete rewrite changes into pairs of delete and create\"),\n> +\t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n> +\t\t\t       diff_opt_break_rewrites),\n> +\n>  \t\tOPT_GROUP(N_(\"Diff other options\")),\n>  \t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n>  \t\t  N_(\"Output to a specific file\"),\n> @@ -5047,12 +5078,7 @@ int diff_opt_parse(struct diff_options *options,\n>  \t\treturn ac;\n>  \n>  \t/* renames options */\n> -\tif (starts_with(arg, \"-B\") ||\n> -\t\t skip_to_optional_arg(arg, \"--break-rewrites\", NULL)) {\n> -\t\tif ((options->break_opt = diff_scoreopt_parse(arg)) == -1)\n> -\t\t\treturn error(\"invalid argument to -B: %s\", arg+2);\n> -\t}\n> -\telse if (starts_with(arg, \"-M\") ||\n> +\tif (starts_with(arg, \"-M\") ||\n>  \t\t skip_to_optional_arg(arg, \"--find-renames\", NULL)) {\n>  \t\tif ((options->rename_score = diff_scoreopt_parse(arg)) == -1)\n>  \t\t\treturn error(\"invalid argument to -M: %s\", arg+2);\n> @@ -5331,17 +5357,14 @@ int parse_rename_score(const char **cp_p)\n>  \n>  static int diff_scoreopt_parse(const char *opt)\n>  {\n> -\tint opt1, opt2, cmd;\n> +\tint opt1, cmd;\n>  \n>  \tif (*opt++ != '-')\n>  \t\treturn -1;\n>  \tcmd = *opt++;\n>  \tif (cmd == '-') {\n>  \t\t/* convert the long-form arguments into short-form versions */\n> -\t\tif (skip_prefix(opt, \"break-rewrites\", &opt)) {\n> -\t\t\tif (*opt == 0 || *opt++ == '=')\n> -\t\t\t\tcmd = 'B';\n> -\t\t} else if (skip_prefix(opt, \"find-copies\", &opt)) {\n> +\t\tif (skip_prefix(opt, \"find-copies\", &opt)) {\n>  \t\t\tif (*opt == 0 || *opt++ == '=')\n>  \t\t\t\tcmd = 'C';\n>  \t\t} else if (skip_prefix(opt, \"find-renames\", &opt)) {\n> @@ -5349,25 +5372,13 @@ static int diff_scoreopt_parse(const char *opt)\n>  \t\t\t\tcmd = 'M';\n>  \t\t}\n>  \t}\n> -\tif (cmd != 'M' && cmd != 'C' && cmd != 'B')\n> -\t\treturn -1; /* that is not a -M, -C, or -B option */\n> +\tif (cmd != 'M' && cmd != 'C')\n> +\t\treturn -1; /* that is not a -M, or -C option */\n>  \n>  \topt1 = parse_rename_score(&opt);\n> -\tif (cmd != 'B')\n> -\t\topt2 = 0;\n> -\telse {\n> -\t\tif (*opt == 0)\n> -\t\t\topt2 = 0;\n> -\t\telse if (*opt != '/')\n> -\t\t\treturn -1; /* we expect -B80/99 or -B80 */\n> -\t\telse {\n> -\t\t\topt++;\n> -\t\t\topt2 = parse_rename_score(&opt);\n> -\t\t}\n> -\t}\n>  \tif (*opt != 0)\n>  \t\treturn -1;\n> -\treturn opt1 | (opt2 << 16);\n> +\treturn opt1;\n>  }\n>  \n>  struct diff_queue_struct diff_queued_diff;\n> -- \n> 2.20.0.482.g66447595a7\n> \n> \n> "},{"id":"367232","messageId":"nycvar.QRO.7.76.6.1901211311320.41@tvgsbejvaqbjf.bet","threadId":"50247","inReplyTo":"20190117130615.18732-64-pclouds@gmail.com","subject":"Re: [PATCH 63/76] diff.c: convert -O","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2019-01-21T12:14:07Z","receivedAt":"2019-01-21T12:14:26Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Duy,\n\nOn Thu, 17 Jan 2019, Nguyễn Thái Ngọc Duy wrote:\n\n> diff --git a/diff.c b/diff.c\n> index ae993f5551..4e004a2195 100644\n> --- a/diff.c\n> +++ b/diff.c\n> @@ -5401,6 +5401,8 @@ static void prep_parse_options(struct diff_options *options)\n>  \t\tOPT_BIT_F(0, \"pickaxe-regex\", &options->pickaxe_opts,\n>  \t\t\t  N_(\"treat <string> in -S as extended POSIX regular expression\"),\n>  \t\t\t  DIFF_PICKAXE_REGEX, PARSE_OPT_NONEG),\n> +\t\tOPT_FILENAME('O', NULL, &options->orderfile,\n> +\t\t\t     N_(\"override diff.orderFile configuration variable\")),\n>  \t\t{ OPTION_CALLBACK, 0, \"output\", options, N_(\"<file>\"),\n>  \t\t  N_(\"Output to a specific file\"),\n>  \t\t  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },\n> @@ -5453,10 +5455,7 @@ int diff_opt_parse(struct diff_options *options,\n>  \t}\n>  \n>  \t/* misc options */\n> -\telse if ((argcount = short_opt('O', av, &optarg))) {\n> -\t\toptions->orderfile = prefix_filename(prefix, optarg);\n> -\t\treturn argcount;\n> -\t} else if (skip_prefix(arg, \"--find-object=\", &arg))\n> +\telse if (skip_prefix(arg, \"--find-object=\", &arg))\n\nYou probably used GCC and therefore missed that this patch removes the\nlast user of `short_opt()`, and therefore leaves `short_opt()` unused.\nApparently Clang v9.1.0 (which is used in Azure Pipelines' macOS builds)\nis smart enough to notice that, though. So please squash this in when you\nsend another iteration of this patch (in a hopefully smaller package than\nthat six-and-a-half-dozen patch series):\n\n-- snip --\ndiff --git a/diff.c b/diff.c\nindex 381259e987a5..5e1ab7daec44 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4692,22 +4692,6 @@ static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *va\n }\n #endif\n \n-static inline int short_opt(char opt, const char **argv,\n-\t\t\t    const char **optarg)\n-{\n-\tconst char *arg = argv[0];\n-\tif (arg[0] != '-' || arg[1] != opt)\n-\t\treturn 0;\n-\tif (arg[2] != '\\0') {\n-\t\t*optarg = arg + 2;\n-\t\treturn 1;\n-\t}\n-\tif (!argv[1])\n-\t\tdie(\"Option '%c' requires a value\", opt);\n-\t*optarg = argv[1];\n-\treturn 2;\n-}\n-\n int parse_long_opt(const char *opt, const char **argv,\n \t\t   const char **optarg)\n {\n-- snap --\n\nCiao,\nJohannes\n\n>  \t\treturn parse_objfind_opt(options, arg);\n>  \telse if ((argcount = parse_long_opt(\"diff-filter\", av, &optarg))) {\n>  \t\tint offending = parse_diff_filter_opt(optarg, options);\n> -- \n> 2.20.0.482.g66447595a7\n> \n> \n> "}]}