git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthieu Moy <Matthieu.Moy@imag.fr>
To: git@vger.kernel.org, gitster@pobox.com
Cc: jrnieder@gmail.com, Matthieu Moy <Matthieu.Moy@imag.fr>
Subject: [PATCH v3 3/6] diff: allow --patch & cie to override -s/--no-patch
Date: Mon, 15 Jul 2013 19:55:22 +0200	[thread overview]
Message-ID: <1373910925-18422-4-git-send-email-Matthieu.Moy@imag.fr> (raw)
In-Reply-To: <1373910925-18422-1-git-send-email-Matthieu.Moy@imag.fr>

All options that trigger a patch output now override --no-patch.

The case of --binary is particular as 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 that "git show --no-patch --binary" display the
binary patch.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
 diff.c                 | 28 +++++++++++++++++-----------
 t/t4000-diff-format.sh |  5 +++++
 2 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/diff.c b/diff.c
index 6bd821d..66ab714 100644
--- a/diff.c
+++ b/diff.c
@@ -3508,6 +3508,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];
@@ -3515,15 +3520,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;
@@ -3545,9 +3550,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;
@@ -3624,7 +3630,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"))
diff --git a/t/t4000-diff-format.sh b/t/t4000-diff-format.sh
index d702575..4fce12f 100755
--- a/t/t4000-diff-format.sh
+++ b/t/t4000-diff-format.sh
@@ -71,4 +71,9 @@ test_expect_success 'git diff-files --no-patch as synonym for -s' '
 	test_must_be_empty err
 '
 
+test_expect_success 'git diff-files --no-patch --patch shows the patch' '
+	git diff-files --no-patch --patch >diff-np-output 2>err &&
+	compare_diff_patch expected actual
+'
+
 test_done
-- 
1.8.3.1.495.g13f33cf.dirty

  parent reply	other threads:[~2013-07-15 17:56 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-15 11:25 Bug in "git show"? Stefan Beller
2013-07-15 12:12 ` Matthieu Moy
2013-07-15 12:23   ` Stefan Beller
2013-07-15 13:07   ` [PATCH 0/5] Make "git show -s" easier to discover for users Matthieu Moy
2013-07-15 13:07     ` [PATCH 1/5] diff: allow --no-patch as synonym for -s Matthieu Moy
2013-07-15 13:07     ` [PATCH 2/5] diff: allow --patch to override -s/--no-patch Matthieu Moy
2013-07-15 15:02       ` Junio C Hamano
2013-07-15 15:28         ` Matthieu Moy
2013-07-15 16:40           ` Junio C Hamano
2013-07-15 17:05             ` [PATCH v2 0/5] Make "git show -s" easier to discover for users Matthieu Moy
2013-07-15 17:05               ` [PATCH v2 1/5] diff: allow --no-patch as synonym for -s Matthieu Moy
2013-07-15 17:35                 ` Jonathan Nieder
2013-07-15 17:55                   ` [PATCH v3 0/6] Make "git show -s" easier to discover for users Matthieu Moy
2013-07-15 17:55                     ` [PATCH v3 1/6] t4000-diff-format.sh: modernize style Matthieu Moy
2013-07-15 18:00                       ` Jonathan Nieder
2013-07-15 17:55                     ` [PATCH v3 2/6] diff: allow --no-patch as synonym for -s Matthieu Moy
2013-07-15 17:55                     ` Matthieu Moy [this message]
2013-07-15 18:09                       ` [PATCH v3 3/6] diff: allow --patch & cie to override -s/--no-patch Jonathan Nieder
2013-07-15 18:23                         ` Matthieu Moy
2013-07-15 18:58                           ` Jonathan Nieder
2013-07-16  8:05                             ` [PATCH v4 0/6] Make "git show -s" easier to discover for users Matthieu Moy
2013-07-16  8:05                               ` [PATCH v4 1/6] t4000-diff-format.sh: modernize style Matthieu Moy
2013-07-16  8:05                               ` [PATCH v4 2/6] diff: allow --no-patch as synonym for -s Matthieu Moy
2013-07-16  8:05                               ` [PATCH v4 3/6] diff: allow --patch & cie to override -s/--no-patch Matthieu Moy
2013-07-16  8:05                               ` [PATCH v4 4/6] Documentation/git-show.txt: include common diff options, like git-log.txt Matthieu Moy
2013-07-16  8:05                               ` [PATCH v4 5/6] Documentation: move description of -s, --no-patch to diff-options.txt Matthieu Moy
2013-07-16  8:05                               ` [PATCH v4 6/6] Documentation/git-log.txt: capitalize section names Matthieu Moy
2013-07-16 17:46                               ` [PATCH v4 0/6] Make "git show -s" easier to discover for users Jonathan Nieder
2013-07-16 18:07                                 ` Stefan Beller
2013-07-18  0:51                               ` Junio C Hamano
2013-07-15 17:55                     ` [PATCH v3 4/6] Documentation/git-show.txt: include common diff options, like git-log.txt Matthieu Moy
2013-07-15 17:55                     ` [PATCH v3 5/6] Documentation: move description of -s, --no-patch to diff-options.txt Matthieu Moy
2013-07-15 17:55                     ` [PATCH v3 6/6] Documentation/git-log.txt: capitalize section names Matthieu Moy
2013-07-15 18:17                       ` Jonathan Nieder
2013-07-15 17:05               ` [PATCH v2 2/5] diff: allow --patch & cie to override -s/--no-patch Matthieu Moy
2013-07-15 17:05               ` [PATCH v2 3/5] Documentation/git-show.txt: include common diff options, like git-log.txt Matthieu Moy
2013-07-15 17:05               ` [PATCH v2 4/5] Documentation: move description of -s, --no-patch to diff-options.txt Matthieu Moy
2013-07-15 17:05               ` [PATCH v2 5/5] Documentation/git-log.txt: capitalize section names Matthieu Moy
2013-07-15 13:07     ` [PATCH 3/5] Documentation/git-show.txt: include common diff options, like git-log.txt Matthieu Moy
2013-07-15 14:54       ` Junio C Hamano
2013-07-15 15:06         ` Junio C Hamano
2013-07-15 13:07     ` [PATCH 4/5] Documentation: move description of -s, --no-patch to diff-options.txt Matthieu Moy
2013-07-15 13:07     ` [PATCH 5/5] Documentation/git-log.txt: capitalize section names Matthieu Moy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1373910925-18422-4-git-send-email-Matthieu.Moy@imag.fr \
    --to=matthieu.moy@imag.fr \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).