Move specific handling of "-m" for diff-index to diff-index.c, so diff-merges is left to handle only diff for merges options. Being a better design by itself, this is especially essential in preparation for letting -m imply -p, as "diff-index -m" obviously should not imply -p, as it's entirely unrelated. Signed-off-by: Sergey Organov <sorganov@xxxxxxxxx> --- builtin/diff-index.c | 45 ++++++++++++++++++++++++++++++++++---------- diff-merges.c | 13 +------------ 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/builtin/diff-index.c b/builtin/diff-index.c index 176fe7ff2b4e..28bc51d0d8f4 100644 --- a/builtin/diff-index.c +++ b/builtin/diff-index.c @@ -12,11 +12,37 @@ static const char diff_cache_usage[] = "[<common-diff-options>] <tree-ish> [<path>...]" COMMON_DIFF_OPTIONS_HELP; +static int parse_distinct_options(int argc, const char **argv, + struct rev_info *revs, unsigned int *options) +{ + int i, left; + + for (i = left = 1; i < argc; i++) { + const char *arg = argv[i]; + int leave = 0; + + if (!strcmp(arg, "--cached")) + *options |= DIFF_INDEX_CACHED; + else if (!strcmp(arg, "--merge-base")) + *options |= DIFF_INDEX_MERGE_BASE; + else if (!strcmp(arg, "-m")) + revs->match_missing = 1; + else + leave = 1; + + if (leave) + argv[left++] = arg; + } + + argv[left] = NULL; + + return left; +} + int cmd_diff_index(int argc, const char **argv, const char *prefix) { struct rev_info rev; unsigned int option = 0; - int i; int result; if (argc == 2 && !strcmp(argv[1], "-h")) @@ -27,17 +53,16 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix) rev.abbrev = 0; prefix = precompose_argv_prefix(argc, argv, prefix); + /* + * It's essential to parse our distinct options before calling + * setup_revisions(), for the latter not to see "-m". + */ + argc = parse_distinct_options(argc, argv, &rev, &option); argc = setup_revisions(argc, argv, &rev, NULL); - for (i = 1; i < argc; i++) { - const char *arg = argv[i]; - if (!strcmp(arg, "--cached")) - option |= DIFF_INDEX_CACHED; - else if (!strcmp(arg, "--merge-base")) - option |= DIFF_INDEX_MERGE_BASE; - else - usage(diff_cache_usage); - } + if (argc > 1) + usage(diff_cache_usage); + if (!rev.diffopt.output_format) rev.diffopt.output_format = DIFF_FORMAT_RAW; diff --git a/diff-merges.c b/diff-merges.c index f3a9daed7e05..4016800c422c 100644 --- a/diff-merges.c +++ b/diff-merges.c @@ -30,17 +30,6 @@ static void set_first_parent(struct rev_info *revs) revs->first_parent_merges = 1; } -static void set_m(struct rev_info *revs) -{ - /* - * To "diff-index", "-m" means "match missing", and to the "log" - * family of commands, it means "show default diff for merges". Set - * both fields appropriately. - */ - set_to_default(revs); - revs->match_missing = 1; -} - static void set_combined(struct rev_info *revs) { suppress(revs); @@ -108,7 +97,7 @@ int diff_merges_parse_opts(struct rev_info *revs, const char **argv) const char *arg = argv[0]; if (!strcmp(arg, "-m")) { - set_m(revs); + set_to_default(revs); } else if (!strcmp(arg, "-c")) { set_combined(revs); revs->combined_imply_patch = 1; -- 2.25.1