# [PATCH] format-patch: allow --no-patch to disable patch output

5 messages from 2016-04-07 to 2016-04-08. Participants: Jacob Keller, Eric Sunshine, Junio C Hamano.
Thread: https://gitlist.dev/t/41954

## Jacob Keller, 2016-04-07 16:46

Subject: [PATCH] format-patch: allow --no-patch to disable patch output
Message-ID: <1460047599-9267-1-git-send-email-jacob.e.keller@intel.com>
URL: https://gitlist.dev/e/1460047599-9267-1-git-send-email-jacob.e.keller%40intel.com

```
The documentation for format-patch indicates that --no-patch wilL
suppress patch output. It also incorrectly mentions that -s will also
suppress the patch output, but this is incorrect because -s is used to
add the sign-off line first. Fix the documentation to remove the
indication about -s. Fix builtin format-patch to prevent always adding
the patch incase --no-patch is given. An alternative approach would be
to remove --no-patch from the documentation for git-format-patch, and
add an error check to indicate that --no-patch is not supported.

Add a test for --no-patch to ensure it functions as expected.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
---
 Documentation/diff-options.txt |  2 ++
 builtin/log.c                  |  4 ++--
 t/t4014-format-patch.sh        | 26 ++++++++++++++++++++++++++
 3 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 4b0318e2ac15..471ee47d0b07 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -27,7 +27,9 @@ ifdef::git-diff[]
 	This is the default.
 endif::git-diff[]
 
+ifndef::git-format-patch[]
 -s::
+endif::git-format-patch[]
 --no-patch::
 	Suppress diff output. Useful for commands like `git show` that
 	show the patch by default, or to cancel the effect of `--patch`.
diff --git a/builtin/log.c b/builtin/log.c
index dff3fbbb437c..10f74837945b 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1390,8 +1390,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		 rev.diffopt.output_format == DIFF_FORMAT_PATCH))
 		rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY;
 
-	/* Always generate a patch */
-	rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
+	if (!(rev.diffopt.output_format & DIFF_FORMAT_NO_OUTPUT))
+		rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
 
 	rev.zero_commit = zero_commit;
 
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index eed2981b96df..ef9cfca30a9e 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -618,6 +618,32 @@ test_expect_success 'format-patch -p suppresses stat' '
 
 '
 
+cat >expect << EOF
+From 422768ba4254e7abbeb467b6fe254472207e3d1f Mon Sep 17 00:00:00 2001
+From: A U Thor <author@example.com>
+Date: Thu, 7 Apr 2005 15:20:13 -0700
+Subject: [PATCH 1/2] This is an excessively long subject line for a message
+ due to the habit some projects have of not having a short, one-line subject
+ at the start of the commit message, but rather sticking a whole paragraph
+ right at the start as the only thing in the commit message. It had better not
+ become the filename for the patch.
+Header1: B E Cipient <rcipient@example.com>
+To: Someone <someone@out.there>
+Cc: C E Cipient <rcipient@example.com>
+
+-- 
+2.8.1.102.ga49ec4a.dirty
+
+EOF
+
+test_expect_success 'format-patch --no-patch suppresses patch' '
+
+	git format-patch --no-patch -2 &&
+	cat 0001-This-is-an-excessively-long-subject-line-for-a-messa.patch > output &&
+	test_cmp expect output
+
+'
+
 test_expect_success 'format-patch from a subdirectory (1)' '
 	filename=$(
 		rm -rf sub &&
-- 
2.8.1.102.ga49ec4a

```

## Eric Sunshine, 2016-04-07 21:30

Subject: Re: [PATCH] format-patch: allow --no-patch to disable patch output
Message-ID: <CAPig+cRNCwFmGW-Zo+osjceA6nb=6t3+rJ2uEbnyYxGfSWQ-Uw@mail.gmail.com>
URL: https://gitlist.dev/e/CAPig%2BcRNCwFmGW-Zo%2BosjceA6nb%3D6t3%2BrJ2uEbnyYxGfSWQ-Uw%40mail.gmail.com
In-Reply-To: <1460047599-9267-1-git-send-email-jacob.e.keller@intel.com>

```
On Thu, Apr 7, 2016 at 12:46 PM, Jacob Keller <jacob.e.keller@intel.com> wrote:
> The documentation for format-patch indicates that --no-patch wilL
> suppress patch output. It also incorrectly mentions that -s will also
> suppress the patch output, but this is incorrect because -s is used to
> add the sign-off line first. Fix the documentation to remove the
> indication about -s. Fix builtin format-patch to prevent always adding
> the patch incase --no-patch is given. An alternative approach would be
> to remove --no-patch from the documentation for git-format-patch, and
> add an error check to indicate that --no-patch is not supported.

See [1] and [2].

[1]: http://thread.gmane.org/gmane.comp.version-control.git/290023
[2]: b73a1bc (git-format-patch.txt: don't show -s as shorthand for
multiple options, 2016-03-27)

> Add a test for --no-patch to ensure it functions as expected.
>
> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>

```

## Jacob Keller, 2016-04-08 18:17

Subject: Re: [PATCH] format-patch: allow --no-patch to disable patch output
Message-ID: <CA+P7+xoUi5H19zOCAiiwQZ0-j8yNZS9-2DzgoMmLSVOrC8Nbpw@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BP7%2BxoUi5H19zOCAiiwQZ0-j8yNZS9-2DzgoMmLSVOrC8Nbpw%40mail.gmail.com
In-Reply-To: <CAPig+cRNCwFmGW-Zo+osjceA6nb=6t3+rJ2uEbnyYxGfSWQ-Uw@mail.gmail.com>

```
On Thu, Apr 7, 2016 at 2:30 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
> On Thu, Apr 7, 2016 at 12:46 PM, Jacob Keller <jacob.e.keller@intel.com> wrote:
>> The documentation for format-patch indicates that --no-patch wilL
>> suppress patch output. It also incorrectly mentions that -s will also
>> suppress the patch output, but this is incorrect because -s is used to
>> add the sign-off line first. Fix the documentation to remove the
>> indication about -s. Fix builtin format-patch to prevent always adding
>> the patch incase --no-patch is given. An alternative approach would be
>> to remove --no-patch from the documentation for git-format-patch, and
>> add an error check to indicate that --no-patch is not supported.
>
> See [1] and [2].
>
> [1]: http://thread.gmane.org/gmane.comp.version-control.git/290023
> [2]: b73a1bc (git-format-patch.txt: don't show -s as shorthand for
> multiple options, 2016-03-27)
>
>> Add a test for --no-patch to ensure it functions as expected.
>>
>> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

So if I want to get the summary of a patch out of a commit without the
actual diff what would you suggest?

Basically, I have a process where we have post processed code, and I
want to be able to generate a "patch" that shows the diff only of the
post-processed code, ie:

checkout commit^ to get the parent commit, process the code, then
checkout the commit and process that code, and run a diff between,
then spit out the equivalent of "git format-patch commit --no-patch" +
the diff between the post processed code.

I think maybe git show --pretty=email might work?

Thanks,
Jake

```

## Junio C Hamano, 2016-04-08 18:30

Subject: Re: [PATCH] format-patch: allow --no-patch to disable patch output
Message-ID: <xmqqh9fcvtqg.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqh9fcvtqg.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <CA+P7+xoUi5H19zOCAiiwQZ0-j8yNZS9-2DzgoMmLSVOrC8Nbpw@mail.gmail.com>

```
Jacob Keller <jacob.keller@gmail.com> writes:

> So if I want to get the summary of a patch out of a commit without the
> actual diff what would you suggest?

"git log --stat"?

If you have a set of (discrete) commits, "git show --stat A B C"?

> Basically, I have a process where we have post processed code, and I
> want to be able to generate a "patch" that shows the diff only of the
> post-processed code, ie:

If you want to script and depend on the exact output, you cannot
depend on "log" or "show", so you would likely be doing "cat-file
commit" for log message part and "diff-tree" (with options like -p
and --stat) for the patch part, I guess.

```

## Jacob Keller, 2016-04-08 18:34

Subject: Re: [PATCH] format-patch: allow --no-patch to disable patch output
Message-ID: <CA+P7+xrYMqcohYpWUpgAu1K=0N-3TgQi0_1sQ+z4v7nCPGcYSQ@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BP7%2BxrYMqcohYpWUpgAu1K%3D0N-3TgQi0_1sQ%2Bz4v7nCPGcYSQ%40mail.gmail.com
In-Reply-To: <xmqqh9fcvtqg.fsf@gitster.mtv.corp.google.com>

```
On Fri, Apr 8, 2016 at 11:30 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Jacob Keller <jacob.keller@gmail.com> writes:
>
>> So if I want to get the summary of a patch out of a commit without the
>> actual diff what would you suggest?
>
> "git log --stat"?
>
> If you have a set of (discrete) commits, "git show --stat A B C"?
>
>> Basically, I have a process where we have post processed code, and I
>> want to be able to generate a "patch" that shows the diff only of the
>> post-processed code, ie:
>
> If you want to script and depend on the exact output, you cannot
> depend on "log" or "show", so you would likely be doing "cat-file
> commit" for log message part and "diff-tree" (with options like -p
> and --stat) for the patch part, I guess.
>

The diff is being done on separate post-processed code, I can do that
part. I just couldn't figure out how to get the same "header" as
format-patch, but without the diff, which is when I saw no-patch, and
then saw that it didn't work.

Thanks,
Jake

```
