summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7ec0f31)
raw | patch | inline | side by side (parent: 7ec0f31)
author | Jeff King <peff@peff.net> | |
Wed, 7 Sep 2011 17:44:56 +0000 (13:44 -0400) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Thu, 8 Sep 2011 20:52:00 +0000 (13:52 -0700) |
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/for-each-ref.c | patch | blob | history | |
t/t6300-for-each-ref.sh | patch | blob | history |
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index bcea0276f3ed8095082c359e02e5952266be953d..ea2112b3881e3c3b791dad0c0b9996a7648e41bd 100644 (file)
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
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, "> ");
/* 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"))
index 6fa4d52740a96898b6274f463defd6a78c74b389..0c9ff96dbed61807483b44358cb9f97a817c57de 100755 (executable)
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
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