From: Jeff King <peff@peff.net>
To: "Michał Górny" <mgorny@gentoo.org>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
Michael J Gruber <git@drmicha.warpmail.net>
Subject: [PATCH 4/5] for-each-ref: handle multiline subjects like --pretty
Date: Wed, 7 Sep 2011 13:44:56 -0400 [thread overview]
Message-ID: <20110907174456.GD11355@sigill.intra.peff.net> (raw)
In-Reply-To: <20110902175323.GA29761@sigill.intra.peff.net>
Generally the format of a git tag or commit message is:
subject
body body body
body body body
However, we occasionally see multiline subjects like:
subject
with multiple
lines
body body body
body body body
The rest of git treats these multiline subjects as something
to be concatenated and shown as a single line (e.g., "git
log --pretty=format:%s" will do so since f53bd74). For
consistency, for-each-ref should do the same with its
"%(subject)".
Signed-off-by: Jeff King <peff@peff.net>
---
I split this out from the signature patch to make it more obvious what's
going on.
builtin/for-each-ref.c | 29 ++++++++++++++++++++++++-----
t/t6300-for-each-ref.sh | 21 +++++++++++++++++++++
2 files changed, 45 insertions(+), 5 deletions(-)
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index bcea027..ea2112b 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -361,6 +361,18 @@ static const char *copy_email(const char *buf)
return xmemdupz(email, eoemail + 1 - email);
}
+static char *copy_subject(const char *buf, unsigned long len)
+{
+ char *r = xmemdupz(buf, len);
+ int i;
+
+ for (i = 0; i < len; i++)
+ if (r[i] == '\n')
+ r[i] = ' ';
+
+ return r;
+}
+
static void grab_date(const char *buf, struct atom_value *v, const char *atomname)
{
const char *eoemail = strstr(buf, "> ");
@@ -476,10 +488,17 @@ static void find_subpos(const char *buf, unsigned long sz,
/* subject is first non-empty line */
*sub = buf;
- /* subject goes to end of line */
- eol = strchrnul(buf, '\n');
- *sublen = eol - buf;
- buf = eol;
+ /* subject goes to first empty line */
+ while (*buf && *buf != '\n') {
+ eol = strchrnul(buf, '\n');
+ if (*eol)
+ eol++;
+ buf = eol;
+ }
+ *sublen = buf - *sub;
+ /* drop trailing newline, if present */
+ if (*sublen && (*sub)[*sublen - 1] == '\n')
+ *sublen -= 1;
/* skip any empty lines */
while (*buf == '\n')
@@ -512,7 +531,7 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, struct obj
&bodypos, &bodylen);
if (!strcmp(name, "subject"))
- v->s = xmemdupz(subpos, sublen);
+ v->s = copy_subject(subpos, sublen);
else if (!strcmp(name, "body"))
v->s = xmemdupz(bodypos, bodylen);
else if (!strcmp(name, "contents"))
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index 6fa4d52..0c9ff96 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -379,4 +379,25 @@ first body line
second body line
'
+test_expect_success 'create tag with multiline subject' '
+ cat >msg <<-\EOF &&
+ first subject line
+ second subject line
+
+ first body line
+ second body line
+ EOF
+ git tag -F msg multiline
+'
+test_atom refs/tags/multiline subject 'first subject line second subject line'
+test_atom refs/tags/multiline body 'first body line
+second body line
+'
+test_atom refs/tags/multiline contents 'first subject line
+second subject line
+
+first body line
+second body line
+'
+
test_done
--
1.7.6.10.g62f04
next prev parent reply other threads:[~2011-09-07 17:45 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-29 19:10 More formatting with 'git tag -l' Michał Górny
2011-08-29 19:36 ` Jeff King
2011-08-29 21:20 ` Michał Górny
2011-08-29 21:37 ` Jeff King
2011-08-29 21:50 ` Michał Górny
2011-08-30 8:57 ` [PATCH] git-for-each-ref: move GPG sigs off %(body) to %(signature) Michał Górny
2011-08-30 9:43 ` Michael J Gruber
2011-08-30 15:58 ` Michał Górny
2011-08-30 16:27 ` Jeff King
2011-08-31 9:11 ` [PATCH] for-each-ref: add split message parts to %(contents:*) Michał Górny
2011-08-31 16:42 ` Jeff King
2011-08-31 16:44 ` [PATCH 1/2] t7004: factor out gpg setup Jeff King
2011-08-31 16:44 ` [PATCH 2/2] t6300: test new content:* for-each-ref placeholders Jeff King
2011-08-31 22:54 ` [PATCH] for-each-ref: add split message parts to %(contents:*) Junio C Hamano
2011-08-31 23:22 ` Jeff King
2011-09-01 7:34 ` Michał Górny
2011-09-01 16:00 ` Junio C Hamano
2011-09-01 16:22 ` Jeff King
2011-09-01 16:48 ` Michał Górny
2011-09-01 16:50 ` Michał Górny
2011-09-02 16:39 ` Jeff King
2011-09-02 17:39 ` Michał Górny
2011-09-02 17:53 ` Jeff King
2011-09-07 17:40 ` Jeff King
2011-09-15 8:18 ` Michał Górny
2011-09-07 17:42 ` [PATCH 1/5] t7004: factor out gpg setup Jeff King
2011-09-07 17:43 ` [PATCH 2/5] t6300: add more body-parsing tests Jeff King
2011-09-07 17:44 ` [PATCH 3/5] for-each-ref: refactor subject and body placeholder parsing Jeff King
2011-09-07 17:44 ` Jeff King [this message]
2011-09-07 17:46 ` [PATCH 5/5] for-each-ref: add split message parts to %(contents:*) Jeff King
2011-09-01 17:16 ` [PATCH] " Junio C Hamano
2011-09-01 18:19 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110907174456.GD11355@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@drmicha.warpmail.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mgorny@gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).