@@ -52,7 +52,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
usage(diff_files_usage);
argv++; argc--;
}
- if (!rev.diffopt.output_format)
+ if (rev.diffopt.output_format == DIFF_FORMAT_DEFAULT)
rev.diffopt.output_format = DIFF_FORMAT_RAW;
rev.diffopt.rotate_to_strict = 1;
@@ -48,7 +48,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
else
usage(diff_cache_usage);
}
- if (!rev.diffopt.output_format)
+ if (rev.diffopt.output_format == DIFF_FORMAT_DEFAULT)
rev.diffopt.output_format = DIFF_FORMAT_RAW;
rev.diffopt.rotate_to_strict = 1;
@@ -100,7 +100,7 @@ COMMON_DIFF_OPTIONS_HELP;
static void diff_tree_tweak_rev(struct rev_info *rev, struct setup_revision_opt *opt)
{
- if (!rev->diffopt.output_format) {
+ if (rev->diffopt.output_format == DIFF_FORMAT_DEFAULT) {
if (rev->dense_combined_merges)
rev->diffopt.output_format = DIFF_FORMAT_PATCH;
else
@@ -505,7 +505,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
if (nongit)
die(_("Not a git repository"));
argc = setup_revisions(argc, argv, &rev, NULL);
- if (!rev.diffopt.output_format) {
+ if (rev.diffopt.output_format == DIFF_FORMAT_DEFAULT) {
rev.diffopt.output_format = DIFF_FORMAT_PATCH;
diff_setup_done(&rev.diffopt);
}
@@ -277,7 +277,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
PARSE_OPT_KEEP_DASHDASH);
if (quiet)
- rev->diffopt.output_format |= DIFF_FORMAT_NO_OUTPUT;
+ rev->diffopt.output_format = DIFF_FORMAT_NO_OUTPUT;
argc = setup_revisions(argc, argv, rev, opt);
/* Any arguments at this point are not recognized */
@@ -633,7 +633,7 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix)
opt.def = "HEAD";
opt.revarg_opt = REVARG_COMMITTISH;
cmd_log_init(argc, argv, prefix, &rev, &opt);
- if (!rev.diffopt.output_format)
+ if (rev.diffopt.output_format == DIFF_FORMAT_DEFAULT)
rev.diffopt.output_format = DIFF_FORMAT_RAW;
return cmd_log_deinit(cmd_log_walk(&rev), &rev);
}
@@ -725,7 +725,7 @@ static void show_setup_revisions_tweak(struct rev_info *rev,
diff_merges_default_to_first_parent(rev);
else
diff_merges_default_to_dense_combined(rev);
- if (!rev->diffopt.output_format)
+ if (rev->diffopt.output_format == DIFF_FORMAT_DEFAULT)
rev->diffopt.output_format = DIFF_FORMAT_PATCH;
}
@@ -891,9 +891,12 @@ int cmd_log(int argc, const char **argv, const char *prefix)
opt.tweak = log_setup_revisions_tweak;
cmd_log_init(argc, argv, prefix, &rev, &opt);
- if (!rev.diffopt.output_format)
+ if (rev.diffopt.output_format == DIFF_FORMAT_DEFAULT) {
if (rev.line_level_traverse)
rev.diffopt.output_format = DIFF_FORMAT_PATCH;
+ else
+ rev.diffopt.output_format = 0;
+ }
return cmd_log_deinit(cmd_log_walk(&rev), &rev);
}
@@ -2126,7 +2129,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
die(_("--remerge-diff does not make sense"));
if (!use_patch_format &&
- (!rev.diffopt.output_format ||
+ (rev.diffopt.output_format == DIFF_FORMAT_DEFAULT ||
rev.diffopt.output_format == DIFF_FORMAT_PATCH))
rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY;
if (!rev.diffopt.stat_width)
@@ -944,7 +944,7 @@ static int show_stash(int argc, const char **argv, const char *prefix)
argc = setup_revisions(revision_args.nr, revision_args.v, &rev, NULL);
if (argc > 1)
goto usage;
- if (!rev.diffopt.output_format) {
+ if (rev.diffopt.output_format == DIFF_FORMAT_DEFAULT) {
rev.diffopt.output_format = DIFF_FORMAT_PATCH;
diff_setup_done(&rev.diffopt);
}
@@ -183,7 +183,7 @@ void diff_merges_setup_revs(struct rev_info *revs)
if (revs->merges_imply_patch)
revs->diff = 1;
if (revs->merges_imply_patch || revs->merges_need_diff) {
- if (!revs->diffopt.output_format)
+ if (revs->diffopt.output_format == DIFF_FORMAT_DEFAULT)
revs->diffopt.output_format = DIFF_FORMAT_PATCH;
}
}
@@ -282,7 +282,7 @@ int diff_no_index(struct rev_info *revs,
fixup_paths(paths, &replacement);
revs->diffopt.skip_stat_unmatch = 1;
- if (!revs->diffopt.output_format)
+ if (revs->diffopt.output_format == DIFF_FORMAT_DEFAULT)
revs->diffopt.output_format = DIFF_FORMAT_PATCH;
revs->diffopt.flags.no_index = 1;
@@ -4669,6 +4669,7 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)
options->file = stdout;
options->repo = r;
+ options->output_format = DIFF_FORMAT_DEFAULT;
options->output_indicators[OUTPUT_INDICATOR_NEW] = '+';
options->output_indicators[OUTPUT_INDICATOR_OLD] = '-';
options->output_indicators[OUTPUT_INDICATOR_CONTEXT] = ' ';
@@ -4987,7 +4988,7 @@ static int diff_opt_diff_filter(const struct option *option,
static void enable_patch_output(int *fmt)
{
- *fmt &= ~DIFF_FORMAT_NO_OUTPUT;
+ *fmt &= ~(DIFF_FORMAT_DEFAULT | DIFF_FORMAT_NO_OUTPUT);
*fmt |= DIFF_FORMAT_PATCH;
}
@@ -5492,13 +5493,13 @@ struct option *add_diff_options(const struct option *opts,
OPT_GROUP(N_("Diff output format options")),
OPT_BITOP('p', "patch", &options->output_format,
N_("generate patch"),
- DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT),
- OPT_BIT_F('s', "no-patch", &options->output_format,
+ DIFF_FORMAT_PATCH, DIFF_FORMAT_DEFAULT | DIFF_FORMAT_NO_OUTPUT),
+ OPT_BITOP('s', "no-patch", &options->output_format,
N_("suppress diff output"),
- DIFF_FORMAT_NO_OUTPUT, PARSE_OPT_NONEG),
+ DIFF_FORMAT_NO_OUTPUT, DIFF_FORMAT_DEFAULT | DIFF_FORMAT_PATCH),
OPT_BITOP('u', NULL, &options->output_format,
N_("generate patch"),
- DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT),
+ DIFF_FORMAT_PATCH, DIFF_FORMAT_DEFAULT | DIFF_FORMAT_NO_OUTPUT),
OPT_CALLBACK_F('U', "unified", options, N_("<n>"),
N_("generate diffs with <n> lines context"),
PARSE_OPT_NONEG | PARSE_OPT_OPTARG, diff_opt_unified),
@@ -5510,17 +5511,17 @@ struct option *add_diff_options(const struct option *opts,
OPT_BITOP(0, "patch-with-raw", &options->output_format,
N_("synonym for '-p --raw'"),
DIFF_FORMAT_PATCH | DIFF_FORMAT_RAW,
- DIFF_FORMAT_NO_OUTPUT),
+ DIFF_FORMAT_DEFAULT | DIFF_FORMAT_NO_OUTPUT),
OPT_BITOP(0, "patch-with-stat", &options->output_format,
N_("synonym for '-p --stat'"),
DIFF_FORMAT_PATCH | DIFF_FORMAT_DIFFSTAT,
- DIFF_FORMAT_NO_OUTPUT),
- OPT_BIT_F(0, "numstat", &options->output_format,
+ DIFF_FORMAT_DEFAULT | DIFF_FORMAT_NO_OUTPUT),
+ OPT_BITOP(0, "numstat", &options->output_format,
N_("machine friendly --stat"),
- DIFF_FORMAT_NUMSTAT, PARSE_OPT_NONEG),
- OPT_BIT_F(0, "shortstat", &options->output_format,
+ DIFF_FORMAT_NUMSTAT, DIFF_FORMAT_DEFAULT),
+ OPT_BITOP(0, "shortstat", &options->output_format,
N_("output only the last line of --stat"),
- DIFF_FORMAT_SHORTSTAT, PARSE_OPT_NONEG),
+ DIFF_FORMAT_SHORTSTAT, DIFF_FORMAT_DEFAULT),
OPT_CALLBACK_F('X', "dirstat", options, N_("<param1,param2>..."),
N_("output the distribution of relative amount of changes for each sub-directory"),
PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
@@ -5533,18 +5534,18 @@ struct option *add_diff_options(const struct option *opts,
N_("synonym for --dirstat=files,param1,param2..."),
PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
diff_opt_dirstat),
- OPT_BIT_F(0, "check", &options->output_format,
+ OPT_BITOP(0, "check", &options->output_format,
N_("warn if changes introduce conflict markers or whitespace errors"),
- DIFF_FORMAT_CHECKDIFF, PARSE_OPT_NONEG),
- OPT_BIT_F(0, "summary", &options->output_format,
+ DIFF_FORMAT_CHECKDIFF, DIFF_FORMAT_DEFAULT),
+ OPT_BITOP(0, "summary", &options->output_format,
N_("condensed summary such as creations, renames and mode changes"),
- DIFF_FORMAT_SUMMARY, PARSE_OPT_NONEG),
- OPT_BIT_F(0, "name-only", &options->output_format,
+ DIFF_FORMAT_SUMMARY, DIFF_FORMAT_DEFAULT),
+ OPT_BITOP(0, "name-only", &options->output_format,
N_("show only names of changed files"),
- DIFF_FORMAT_NAME, PARSE_OPT_NONEG),
- OPT_BIT_F(0, "name-status", &options->output_format,
+ DIFF_FORMAT_NAME, DIFF_FORMAT_DEFAULT),
+ OPT_BITOP(0, "name-status", &options->output_format,
N_("show only names and status of changed files"),
- DIFF_FORMAT_NAME_STATUS, PARSE_OPT_NONEG),
+ DIFF_FORMAT_NAME_STATUS, DIFF_FORMAT_DEFAULT),
OPT_CALLBACK_F(0, "stat", options, N_("<width>[,<name-width>[,<count>]]"),
N_("generate diffstat"),
PARSE_OPT_NONEG | PARSE_OPT_OPTARG, diff_opt_stat),
@@ -101,6 +101,7 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data)
#define DIFF_FORMAT_PATCH 0x0010
#define DIFF_FORMAT_SHORTSTAT 0x0020
#define DIFF_FORMAT_DIRSTAT 0x0040
+#define DIFF_FORMAT_DEFAULT 0x0080
/* These override all above */
#define DIFF_FORMAT_NAME 0x0100
@@ -492,7 +492,7 @@ static void output(struct string_list *a, struct string_list *b,
repo_diff_setup(the_repository, &opts);
opts.no_free = 1;
- if (!opts.output_format)
+ if (opts.output_format == DIFF_FORMAT_DEFAULT)
opts.output_format = DIFF_FORMAT_PATCH;
opts.flags.suppress_diff_headers = 1;
opts.flags.dual_color_diffed_diffs =
@@ -2966,7 +2966,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
}
/* Did the user ask for any diff output? Run the diff! */
- if (revs->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT)
+ if (revs->diffopt.output_format & ~(DIFF_FORMAT_DEFAULT | DIFF_FORMAT_NO_OUTPUT))
revs->diff = 1;
/* Pickaxe, diff-filter and rename following need diffs */
@@ -3030,7 +3030,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
die(_("the option '%s' requires '%s'"), "--grep-reflog", "--walk-reflogs");
if (revs->line_level_traverse &&
- (revs->diffopt.output_format & ~(DIFF_FORMAT_PATCH | DIFF_FORMAT_NO_OUTPUT)))
+ (revs->diffopt.output_format & ~(DIFF_FORMAT_DEFAULT | DIFF_FORMAT_PATCH | DIFF_FORMAT_NO_OUTPUT)))
die(_("-L does not yet support diff formats besides -p and -s"));
if (revs->expand_tabs_in_log < 0)
As the name suggests this is the default format, which means no format was specified. This is not the same as DIFF_FORMAT_PATCH, as some commands like `git diff-files` use a different default. This makes it possible to distinguish `git diff` (DEFAULT) from `git diff --no-patch` (0). Will help further changes. There should be no functional changes. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> --- builtin/diff-files.c | 2 +- builtin/diff-index.c | 2 +- builtin/diff-tree.c | 2 +- builtin/diff.c | 2 +- builtin/log.c | 13 ++++++++----- builtin/stash.c | 2 +- diff-merges.c | 2 +- diff-no-index.c | 2 +- diff.c | 39 ++++++++++++++++++++------------------- diff.h | 1 + range-diff.c | 2 +- revision.c | 4 ++-- 12 files changed, 39 insertions(+), 34 deletions(-)