Skip to content

Commit 19b2517

Browse files
sorganovgitster
authored andcommitted
diff-merges: move specific diff-index "-m" handling to diff-index
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. To handle this, in addition to moving specific diff-index "-m" code out of diff-merges, we introduce new diff_merges_suppress_options_parsing() and call it before generic options processing in cmd_diff_index(). This new diff_merges_suppress_options_parsing() could then be reused and called before invocations of setup_revisions() for other commands that don't need --diff-merges options, but that's outside of the scope of these patch series. Signed-off-by: Sergey Organov <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e0b1642 commit 19b2517

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

builtin/diff-index.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "cache.h"
33
#include "config.h"
44
#include "diff.h"
5+
#include "diff-merges.h"
56
#include "commit.h"
67
#include "revision.h"
78
#include "builtin.h"
@@ -27,6 +28,12 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
2728
rev.abbrev = 0;
2829
prefix = precompose_argv_prefix(argc, argv, prefix);
2930

31+
/*
32+
* We need no diff for merges options, and we need to avoid conflict
33+
* with our own meaning of "-m".
34+
*/
35+
diff_merges_suppress_options_parsing();
36+
3037
argc = setup_revisions(argc, argv, &rev, NULL);
3138
for (i = 1; i < argc; i++) {
3239
const char *arg = argv[i];
@@ -35,6 +42,8 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
3542
option |= DIFF_INDEX_CACHED;
3643
else if (!strcmp(arg, "--merge-base"))
3744
option |= DIFF_INDEX_MERGE_BASE;
45+
else if (!strcmp(arg, "-m"))
46+
rev.match_missing = 1;
3847
else
3948
usage(diff_cache_usage);
4049
}

diff-merges.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ typedef void (*diff_merges_setup_func_t)(struct rev_info *);
66
static void set_separate(struct rev_info *revs);
77

88
static diff_merges_setup_func_t set_to_default = set_separate;
9+
static int suppress_parsing;
910

1011
static void suppress(struct rev_info *revs)
1112
{
@@ -30,17 +31,6 @@ static void set_first_parent(struct rev_info *revs)
3031
revs->first_parent_merges = 1;
3132
}
3233

33-
static void set_m(struct rev_info *revs)
34-
{
35-
/*
36-
* To "diff-index", "-m" means "match missing", and to the "log"
37-
* family of commands, it means "show default diff for merges". Set
38-
* both fields appropriately.
39-
*/
40-
set_to_default(revs);
41-
revs->match_missing = 1;
42-
}
43-
4434
static void set_combined(struct rev_info *revs)
4535
{
4636
suppress(revs);
@@ -101,14 +91,22 @@ int diff_merges_config(const char *value)
10191
return 0;
10292
}
10393

94+
void diff_merges_suppress_options_parsing(void)
95+
{
96+
suppress_parsing = 1;
97+
}
98+
10499
int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
105100
{
106101
int argcount = 1;
107102
const char *optarg;
108103
const char *arg = argv[0];
109104

105+
if (suppress_parsing)
106+
return 0;
107+
110108
if (!strcmp(arg, "-m")) {
111-
set_m(revs);
109+
set_to_default(revs);
112110
} else if (!strcmp(arg, "-c")) {
113111
set_combined(revs);
114112
revs->combined_imply_patch = 1;
@@ -155,6 +153,9 @@ void diff_merges_set_dense_combined_if_unset(struct rev_info *revs)
155153

156154
void diff_merges_setup_revs(struct rev_info *revs)
157155
{
156+
if (suppress_parsing)
157+
return;
158+
158159
if (revs->combine_merges == 0)
159160
revs->dense_combined_merges = 0;
160161
if (revs->separate_merges == 0)

diff-merges.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ struct rev_info;
1111

1212
int diff_merges_config(const char *value);
1313

14+
void diff_merges_suppress_options_parsing(void);
15+
1416
int diff_merges_parse_opts(struct rev_info *revs, const char **argv);
1517

1618
void diff_merges_suppress(struct rev_info *revs);

0 commit comments

Comments
 (0)