threads / patch / 43890

patchformat-patch: show 0/1 and 1/1 for singleton patch with cover letter

Subject: [PATCH] format-patch: show 0/1 and 1/1 for singleton patch with cover letter

## tl;dr

5 messages between Aug 19, 2016 and Aug 23, 2016. Diffs are folded; open one to read it.

replies: 4people: 3as markdown or json

Jacob Keller· Aug 19, 2016, 23:49 UTC · lore
From: Jacob Keller <jacob.keller@gmail.com>

Change the default behavior of git-format-patch to generate numbered sequence of 0/1 and 1/1 when generating both a cover-letter and a single patch. This standardizes the cover letter to have 0/N which helps distinguish the cover letter from the patch itself. Since the behavior is easily changed via configuration as well as the use of -n and -N this should be acceptable default behavior.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
---
 builtin/log.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to builtin/log.c +1 −1
diff --git a/builtin/log.c b/builtin/log.c
index 92dc34dcb0cc..8e6100fb0c5b 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1676,7 +1676,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		/* nothing to do */
 		return 0;
 	total = nr;
-	if (!keep_subject && auto_number && total > 1)
+	if (!keep_subject && auto_number && (total > 1 || cover_letter))
 		numbered = 1;
 	if (numbered)
 		rev.total = total + start_number - 1;
-- 
2.10.0.rc0.259.g83512d9
Junio C Hamano· Aug 23, 2016, 16:33 UTC · re: Jacob Keller · lore

Re: [PATCH] format-patch: show 0/1 and 1/1 for singleton patch with cover letter

Jacob Keller <jacob.e.keller@intel.com> writes:
Show 11 quoted lines
> From: Jacob Keller <jacob.keller@gmail.com>
>
> Change the default behavior of git-format-patch to generate numbered
> sequence of 0/1 and 1/1 when generating both a cover-letter and a single
> patch. This standardizes the cover letter to have 0/N which helps
> distinguish the cover letter from the patch itself. Since the behavior
> is easily changed via configuration as well as the use of -n and -N this
> should be acceptable default behavior.
>
> Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
> ---

This obviously changes the behaviour, but I do not think of a reason why this change is a bad idea.

Show 16 quoted lines
>  builtin/log.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/builtin/log.c b/builtin/log.c
> index 92dc34dcb0cc..8e6100fb0c5b 100644
> --- a/builtin/log.c
> +++ b/builtin/log.c
> @@ -1676,7 +1676,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
>  		/* nothing to do */
>  		return 0;
>  	total = nr;
> -	if (!keep_subject && auto_number && total > 1)
> +	if (!keep_subject && auto_number && (total > 1 || cover_letter))
>  		numbered = 1;
>  	if (numbered)
>  		rev.total = total + start_number - 1;
Jacob Keller· Aug 23, 2016, 21:06 UTC · re: Junio C Hamano · lore

Re: [PATCH] format-patch: show 0/1 and 1/1 for singleton patch with cover letter

On Tue, Aug 23, 2016 at 9:33 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 17 quoted lines
> Jacob Keller <jacob.e.keller@intel.com> writes:
>
>> From: Jacob Keller <jacob.keller@gmail.com>
>>
>> Change the default behavior of git-format-patch to generate numbered
>> sequence of 0/1 and 1/1 when generating both a cover-letter and a single
>> patch. This standardizes the cover letter to have 0/N which helps
>> distinguish the cover letter from the patch itself. Since the behavior
>> is easily changed via configuration as well as the use of -n and -N this
>> should be acceptable default behavior.
>>
>> Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
>> ---
>
> This obviously changes the behaviour, but I do not think of a reason
> why this change is a bad idea.
>

Yes. The basic idea is "number all files outputted if we generate more than 1 file" Since a cover letter is a separate file, we number 0/1 and 1/1.

Thanks, Jake

Junio C Hamano· Aug 23, 2016, 21:21 UTC · re: Junio C Hamano · lore

Re: [PATCH] format-patch: show 0/1 and 1/1 for singleton patch with cover letter

Junio C Hamano <gitster@pobox.com> writes:
> This obviously changes the behaviour, but I do not think of a reason
> why this change is a bad idea.  
Show 13 quoted lines
>> diff --git a/builtin/log.c b/builtin/log.c
>> index 92dc34dcb0cc..8e6100fb0c5b 100644
>> --- a/builtin/log.c
>> +++ b/builtin/log.c
>> @@ -1676,7 +1676,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
>>  		/* nothing to do */
>>  		return 0;
>>  	total = nr;
>> -	if (!keep_subject && auto_number && total > 1)
>> +	if (!keep_subject && auto_number && (total > 1 || cover_letter))
>>  		numbered = 1;
>>  	if (numbered)
>>  		rev.total = total + start_number - 1;

Actually there is a very good reason why this patch is not good (yet). When the --cover option is not specified on the command line, cover_letter is -1 (use configuration or turn it on only when it is a multi-patch series) at this point.

I think you would have noticed it if you ran any format-patch tests. t/t4021-format-patch-numbered.sh fails at the very beginning.

With the attached SQUASH, existing tests pass, which is a strong sign that this new feature needs to be protected by a new test in the t4021 script to make sure other people would not break it in the future.

 builtin/log.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Show changes to builtin/log.c +4 −4
diff --git a/builtin/log.c b/builtin/log.c
index e50d361..b7bfeb9 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1650,16 +1650,16 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		/* nothing to do */
 		return 0;
 	total = nr;
-	if (!keep_subject && auto_number && (total > 1 || cover_letter))
-		numbered = 1;
-	if (numbered)
-		rev.total = total + start_number - 1;
 	if (cover_letter == -1) {
 		if (config_cover_letter == COVER_AUTO)
 			cover_letter = (total > 1);
 		else
 			cover_letter = (config_cover_letter == COVER_ON);
 	}
+	if (!keep_subject && auto_number && (total > 1 || cover_letter))
+		numbered = 1;
+	if (numbered)
+		rev.total = total + start_number - 1;
 
 	if (!signature) {
 		; /* --no-signature inhibits all signatures */
Jacob Keller· Aug 23, 2016, 21:28 UTC · re: Junio C Hamano · lore

Re: [PATCH] format-patch: show 0/1 and 1/1 for singleton patch with cover letter

On Tue, Aug 23, 2016 at 2:21 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 16 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
>>>      total = nr;
>>> -    if (!keep_subject && auto_number && total > 1)
>>> +    if (!keep_subject && auto_number && (total > 1 || cover_letter))
>>>              numbered = 1;
>>>      if (numbered)
>>>              rev.total = total + start_number - 1;
>
> Actually there is a very good reason why this patch is not good
> (yet).  When the --cover option is not specified on the command
> line, cover_letter is -1 (use configuration or turn it on only when
> it is a multi-patch series) at this point.
>
> I think you would have noticed it if you ran any format-patch tests.
> t/t4021-format-patch-numbered.sh fails at the very beginning.
>
Oops! Sorry for not running tests.
Show 5 quoted lines
> With the attached SQUASH, existing tests pass, which is a strong
> sign that this new feature needs to be protected by a new test in
> the t4021 script to make sure other people would not break it in the
> future.
>
I'll add a new test and squash your fix in.

Thanks, Jake

Show 28 quoted lines
>  builtin/log.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/builtin/log.c b/builtin/log.c
> index e50d361..b7bfeb9 100644
> --- a/builtin/log.c
> +++ b/builtin/log.c
> @@ -1650,16 +1650,16 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
>                 /* nothing to do */
>                 return 0;
>         total = nr;
> -       if (!keep_subject && auto_number && (total > 1 || cover_letter))
> -               numbered = 1;
> -       if (numbered)
> -               rev.total = total + start_number - 1;
>         if (cover_letter == -1) {
>                 if (config_cover_letter == COVER_AUTO)
>                         cover_letter = (total > 1);
>                 else
>                         cover_letter = (config_cover_letter == COVER_ON);
>         }
> +       if (!keep_subject && auto_number && (total > 1 || cover_letter))
> +               numbered = 1;
> +       if (numbered)
> +               rev.total = total + start_number - 1;
>
>         if (!signature) {
>                 ; /* --no-signature inhibits all signatures */

← back to recent threads