summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fb674d7)
raw | patch | inline | side by side (parent: fb674d7)
author | Jeff King <peff@peff.net> | |
Mon, 30 May 2011 14:19:05 +0000 (10:19 -0400) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 30 May 2011 18:18:59 +0000 (11:18 -0700) |
If you give a zero-length subject prefix to format-patch
(e.g., "format-patch --subject-prefix="), we will print the
ugly:
Subject: [ 1/2] your subject here
because we always insert a space between the prefix and
numbering. Requiring the user to provide the space in their
prefix would be more flexible, but would break existing
usage. This patch provides a DWIM and suppresses the space
for zero-length prefixes, under the assumption that nobody
actually wants "[ 1/2]".
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
(e.g., "format-patch --subject-prefix="), we will print the
ugly:
Subject: [ 1/2] your subject here
because we always insert a space between the prefix and
numbering. Requiring the user to provide the space in their
prefix would be more flexible, but would break existing
usage. This patch provides a DWIM and suppresses the space
for zero-length prefixes, under the assumption that nobody
actually wants "[ 1/2]".
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
log-tree.c | patch | blob | history | |
t/t4014-format-patch.sh | patch | blob | history |
diff --git a/log-tree.c b/log-tree.c
index 2a1e3a94c910cd74e41303d8b7aefa539817c831..296f417dfcc2fe966527064aa4a95dc96a8eca2d 100644 (file)
--- a/log-tree.c
+++ b/log-tree.c
if (opt->total > 0) {
static char buffer[64];
snprintf(buffer, sizeof(buffer),
- "Subject: [%s %0*d/%d] ",
+ "Subject: [%s%s%0*d/%d] ",
opt->subject_prefix,
+ *opt->subject_prefix ? " " : "",
digits_in_number(opt->total),
opt->nr, opt->total);
subject = buffer;
index 045cee312cdeb515869eeeda3f7b167fb5b91504..92248d24c48a65ab89a5b0ad255357f6034e6ad4 100755 (executable)
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
test_cmp expect actual
'
+cat >expect <<'EOF'
+Subject: [PREFIX 1/1] header with . in it
+EOF
+test_expect_success 'subject prefixes have space prepended' '
+ git format-patch -n -1 --stdout --subject-prefix=PREFIX >patch &&
+ grep ^Subject: patch >actual &&
+ test_cmp expect actual
+'
+
+cat >expect <<'EOF'
+Subject: [1/1] header with . in it
+EOF
+test_expect_success 'empty subject prefix does not have extra space' '
+ git format-patch -n -1 --stdout --subject-prefix= >patch &&
+ grep ^Subject: patch >actual &&
+ test_cmp expect actual
+'
+
test_done