diff: prepare for additional submodule formats
A future patch will add a new format for displaying the difference of a submodule. Make it easier by changing how we store the current selected format. Replace the DIFF_OPT flag with an enumeration, as each format will be mutually exclusive. Signed-off-by: Jacob Keller <jacob.keller@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jacob Keller committed
Aug 31, 2016 at 16:27 UTC
61cfbc054d8341c3276efbf1380a2be0ee435dba
2 files changed
+12
-7
diff.c
+6
-6
@@ -132,9 +132,9 @@ static int parse_dirstat_params(struct diff_options *options, const char *params
132
static int parse_submodule_params(struct diff_options *options, const char *value)
133
{
134
if (!strcmp(value, "log"))
135
- DIFF_OPT_SET(options, SUBMODULE_LOG);
135
+ options->submodule_format = DIFF_SUBMODULE_LOG;
136
else if (!strcmp(value, "short"))
137
- DIFF_OPT_CLR(options, SUBMODULE_LOG);
137
+ options->submodule_format = DIFF_SUBMODULE_SHORT;
138
else
139
return -1;
140
return 0;
@@ -2300,9 +2300,9 @@ static void builtin_diff(const char *name_a,
2300
struct strbuf header = STRBUF_INIT;
2301
const char *line_prefix = diff_line_prefix(o);
2302
2303
- if (DIFF_OPT_TST(o, SUBMODULE_LOG) &&
2304
- (!one->mode || S_ISGITLINK(one->mode)) &&
2305
- (!two->mode || S_ISGITLINK(two->mode))) {
2303
+ if (o->submodule_format == DIFF_SUBMODULE_LOG &&
2304
+ (!one->mode || S_ISGITLINK(one->mode)) &&
2305
+ (!two->mode || S_ISGITLINK(two->mode))) {
2306
const char *del = diff_get_color_opt(o, DIFF_FILE_OLD);
2307
const char *add = diff_get_color_opt(o, DIFF_FILE_NEW);
2308
show_submodule_summary(o->file, one->path ? one->path : two->path,
@@ -3916,7 +3916,7 @@ int diff_opt_parse(struct diff_options *options,
3916
DIFF_OPT_SET(options, OVERRIDE_SUBMODULE_CONFIG);
3917
handle_ignore_submodules_arg(options, arg);
3918
} else if (!strcmp(arg, "--submodule"))
3919
- DIFF_OPT_SET(options, SUBMODULE_LOG);
3919
+ options->submodule_format = DIFF_SUBMODULE_LOG;
3920
else if (skip_prefix(arg, "--submodule=", &arg))
3921
return parse_submodule_opt(options, arg);
3922
else if (skip_prefix(arg, "--ws-error-highlight=", &arg))
diff.h
+6
-1
@@ -83,7 +83,6 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data)
83
#define DIFF_OPT_DIRSTAT_BY_FILE (1 << 20)
84
#define DIFF_OPT_ALLOW_TEXTCONV (1 << 21)
85
#define DIFF_OPT_DIFF_FROM_CONTENTS (1 << 22)
86
-#define DIFF_OPT_SUBMODULE_LOG (1 << 23)
86
#define DIFF_OPT_DIRTY_SUBMODULES (1 << 24)
87
#define DIFF_OPT_IGNORE_UNTRACKED_IN_SUBMODULES (1 << 25)
88
#define DIFF_OPT_IGNORE_DIRTY_SUBMODULES (1 << 26)
@@ -110,6 +109,11 @@ enum diff_words_type {
109
DIFF_WORDS_COLOR
110
};
111
112
+enum diff_submodule_format {
113
+ DIFF_SUBMODULE_SHORT = 0,
114
+ DIFF_SUBMODULE_LOG
115
+};
116
+
117
struct diff_options {
118
const char *orderfile;
119
const char *pickaxe;
@@ -157,6 +161,7 @@ struct diff_options {
161
int stat_count;
162
const char *word_regex;
163
enum diff_words_type word_diff;
164
+ enum diff_submodule_format submodule_format;
165
166
/* this is set by diffcore for DIFF_FORMAT_PATCH */
167
int found_changes;