Re: [PATCH 2/5] diff: allow --patch to override -s/--no-patch

18 messages, 3 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH 2/5] diff: allow --patch to override -s/--no-patch

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:58:10

Matthieu Moy [off-list ref] writes:
Junio C Hamano [off-list ref] writes:
quoted
I am wondering if the difference after this patch between "-p" and
"-U8" is deliberate, or just an accident coming from the way the
original was written in ee1e5412 (git diff: support "-U" and
"--unified" options properly, 2006-05-13).
No, it isn't. I just didn't notice the -U case.
quoted
If the original were written in this way:

	if (!strcmp(arg, "-p") || !strcmp(arg, "-u") || !strcmp(arg, "--patch") ||
            opt_arg(arg, 'U', "unified", &options->context))
  		options->output_format |= DIFF_FORMAT_PATCH;
Yes, this seems to be a better way.

There are other cases like --patch-with-raw, I'll send a reroll.
Thanks.

[PATCH v2 0/5] Make "git show -s" easier to discover for users

From: Matthieu Moy <hidden>
Date: 2016-06-15 22:58:10

This fixes the issue found by Junio where "git log --no-patch -u" was
showing the patch, but not "git log --no-patch -U8". Other patches are
unmodified.

Matthieu Moy (5):
  diff: allow --no-patch as synonym for -s
  diff: allow --patch & cie to override -s/--no-patch
  Documentation/git-show.txt: include common diff options, like
    git-log.txt
  Documentation: move description of -s, --no-patch to diff-options.txt
  Documentation/git-log.txt: capitalize section names

 Documentation/diff-options.txt     |  5 +++++
 Documentation/git-log.txt          |  8 ++++----
 Documentation/git-show.txt         |  9 +++++++++
 Documentation/rev-list-options.txt |  3 ---
 diff.c                             | 30 ++++++++++++++++++------------
 5 files changed, 36 insertions(+), 19 deletions(-)

-- 
1.8.3.1.495.g13f33cf.dirty

[PATCH v2 3/5] Documentation/git-show.txt: include common diff options, like git-log.txt

From: Matthieu Moy <hidden>
Date: 2016-06-15 22:58:10

Signed-off-by: Matthieu Moy <redacted>
---
 Documentation/git-show.txt | 9 +++++++++
 1 file changed, 9 insertions(+)
diff --git a/Documentation/git-show.txt b/Documentation/git-show.txt
index ae4edcc..4e617e6 100644
--- a/Documentation/git-show.txt
+++ b/Documentation/git-show.txt
@@ -45,6 +45,15 @@ include::pretty-options.txt[]
 include::pretty-formats.txt[]
 
 
+COMMON DIFF OPTIONS
+-------------------
+
+:git-log: 1
+include::diff-options.txt[]
+
+include::diff-generate-patch.txt[]
+
+
 EXAMPLES
 --------
 
-- 
1.8.3.1.495.g13f33cf.dirty

[PATCH v2 5/5] Documentation/git-log.txt: capitalize section names

From: Matthieu Moy <hidden>
Date: 2016-06-15 22:58:10

This is the convention in other files and even at the beginning of git-log.txt

Signed-off-by: Matthieu Moy <redacted>
---
 Documentation/git-log.txt | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt
index 2ea79ba..2eda5e4 100644
--- a/Documentation/git-log.txt
+++ b/Documentation/git-log.txt
@@ -97,7 +97,7 @@ include::rev-list-options.txt[]
 
 include::pretty-formats.txt[]
 
-Common diff options
+COMMON DIFF OPTIONS
 -------------------
 
 :git-log: 1
@@ -105,7 +105,7 @@ include::diff-options.txt[]
 
 include::diff-generate-patch.txt[]
 
-Examples
+EXAMPLES
 --------
 `git log --no-merges`::
 
@@ -161,12 +161,12 @@ git log -L '/int main/',/^}/:main.c::
 `git log -3`::
 	Limits the number of commits to show to 3.
 
-Discussion
+DISCUSSION
 ----------
 
 include::i18n.txt[]
 
-Configuration
+CONFIGURATION
 -------------
 
 See linkgit:git-config[1] for core variables and linkgit:git-diff[1]
-- 
1.8.3.1.495.g13f33cf.dirty

[PATCH v2 4/5] Documentation: move description of -s, --no-patch to diff-options.txt

From: Matthieu Moy <hidden>
Date: 2016-06-15 22:58:10

Technically, "-s, --no-patch" is implemented in diff.c ("git diff
--no-patch" is essentially useless, but valid). From the user point of
view, this allows the documentation to show up in "git show --help",
which is one of the most useful use of the option.

While we're there, add a sentence explaining why the option can be
useful.

Signed-off-by: Matthieu Moy <redacted>
---
 Documentation/diff-options.txt     | 5 +++++
 Documentation/rev-list-options.txt | 4 ----
 2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 87e92d6..bbed2cd 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -26,6 +26,11 @@ ifndef::git-format-patch[]
 	{git-diff? This is the default.}
 endif::git-format-patch[]
 
+-s::
+--no-patch::
+	Suppress diff output. Useful for commands like `git show` that
+	show the patch by default, or to cancel the effect of `--patch`.
+
 -U<n>::
 --unified=<n>::
 	Generate diffs with <n> lines of context instead of
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
index c128a85..e632e85 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -849,8 +849,4 @@ options may be given. See linkgit:git-diff-files[1] for more options.
 -t::
 
 	Show the tree objects in the diff output. This implies '-r'.
-
--s::
---no-patch::
-	Suppress diff output.
 endif::git-rev-list[]
-- 
1.8.3.1.495.g13f33cf.dirty

[PATCH v2 1/5] diff: allow --no-patch as synonym for -s

From: Matthieu Moy <hidden>
Date: 2016-06-15 22:58:10

This follows the usual convention of having a --no-foo option to negate
--foo.

Signed-off-by: Matthieu Moy <redacted>
---
 Documentation/rev-list-options.txt | 1 +
 diff.c                             | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
index e157ec3..c128a85 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -851,5 +851,6 @@ options may be given. See linkgit:git-diff-files[1] for more options.
 	Show the tree objects in the diff output. This implies '-r'.
 
 -s::
+--no-patch::
 	Suppress diff output.
 endif::git-rev-list[]
diff --git a/diff.c b/diff.c
index 6578690..6bd821d 100644
--- a/diff.c
+++ b/diff.c
@@ -3551,7 +3551,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
 		options->output_format |= DIFF_FORMAT_NAME;
 	else if (!strcmp(arg, "--name-status"))
 		options->output_format |= DIFF_FORMAT_NAME_STATUS;
-	else if (!strcmp(arg, "-s"))
+	else if (!strcmp(arg, "-s") || !strcmp(arg, "--no-patch"))
 		options->output_format |= DIFF_FORMAT_NO_OUTPUT;
 	else if (!prefixcmp(arg, "--stat"))
 		/* --stat, --stat-width, --stat-name-width, or --stat-count */
-- 
1.8.3.1.495.g13f33cf.dirty

Re: [PATCH v2 1/5] diff: allow --no-patch as synonym for -s

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:58:10

Matthieu Moy wrote:
quoted hunk
--- a/diff.c
+++ b/diff.c
@@ -3551,7 +3551,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
 		options->output_format |= DIFF_FORMAT_NAME;
 	else if (!strcmp(arg, "--name-status"))
 		options->output_format |= DIFF_FORMAT_NAME_STATUS;
-	else if (!strcmp(arg, "-s"))
+	else if (!strcmp(arg, "-s") || !strcmp(arg, "--no-patch"))
 		options->output_format |= DIFF_FORMAT_NO_OUTPUT;
Very nice idea.

Tests?  E.g.:
diff --git i/t/t4000-diff-format.sh w/t/t4000-diff-format.sh
index 6ddd469..0fa7380 100755
--- i/t/t4000-diff-format.sh
+++ w/t/t4000-diff-format.sh
@@ -59,4 +59,18 @@ test_expect_success \
     'validate git diff-files -p output.' \
     'compare_diff_patch current expected'
 
+test_expect_success \
+    'git diff-files -s after editing work tree' \
+    '>empty &&
+    git diff-files -s >diff-s-output 2>err &&
+    test_cmp empty diff-s-output &&
+    test_cmp empty err'
+
+test_expect_success \
+    'git diff-files --no-patch as synonym for -s' \
+    '>empty &&
+    git diff-files --no-patch >diff-np-output 2>err &&
+    test_cmp empty diff-np-output &&
+    test_cmp empty err'
+
 test_done

[PATCH v3 0/6] Make "git show -s" easier to discover for users

From: Matthieu Moy <hidden>
Date: 2016-06-15 22:58:10

Compared to v2, I just added tests. Strongly inspired from Jonathan's,
but there's one more, and I chose the "modern" indentation style
(hence a clean-up patch before, to avoid mixed-style in the same file).

Matthieu Moy (6):
  t4000-diff-format.sh: modernize style
  diff: allow --no-patch as synonym for -s
  diff: allow --patch & cie to override -s/--no-patch
  Documentation/git-show.txt: include common diff options, like
    git-log.txt
  Documentation: move description of -s, --no-patch to diff-options.txt
  Documentation/git-log.txt: capitalize section names

 Documentation/diff-options.txt     |  5 +++++
 Documentation/git-log.txt          |  8 ++++----
 Documentation/git-show.txt         |  9 +++++++++
 Documentation/rev-list-options.txt |  3 ---
 diff.c                             | 30 ++++++++++++++++++------------
 t/t4000-diff-format.sh             | 35 ++++++++++++++++++++++++++---------
 6 files changed, 62 insertions(+), 28 deletions(-)

-- 
1.8.3.1.495.g13f33cf.dirty

[PATCH v3 1/6] t4000-diff-format.sh: modernize style

From: Matthieu Moy <hidden>
Date: 2016-06-15 22:58:10

Signed-off-by: Matthieu Moy <redacted>
---
 t/t4000-diff-format.sh | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/t/t4000-diff-format.sh b/t/t4000-diff-format.sh
index 6ddd469..2b5dffc 100755
--- a/t/t4000-diff-format.sh
+++ b/t/t4000-diff-format.sh
@@ -15,17 +15,17 @@ line 3'
 cat path0 >path1
 chmod +x path1
 
-test_expect_success \
-    'update-index --add two files with and without +x.' \
-    'git update-index --add path0 path1'
+test_expect_success 'update-index --add two files with and without +x.' '
+	git update-index --add path0 path1
+'
 
 mv path0 path0-
 sed -e 's/line/Line/' <path0- >path0
 chmod +x path0
 rm -f path1
-test_expect_success \
-    'git diff-files -p after editing work tree.' \
-    'git diff-files -p >current'
+test_expect_success 'git diff-files -p after editing work tree.' '
+	git diff-files -p >actual
+'
 
 # that's as far as it comes
 if [ "$(git config --get core.filemode)" = false ]
@@ -55,8 +55,8 @@ deleted file mode 100755
 -line 3
 EOF
 
-test_expect_success \
-    'validate git diff-files -p output.' \
-    'compare_diff_patch current expected'
+test_expect_success 'validate git diff-files -p output.' '
+	compare_diff_patch expected actual
+'
 
 test_done
-- 
1.8.3.1.495.g13f33cf.dirty

Re: [PATCH v3 1/6] t4000-diff-format.sh: modernize style

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:58:10

Matthieu Moy wrote:
Signed-off-by: Matthieu Moy <redacted>
---
 t/t4000-diff-format.sh | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
This test script can use more cleanup, but as preparation for later
patches in this series the above is enough. :)  If I forget to do more
cleanup as a followup, feel free to kick me.

Reviewed-by: Jonathan Nieder <redacted>

[PATCH v3 3/6] diff: allow --patch & cie to override -s/--no-patch

From: Matthieu Moy <hidden>
Date: 2016-06-15 22:58:10

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 <redacted>
---
 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

Re: [PATCH v3 3/6] diff: allow --patch & cie to override -s/--no-patch

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:58:10

Matthieu Moy wrote:
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
Usage nit: this should say "is unusual" or "In the case of --binary in
particular, the name may suggest ...".
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.
[...]
quoted hunk
--- 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
Shouldn't that be "compare_diff_patch expected diff-np-output"?

A couple of other test ideas:

 - "git diff-files --patch --no-patch"
 - "git diff-files -s --patch-with-stat"

Aside from that, the patch looks good.

Thanks,
Jonathan

[PATCH v3 6/6] Documentation/git-log.txt: capitalize section names

From: Matthieu Moy <hidden>
Date: 2016-06-15 22:58:10

This is the convention in other files and even at the beginning of git-log.txt

Signed-off-by: Matthieu Moy <redacted>
---
 Documentation/git-log.txt | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt
index 2ea79ba..2eda5e4 100644
--- a/Documentation/git-log.txt
+++ b/Documentation/git-log.txt
@@ -97,7 +97,7 @@ include::rev-list-options.txt[]
 
 include::pretty-formats.txt[]
 
-Common diff options
+COMMON DIFF OPTIONS
 -------------------
 
 :git-log: 1
@@ -105,7 +105,7 @@ include::diff-options.txt[]
 
 include::diff-generate-patch.txt[]
 
-Examples
+EXAMPLES
 --------
 `git log --no-merges`::
 
@@ -161,12 +161,12 @@ git log -L '/int main/',/^}/:main.c::
 `git log -3`::
 	Limits the number of commits to show to 3.
 
-Discussion
+DISCUSSION
 ----------
 
 include::i18n.txt[]
 
-Configuration
+CONFIGURATION
 -------------
 
 See linkgit:git-config[1] for core variables and linkgit:git-diff[1]
-- 
1.8.3.1.495.g13f33cf.dirty

Re: [PATCH v3 6/6] Documentation/git-log.txt: capitalize section names

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:58:10

Matthieu Moy wrote:
This is the convention in other files and even at the beginning of git-log.txt
The docs aren't so consistent on this, but I agree that it makes sense
to at least be consistent within the generated git-log.html. :)

Generally the series looks very good.  Thanks for taking this on.

[PATCH v3 4/6] Documentation/git-show.txt: include common diff options, like git-log.txt

From: Matthieu Moy <hidden>
Date: 2016-06-15 22:58:10

Signed-off-by: Matthieu Moy <redacted>
---
 Documentation/git-show.txt | 9 +++++++++
 1 file changed, 9 insertions(+)
diff --git a/Documentation/git-show.txt b/Documentation/git-show.txt
index ae4edcc..4e617e6 100644
--- a/Documentation/git-show.txt
+++ b/Documentation/git-show.txt
@@ -45,6 +45,15 @@ include::pretty-options.txt[]
 include::pretty-formats.txt[]
 
 
+COMMON DIFF OPTIONS
+-------------------
+
+:git-log: 1
+include::diff-options.txt[]
+
+include::diff-generate-patch.txt[]
+
+
 EXAMPLES
 --------
 
-- 
1.8.3.1.495.g13f33cf.dirty

[PATCH v3 2/6] diff: allow --no-patch as synonym for -s

From: Matthieu Moy <hidden>
Date: 2016-06-15 22:58:10

This follows the usual convention of having a --no-foo option to negate
--foo.

Signed-off-by: Matthieu Moy <redacted>
---
 Documentation/rev-list-options.txt |  1 +
 diff.c                             |  2 +-
 t/t4000-diff-format.sh             | 12 ++++++++++++
 3 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
index e157ec3..c128a85 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -851,5 +851,6 @@ options may be given. See linkgit:git-diff-files[1] for more options.
 	Show the tree objects in the diff output. This implies '-r'.
 
 -s::
+--no-patch::
 	Suppress diff output.
 endif::git-rev-list[]
diff --git a/diff.c b/diff.c
index 6578690..6bd821d 100644
--- a/diff.c
+++ b/diff.c
@@ -3551,7 +3551,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
 		options->output_format |= DIFF_FORMAT_NAME;
 	else if (!strcmp(arg, "--name-status"))
 		options->output_format |= DIFF_FORMAT_NAME_STATUS;
-	else if (!strcmp(arg, "-s"))
+	else if (!strcmp(arg, "-s") || !strcmp(arg, "--no-patch"))
 		options->output_format |= DIFF_FORMAT_NO_OUTPUT;
 	else if (!prefixcmp(arg, "--stat"))
 		/* --stat, --stat-width, --stat-name-width, or --stat-count */
diff --git a/t/t4000-diff-format.sh b/t/t4000-diff-format.sh
index 2b5dffc..d702575 100755
--- a/t/t4000-diff-format.sh
+++ b/t/t4000-diff-format.sh
@@ -59,4 +59,16 @@ test_expect_success 'validate git diff-files -p output.' '
 	compare_diff_patch expected actual
 '
 
+test_expect_success 'git diff-files -s after editing work tree' '
+	git diff-files -s >diff-s-output 2>err &&
+	test_must_be_empty diff-s-output &&
+	test_must_be_empty err
+'
+
+test_expect_success 'git diff-files --no-patch as synonym for -s' '
+	git diff-files --no-patch >diff-np-output 2>err &&
+	test_must_be_empty diff-np-output &&
+	test_must_be_empty err
+'
+
 test_done
-- 
1.8.3.1.495.g13f33cf.dirty

[PATCH v3 5/6] Documentation: move description of -s, --no-patch to diff-options.txt

From: Matthieu Moy <hidden>
Date: 2016-06-15 22:58:10

Technically, "-s, --no-patch" is implemented in diff.c ("git diff
--no-patch" is essentially useless, but valid). From the user point of
view, this allows the documentation to show up in "git show --help",
which is one of the most useful use of the option.

While we're there, add a sentence explaining why the option can be
useful.

Signed-off-by: Matthieu Moy <redacted>
---
 Documentation/diff-options.txt     | 5 +++++
 Documentation/rev-list-options.txt | 4 ----
 2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 87e92d6..bbed2cd 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -26,6 +26,11 @@ ifndef::git-format-patch[]
 	{git-diff? This is the default.}
 endif::git-format-patch[]
 
+-s::
+--no-patch::
+	Suppress diff output. Useful for commands like `git show` that
+	show the patch by default, or to cancel the effect of `--patch`.
+
 -U<n>::
 --unified=<n>::
 	Generate diffs with <n> lines of context instead of
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
index c128a85..e632e85 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -849,8 +849,4 @@ options may be given. See linkgit:git-diff-files[1] for more options.
 -t::
 
 	Show the tree objects in the diff output. This implies '-r'.
-
--s::
---no-patch::
-	Suppress diff output.
 endif::git-rev-list[]
-- 
1.8.3.1.495.g13f33cf.dirty

[PATCH v2 2/5] diff: allow --patch & cie to override -s/--no-patch

From: Matthieu Moy <hidden>
Date: 2016-06-15 22:58:10

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 <redacted>
---
This is the one which changed.

 diff.c | 28 +++++++++++++++++-----------
 1 file changed, 17 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"))
-- 
1.8.3.1.495.g13f33cf.dirty
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help