Skip to content

Commit 61cfbc0

Browse files
jacob-kellergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 660e113 commit 61cfbc0

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

diff.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ static int parse_dirstat_params(struct diff_options *options, const char *params
132132
static int parse_submodule_params(struct diff_options *options, const char *value)
133133
{
134134
if (!strcmp(value, "log"))
135-
DIFF_OPT_SET(options, SUBMODULE_LOG);
135+
options->submodule_format = DIFF_SUBMODULE_LOG;
136136
else if (!strcmp(value, "short"))
137-
DIFF_OPT_CLR(options, SUBMODULE_LOG);
137+
options->submodule_format = DIFF_SUBMODULE_SHORT;
138138
else
139139
return -1;
140140
return 0;
@@ -2300,9 +2300,9 @@ static void builtin_diff(const char *name_a,
23002300
struct strbuf header = STRBUF_INIT;
23012301
const char *line_prefix = diff_line_prefix(o);
23022302

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))) {
23062306
const char *del = diff_get_color_opt(o, DIFF_FILE_OLD);
23072307
const char *add = diff_get_color_opt(o, DIFF_FILE_NEW);
23082308
show_submodule_summary(o->file, one->path ? one->path : two->path,
@@ -3916,7 +3916,7 @@ int diff_opt_parse(struct diff_options *options,
39163916
DIFF_OPT_SET(options, OVERRIDE_SUBMODULE_CONFIG);
39173917
handle_ignore_submodules_arg(options, arg);
39183918
} else if (!strcmp(arg, "--submodule"))
3919-
DIFF_OPT_SET(options, SUBMODULE_LOG);
3919+
options->submodule_format = DIFF_SUBMODULE_LOG;
39203920
else if (skip_prefix(arg, "--submodule=", &arg))
39213921
return parse_submodule_opt(options, arg);
39223922
else if (skip_prefix(arg, "--ws-error-highlight=", &arg))

diff.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data)
8383
#define DIFF_OPT_DIRSTAT_BY_FILE (1 << 20)
8484
#define DIFF_OPT_ALLOW_TEXTCONV (1 << 21)
8585
#define DIFF_OPT_DIFF_FROM_CONTENTS (1 << 22)
86-
#define DIFF_OPT_SUBMODULE_LOG (1 << 23)
8786
#define DIFF_OPT_DIRTY_SUBMODULES (1 << 24)
8887
#define DIFF_OPT_IGNORE_UNTRACKED_IN_SUBMODULES (1 << 25)
8988
#define DIFF_OPT_IGNORE_DIRTY_SUBMODULES (1 << 26)
@@ -110,6 +109,11 @@ enum diff_words_type {
110109
DIFF_WORDS_COLOR
111110
};
112111

112+
enum diff_submodule_format {
113+
DIFF_SUBMODULE_SHORT = 0,
114+
DIFF_SUBMODULE_LOG
115+
};
116+
113117
struct diff_options {
114118
const char *orderfile;
115119
const char *pickaxe;
@@ -157,6 +161,7 @@ struct diff_options {
157161
int stat_count;
158162
const char *word_regex;
159163
enum diff_words_type word_diff;
164+
enum diff_submodule_format submodule_format;
160165

161166
/* this is set by diffcore for DIFF_FORMAT_PATCH */
162167
int found_changes;

0 commit comments

Comments
 (0)