{"thread":{"id":"27495","subject":"Using really empty start prefixes for git-format-patch numbered patches?","startedAt":"2011-05-28T21:57:01Z","lastAt":"2011-05-30T20:23:02Z","messageCount":5,"participants":["Frédéric Delanoy","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"168932","messageId":"BANLkTikVQWN2kZ4gc8kd-kJWZhLXgkvTAA@mail.gmail.com","threadId":"27495","inReplyTo":null,"subject":"Using really empty start prefixes for git-format-patch numbered patches?","fromName":"Frédéric Delanoy","fromEmail":"frederic.delanoy@gmail.com","sentAt":"2011-05-28T21:57:01Z","receivedAt":"2011-05-28T21:57:01Z","isPatch":false,"sender":{"key":"frederic.delanoy@gmail.com","avatar":null},"body":"Hi,\n\nI'm trying to generate numbered patches using git-format-patch such\nthat I get e.g. [1/2] instead of [PATCH 1/2]\n\nHowever, if I use an empty string as prefix, for instance in\n\ngit-format-patch --subject-prefix=\"\" -2\n\nan extraneous space is inserted, and I get [ 1/2] instead of desired\n[1/2] in the Subject line\n\n(I also tried using a single backspace char as prefix, but that didn't\nchange anything, as might have been expected)\n\nIs there a way to get rid of this space? IMO the space should only be\nadded if the prefix is non-empty\n\nFrédéric Delanoy\n"},{"id":"168993","messageId":"BANLkTikUECxikNKmYX1qoXvz1xmYRRtfUg@mail.gmail.com","threadId":"27495","inReplyTo":"BANLkTikVQWN2kZ4gc8kd-kJWZhLXgkvTAA@mail.gmail.com","subject":"Re: Using really empty start prefixes for git-format-patch numbered patches?","fromName":"Frédéric Delanoy","fromEmail":"frederic.delanoy@gmail.com","sentAt":"2011-05-30T13:04:13Z","receivedAt":"2011-05-30T13:04:13Z","isPatch":false,"sender":{"key":"frederic.delanoy@gmail.com","avatar":null},"body":"Is this a bug or a feature?\n\n2011/5/28 Frédéric Delanoy <frederic.delanoy@gmail.com>:\n> Hi,\n>\n> I'm trying to generate numbered patches using git-format-patch such\n> that I get e.g. [1/2] instead of [PATCH 1/2]\n>\n> However, if I use an empty string as prefix, for instance in\n>\n> git-format-patch --subject-prefix=\"\" -2\n>\n> an extraneous space is inserted, and I get [ 1/2] instead of desired\n> [1/2] in the Subject line\n>\n> (I also tried using a single backspace char as prefix, but that didn't\n> change anything, as might have been expected)\n>\n> Is there a way to get rid of this space? IMO the space should only be\n> added if the prefix is non-empty\n>\n> Frédéric Delanoy\n>\n"},{"id":"168995","messageId":"20110530141905.GA31490@sigill.intra.peff.net","threadId":"27495","inReplyTo":"BANLkTikVQWN2kZ4gc8kd-kJWZhLXgkvTAA@mail.gmail.com","subject":"Re: Using really empty start prefixes for git-format-patch numbered patches?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-05-30T14:19:05Z","receivedAt":"2011-05-30T14:19:05Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, May 28, 2011 at 11:57:01PM +0200, Frédéric Delanoy wrote:\n\n> I'm trying to generate numbered patches using git-format-patch such\n> that I get e.g. [1/2] instead of [PATCH 1/2]\n> \n> However, if I use an empty string as prefix, for instance in\n> \n> git-format-patch --subject-prefix=\"\" -2\n> \n> an extraneous space is inserted, and I get [ 1/2] instead of desired\n> [1/2] in the Subject line\n> \n> (I also tried using a single backspace char as prefix, but that didn't\n> change anything, as might have been expected)\n> \n> Is there a way to get rid of this space? IMO the space should only be\n> added if the prefix is non-empty\n\nI don't think there is currently a way to do what you want short of\npost-processing the output of format-patch. You can use \"-k\" to preserve\nthe subject, but then you don't get the \"1/2\" that you want.\n\nSo I think we should do this:\n\n-- >8 --\nSubject: [PATCH] format-patch: make zero-length subject prefixes prettier\n\nIf you give a zero-length subject prefix to format-patch\n(e.g., \"format-patch --subject-prefix=\"), we will print the\nugly:\n\n  Subject: [ 1/2] your subject here\n\nbecause we always insert a space between the prefix and\nnumbering. Requiring the user to provide the space in their\nprefix would be more flexible, but would break existing\nusage. This patch provides a DWIM and suppresses the space\nfor zero-length prefixes, under the assumption that nobody\nactually wants \"[ 1/2]\".\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n log-tree.c              |    3 ++-\n t/t4014-format-patch.sh |   18 ++++++++++++++++++\n 2 files changed, 20 insertions(+), 1 deletions(-)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex 2a1e3a9..296f417 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -294,8 +294,9 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,\n \tif (opt->total > 0) {\n \t\tstatic char buffer[64];\n \t\tsnprintf(buffer, sizeof(buffer),\n-\t\t\t \"Subject: [%s %0*d/%d] \",\n+\t\t\t \"Subject: [%s%s%0*d/%d] \",\n \t\t\t opt->subject_prefix,\n+\t\t\t *opt->subject_prefix ? \" \" : \"\",\n \t\t\t digits_in_number(opt->total),\n \t\t\t opt->nr, opt->total);\n \t\tsubject = buffer;\ndiff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\nindex 045cee3..92248d2 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -851,4 +851,22 @@ test_expect_success 'subject lines do not have 822 atom-quoting' '\n \ttest_cmp expect actual\n '\n \n+cat >expect <<'EOF'\n+Subject: [PREFIX 1/1] header with . in it\n+EOF\n+test_expect_success 'subject prefixes have space prepended' '\n+\tgit format-patch -n -1 --stdout --subject-prefix=PREFIX >patch &&\n+\tgrep ^Subject: patch >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+cat >expect <<'EOF'\n+Subject: [1/1] header with . in it\n+EOF\n+test_expect_success 'empty subject prefix does not have extra space' '\n+\tgit format-patch -n -1 --stdout --subject-prefix= >patch &&\n+\tgrep ^Subject: patch >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n1.7.5.3.12.g99e25\n"},{"id":"169017","messageId":"7voc2km1xh.fsf@alter.siamese.dyndns.org","threadId":"27495","inReplyTo":"20110530141905.GA31490@sigill.intra.peff.net","subject":"Re: Using really empty start prefixes for git-format-patch numbered patches?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-05-30T19:19:22Z","receivedAt":"2011-05-30T19:19:22Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> I don't think there is currently a way to do what you want short of\n> post-processing the output of format-patch. You can use \"-k\" to preserve\n> the subject, but then you don't get the \"1/2\" that you want.\n\nYou would unconditionally get \"[\" and \"]\" that you may or may not want and\nthere is no way to change it to \"(1/2)\" or \"1 of 2: \"; unless we shoot for\na completely flexible solution, we need to draw a line somewhere.\n\nIt was not optimal in the hindsight to draw the line where the prefix is\ncustomizable, while always assuming that people would want some prefix,\nperhaps.\n\n> So I think we should do this:\n\nYes, ...\n\n> ... under the assumption that nobody\n> actually wants \"[ 1/2]\".\n\nwhich I think is a reasonable thing to do.\n\nWill queue; thanks.\n"},{"id":"169024","messageId":"20110530202302.GA29811@sigill.intra.peff.net","threadId":"27495","inReplyTo":"7voc2km1xh.fsf@alter.siamese.dyndns.org","subject":"Re: Using really empty start prefixes for git-format-patch numbered patches?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-05-30T20:23:02Z","receivedAt":"2011-05-30T20:23:02Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, May 30, 2011 at 12:19:22PM -0700, Junio C Hamano wrote:\n\n> Jeff King <peff@peff.net> writes:\n> \n> > I don't think there is currently a way to do what you want short of\n> > post-processing the output of format-patch. You can use \"-k\" to preserve\n> > the subject, but then you don't get the \"1/2\" that you want.\n> \n> You would unconditionally get \"[\" and \"]\" that you may or may not want and\n> there is no way to change it to \"(1/2)\" or \"1 of 2: \"; unless we shoot for\n> a completely flexible solution, we need to draw a line somewhere.\n\nHmm, yeah, I guess we could go farther pretty simply with:\n\n  git format-patch --subject='[PATCH %n/%m] %s'\n\nbut I admit I don't really care enough to work on it. :)\n\n> Will queue; thanks.\n\nThanks.\n\n-Peff\n"}]}