Skip to contentSkip to conversation

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

PATCH Superseded Jacob Keller 3 participants 5 messages Aug 19, 2016 – Aug 23, 2016

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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

From: Jacob Keller <[email protected]>

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.

---
 builtin/log.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/log.c +1 -1
index 92dc34dcb0cc..8e6100fb0c5b 100644
@@ -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;
Signature · 1 line
2.10.0.rc0.259.g83512d9
#1 lore raw
Quoted 11 lines · Jacob Keller

From: Jacob Keller <[email protected]>

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.

---

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

Quoted 16 lines
 builtin/log.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/log.c +1 -1
index 92dc34dcb0cc..8e6100fb0c5b 100644
@@ -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 lore raw
Quoted 11 lines · Junio C Hamano
Quoted 9 lines · Jacob Keller

From: Jacob Keller <[email protected]>

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.

Quoted 6 lines
Quoted 2 lines

---

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

#4 lore raw
In reply to Junio C Hamano
Quoted 8 lines · Junio C Hamano
Quoted 6 lines · Junio C Hamano

Review

Quoted 6 lines
     total = nr;
(quoted diff) +1 -1
-    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;
Quoted 8 lines

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.

Quoted 5 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

Quoted 28 lines
 builtin/log.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
builtin/log.c +4 -4
index e50d361..b7bfeb9 100644
@@ -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 */
#3 lore raw
In reply to Junio C Hamano
Quoted 16 lines · Junio C Hamano

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

builtin/log.c int cmd_format_patch(int argc, const char **argv, const char *prefix) · line 1682

Quoted 13 lines
builtin/log.c +1 -1
index 92dc34dcb0cc..8e6100fb0c5b 100644
@@ -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(-)
builtin/log.c +4 -4
index e50d361..b7bfeb9 100644
@@ -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 */