for-each-ref: handle multiline subjects like --pretty
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>
maint
parent
7ec0f31eec
commit
7f6e275bc0
|
|
@ -361,6 +361,18 @@ static const char *copy_email(const char *buf)
|
||||||
return xmemdupz(email, eoemail + 1 - email);
|
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)
|
static void grab_date(const char *buf, struct atom_value *v, const char *atomname)
|
||||||
{
|
{
|
||||||
const char *eoemail = strstr(buf, "> ");
|
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 */
|
/* subject is first non-empty line */
|
||||||
*sub = buf;
|
*sub = buf;
|
||||||
/* subject goes to end of line */
|
/* subject goes to first empty line */
|
||||||
eol = strchrnul(buf, '\n');
|
while (*buf && *buf != '\n') {
|
||||||
*sublen = eol - buf;
|
eol = strchrnul(buf, '\n');
|
||||||
buf = eol;
|
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 */
|
/* skip any empty lines */
|
||||||
while (*buf == '\n')
|
while (*buf == '\n')
|
||||||
|
|
@ -512,7 +531,7 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, struct obj
|
||||||
&bodypos, &bodylen);
|
&bodypos, &bodylen);
|
||||||
|
|
||||||
if (!strcmp(name, "subject"))
|
if (!strcmp(name, "subject"))
|
||||||
v->s = xmemdupz(subpos, sublen);
|
v->s = copy_subject(subpos, sublen);
|
||||||
else if (!strcmp(name, "body"))
|
else if (!strcmp(name, "body"))
|
||||||
v->s = xmemdupz(bodypos, bodylen);
|
v->s = xmemdupz(bodypos, bodylen);
|
||||||
else if (!strcmp(name, "contents"))
|
else if (!strcmp(name, "contents"))
|
||||||
|
|
|
||||||
|
|
@ -379,4 +379,25 @@ first body line
|
||||||
second 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
|
test_done
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue