All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] format-patch: output header for empty commits
@ 2023-03-03 16:03 John Keeping
  2023-03-03 17:13 ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: John Keeping @ 2023-03-03 16:03 UTC (permalink / raw)
  To: git; +Cc: John Keeping

When formatting an empty commit, it is surprising that a totally empty
file is generated.  Set the flag to always print the header, matching
the behaviour of git-log.

Signed-off-by: John Keeping <john@keeping.me.uk>
---
 builtin/log.c           |  1 +
 t/t4014-format-patch.sh | 10 ++++++++++
 2 files changed, 11 insertions(+)

diff --git a/builtin/log.c b/builtin/log.c
index a70fba198f..87b4fb2edc 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -2097,6 +2097,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 
 	/* Always generate a patch */
 	rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
+	rev.always_show_header = 1;
 
 	rev.zero_commit = zero_commit;
 	rev.patch_name_max = fmt_patch_name_max;
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index f3313b8c58..ffc7c60680 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -59,6 +59,10 @@ test_expect_success setup '
 	test_tick &&
 	git commit -m "patchid 3" &&
 
+	git checkout -b empty main &&
+	test_tick &&
+	git commit --allow-empty -m "empty commit" &&
+
 	git checkout main
 '
 
@@ -128,6 +132,12 @@ test_expect_success 'replay did not screw up the log message' '
 	grep "^Side .* with .* backslash-n" actual
 '
 
+test_expect_success 'format-patch empty commit' '
+	git format-patch --stdout main..empty >empty &&
+	grep "^From " empty >from &&
+	test_line_count = 1 from
+'
+
 test_expect_success 'extra headers' '
 	git config format.headers "To: R E Cipient <rcipient@example.com>
 " &&
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] format-patch: output header for empty commits
  2023-03-03 16:03 [PATCH] format-patch: output header for empty commits John Keeping
@ 2023-03-03 17:13 ` Junio C Hamano
  2023-03-04 10:45   ` John Keeping
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2023-03-03 17:13 UTC (permalink / raw)
  To: John Keeping; +Cc: git

John Keeping <john@keeping.me.uk> writes:

> When formatting an empty commit, it is surprising that a totally empty
> file is generated.  Set the flag to always print the header, matching
> the behaviour of git-log.

Don't these empty files help send-email as safety against sending
them out?  Unless existing tools depend on the current behaviour in
such a way, I think this is quite a sensible change.

> diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
> index f3313b8c58..ffc7c60680 100755
> --- a/t/t4014-format-patch.sh
> +++ b/t/t4014-format-patch.sh
> @@ -59,6 +59,10 @@ test_expect_success setup '
>  	test_tick &&
>  	git commit -m "patchid 3" &&
>  
> +	git checkout -b empty main &&
> +	test_tick &&
> +	git commit --allow-empty -m "empty commit" &&
> +
>  	git checkout main
>  '
>  
> @@ -128,6 +132,12 @@ test_expect_success 'replay did not screw up the log message' '
>  	grep "^Side .* with .* backslash-n" actual
>  '
>  
> +test_expect_success 'format-patch empty commit' '
> +	git format-patch --stdout main..empty >empty &&
> +	grep "^From " empty >from &&
> +	test_line_count = 1 from
> +'
> +
>  test_expect_success 'extra headers' '
>  	git config format.headers "To: R E Cipient <rcipient@example.com>
>  " &&

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] format-patch: output header for empty commits
  2023-03-03 17:13 ` Junio C Hamano
@ 2023-03-04 10:45   ` John Keeping
  2023-03-06 17:08     ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: John Keeping @ 2023-03-04 10:45 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Fri, Mar 03, 2023 at 09:13:27AM -0800, Junio C Hamano wrote:
> John Keeping <john@keeping.me.uk> writes:
> 
> > When formatting an empty commit, it is surprising that a totally empty
> > file is generated.  Set the flag to always print the header, matching
> > the behaviour of git-log.
> 
> Don't these empty files help send-email as safety against sending
> them out?  Unless existing tools depend on the current behaviour in
> such a way, I think this is quite a sensible change.

Yes, send-email fails trying to send an empty file, but to me this feels
more like an accident than an intentional safeguard.  If there were
something intentional I'd expect format-patch to fail with --allow-empty
as an option to bypass that safety check.

Since there are checks in place to avoid unintentionally creating empty
commits, it seems reasonable for format-patch to create output that
represents what is present in the repository without needing extra
options.

> > diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
> > index f3313b8c58..ffc7c60680 100755
> > --- a/t/t4014-format-patch.sh
> > +++ b/t/t4014-format-patch.sh
> > @@ -59,6 +59,10 @@ test_expect_success setup '
> >  	test_tick &&
> >  	git commit -m "patchid 3" &&
> >  
> > +	git checkout -b empty main &&
> > +	test_tick &&
> > +	git commit --allow-empty -m "empty commit" &&
> > +
> >  	git checkout main
> >  '
> >  
> > @@ -128,6 +132,12 @@ test_expect_success 'replay did not screw up the log message' '
> >  	grep "^Side .* with .* backslash-n" actual
> >  '
> >  
> > +test_expect_success 'format-patch empty commit' '
> > +	git format-patch --stdout main..empty >empty &&
> > +	grep "^From " empty >from &&
> > +	test_line_count = 1 from
> > +'
> > +
> >  test_expect_success 'extra headers' '
> >  	git config format.headers "To: R E Cipient <rcipient@example.com>
> >  " &&

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] format-patch: output header for empty commits
  2023-03-04 10:45   ` John Keeping
@ 2023-03-06 17:08     ` Junio C Hamano
  2023-03-08 20:33       ` John Keeping
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2023-03-06 17:08 UTC (permalink / raw)
  To: John Keeping; +Cc: git

John Keeping <john@keeping.me.uk> writes:

> On Fri, Mar 03, 2023 at 09:13:27AM -0800, Junio C Hamano wrote:
>> John Keeping <john@keeping.me.uk> writes:
>> 
>> > When formatting an empty commit, it is surprising that a totally empty
>> > file is generated.  Set the flag to always print the header, matching
>> > the behaviour of git-log.
>> 
>> Don't these empty files help send-email as safety against sending
>> them out?  Unless existing tools depend on the current behaviour in
>> such a way, I think this is quite a sensible change.
>
> Yes, send-email fails trying to send an empty file, but to me this feels
> more like an accident than an intentional safeguard.  If there were
> something intentional I'd expect format-patch to fail with --allow-empty
> as an option to bypass that safety check.
>
> Since there are checks in place to avoid unintentionally creating empty
> commits,...

Speaking as the original implementer of format-patch, the original
intention was to forbid such a message to be sent out.  But it was
designed back in the days when an empty commit were not used as "a
marker in the history" as widely as these days.  IOW, the original
intention does not matter all that much when we have to determine if
the code with the proposed change would negatively affect _today's_
users.  What the users would see is that they have been protected
from sending out such a message by mistake (an empty commit may not
be something you created but you pulled from your colleages), but
with this change the protection is no longer there.

Another worry is if the receiving end is prepared to see such a
"patch".

Overall, if we were designing format-patch/send-email/am today with
today's use cases in mind without any existing users of these three
commands, I think these three would be designed to pass an empty
commit through the chain unconditionally.  But we do not live in
such a world, so perhaps some sort of opting in may be appropriate.

Thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] format-patch: output header for empty commits
  2023-03-06 17:08     ` Junio C Hamano
@ 2023-03-08 20:33       ` John Keeping
  2023-03-08 20:43         ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: John Keeping @ 2023-03-08 20:33 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Mon, Mar 06, 2023 at 09:08:44AM -0800, Junio C Hamano wrote:
> John Keeping <john@keeping.me.uk> writes:
> 
> > On Fri, Mar 03, 2023 at 09:13:27AM -0800, Junio C Hamano wrote:
> >> John Keeping <john@keeping.me.uk> writes:
> >> 
> >> > When formatting an empty commit, it is surprising that a totally empty
> >> > file is generated.  Set the flag to always print the header, matching
> >> > the behaviour of git-log.
> >> 
> >> Don't these empty files help send-email as safety against sending
> >> them out?  Unless existing tools depend on the current behaviour in
> >> such a way, I think this is quite a sensible change.
> >
> > Yes, send-email fails trying to send an empty file, but to me this feels
> > more like an accident than an intentional safeguard.  If there were
> > something intentional I'd expect format-patch to fail with --allow-empty
> > as an option to bypass that safety check.
> >
> > Since there are checks in place to avoid unintentionally creating empty
> > commits,...
> 
> Speaking as the original implementer of format-patch, the original
> intention was to forbid such a message to be sent out.  But it was
> designed back in the days when an empty commit were not used as "a
> marker in the history" as widely as these days.  IOW, the original
> intention does not matter all that much when we have to determine if
> the code with the proposed change would negatively affect _today's_
> users.  What the users would see is that they have been protected
> from sending out such a message by mistake (an empty commit may not
> be something you created but you pulled from your colleages), but
> with this change the protection is no longer there.
> 
> Another worry is if the receiving end is prepared to see such a
> "patch".
> 
> Overall, if we were designing format-patch/send-email/am today with
> today's use cases in mind without any existing users of these three
> commands, I think these three would be designed to pass an empty
> commit through the chain unconditionally.  But we do not live in
> such a world, so perhaps some sort of opting in may be appropriate.

Does that mean you want to see format-patch die on empty commits unless
--allow-empty is specified?

I think it's in a slightly strange place because it's both a "creation"
command and an "inspection" command.  Elsewhere the creation commands
(like commit or cherry-pick) require --allow-empty but inspection
commands (like log or show) always show all commits.

My mental model groups format-patch in the inspection commands and I
wouldn't send anything out without inspecting the patch files first (but
then I get caught out by this empty commit behaviour when I use
format-patch for non-email use and grep doesn't find something I'm sure
should be there in an empty commit's message!).

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] format-patch: output header for empty commits
  2023-03-08 20:33       ` John Keeping
@ 2023-03-08 20:43         ` Junio C Hamano
  0 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2023-03-08 20:43 UTC (permalink / raw)
  To: John Keeping; +Cc: git

John Keeping <john@keeping.me.uk> writes:

>> Overall, if we were designing format-patch/send-email/am today with
>> today's use cases in mind without any existing users of these three
>> commands, I think these three would be designed to pass an empty
>> commit through the chain unconditionally.  But we do not live in
>> such a world, so perhaps some sort of opting in may be appropriate.
>
> Does that mean you want to see format-patch die on empty commits unless
> --allow-empty is specified?

No, what I (with Devil's advocate hat on) suggested was to hide the
"instead of leaving an empty file, fill the file with the log message"
feature this patch adds behind --allow-empty option, and when the
option is not given, keep the current behaviour.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-03-08 20:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-03 16:03 [PATCH] format-patch: output header for empty commits John Keeping
2023-03-03 17:13 ` Junio C Hamano
2023-03-04 10:45   ` John Keeping
2023-03-06 17:08     ` Junio C Hamano
2023-03-08 20:33       ` John Keeping
2023-03-08 20:43         ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.