summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorMatthieu Moy <Matthieu.Moy@imag.fr>2013-07-16 08:05:37 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-07-18 00:50:56 (GMT)
commit71482d389d0b214d2cfc2adf788ba1011a7dcb18 (patch)
treeeed10dcbed7a53968a322849650287642b3bf23d /diff.c
parentd09cd15d19de23aca532a85f6d27a71b2baceb3f (diff)
downloadgit-71482d389d0b214d2cfc2adf788ba1011a7dcb18.zip
git-71482d389d0b214d2cfc2adf788ba1011a7dcb18.tar.gz
git-71482d389d0b214d2cfc2adf788ba1011a7dcb18.tar.bz2
diff: allow --patch & cie to override -s/--no-patch
All options that trigger a patch output now override --no-patch. The case of --binary deserves extra attention: the name may suggest that it turns a normal patch into a binary patch, but it actually already enables patch output when normally disabled (e.g. "git log --binary" displays a patch), hence it makes sense for "git show --no-patch --binary" to display the binary patch. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/diff.c b/diff.c
index cc41d88..5290306 100644
--- a/diff.c
+++ b/diff.c
@@ -3497,6 +3497,11 @@ static int parse_submodule_opt(struct diff_options *options, const char *value)
return 1;
}
+static void enable_patch_output(int *fmt) {
+ *fmt &= ~DIFF_FORMAT_NO_OUTPUT;
+ *fmt |= DIFF_FORMAT_PATCH;
+}
+
int diff_opt_parse(struct diff_options *options, const char **av, int ac)
{
const char *arg = av[0];
@@ -3504,15 +3509,15 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
int argcount;
/* Output format options */
- if (!strcmp(arg, "-p") || !strcmp(arg, "-u") || !strcmp(arg, "--patch"))
- options->output_format |= DIFF_FORMAT_PATCH;
- else if (opt_arg(arg, 'U', "unified", &options->context))
- options->output_format |= DIFF_FORMAT_PATCH;
+ if (!strcmp(arg, "-p") || !strcmp(arg, "-u") || !strcmp(arg, "--patch")
+ || opt_arg(arg, 'U', "unified", &options->context))
+ enable_patch_output(&options->output_format);
else if (!strcmp(arg, "--raw"))
options->output_format |= DIFF_FORMAT_RAW;
- else if (!strcmp(arg, "--patch-with-raw"))
- options->output_format |= DIFF_FORMAT_PATCH | DIFF_FORMAT_RAW;
- else if (!strcmp(arg, "--numstat"))
+ else if (!strcmp(arg, "--patch-with-raw")) {
+ enable_patch_output(&options->output_format);
+ options->output_format |= DIFF_FORMAT_RAW;
+ } else if (!strcmp(arg, "--numstat"))
options->output_format |= DIFF_FORMAT_NUMSTAT;
else if (!strcmp(arg, "--shortstat"))
options->output_format |= DIFF_FORMAT_SHORTSTAT;
@@ -3534,9 +3539,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
options->output_format |= DIFF_FORMAT_CHECKDIFF;
else if (!strcmp(arg, "--summary"))
options->output_format |= DIFF_FORMAT_SUMMARY;
- else if (!strcmp(arg, "--patch-with-stat"))
- options->output_format |= DIFF_FORMAT_PATCH | DIFF_FORMAT_DIFFSTAT;
- else if (!strcmp(arg, "--name-only"))
+ else if (!strcmp(arg, "--patch-with-stat")) {
+ enable_patch_output(&options->output_format);
+ options->output_format |= DIFF_FORMAT_DIFFSTAT;
+ } else if (!strcmp(arg, "--name-only"))
options->output_format |= DIFF_FORMAT_NAME;
else if (!strcmp(arg, "--name-status"))
options->output_format |= DIFF_FORMAT_NAME_STATUS;
@@ -3611,7 +3617,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
/* flags options */
else if (!strcmp(arg, "--binary")) {
- options->output_format |= DIFF_FORMAT_PATCH;
+ enable_patch_output(&options->output_format);
DIFF_OPT_SET(options, BINARY);
}
else if (!strcmp(arg, "--full-index"))