Skip to content

Commit 409d1d2

Browse files
author
Junio C Hamano
committed
Merge branch 'jc/format-patch'
* jc/format-patch: Add a newline before appending "Signed-off-by: " line
2 parents 076a10c + c35f4c3 commit 409d1d2

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

log-tree.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static int append_signoff(char *buf, int buf_sz, int at, const char *signoff)
1919
char *cp = buf;
2020

2121
/* Do we have enough space to add it? */
22-
if (buf_sz - at <= strlen(signed_off_by) + signoff_len + 2)
22+
if (buf_sz - at <= strlen(signed_off_by) + signoff_len + 3)
2323
return at;
2424

2525
/* First see if we already have the sign-off by the signer */
@@ -34,6 +34,48 @@ static int append_signoff(char *buf, int buf_sz, int at, const char *signoff)
3434
return at; /* we already have him */
3535
}
3636

37+
/* Does the last line already end with "^[-A-Za-z]+: [^@]+@"?
38+
* If not, add a blank line to separate the message from
39+
* the run of Signed-off-by: and Acked-by: lines.
40+
*/
41+
{
42+
char ch;
43+
int seen_colon, seen_at, seen_name, seen_head, not_signoff;
44+
seen_colon = 0;
45+
seen_at = 0;
46+
seen_name = 0;
47+
seen_head = 0;
48+
not_signoff = 0;
49+
cp = buf + at;
50+
while (buf <= --cp && (ch = *cp) == '\n')
51+
;
52+
while (!not_signoff && buf <= cp && (ch = *cp--) != '\n') {
53+
if (!seen_at) {
54+
if (ch == '@')
55+
seen_at = 1;
56+
continue;
57+
}
58+
if (!seen_colon) {
59+
if (ch == '@')
60+
not_signoff = 1;
61+
else if (ch == ':')
62+
seen_colon = 1;
63+
else
64+
seen_name = 1;
65+
continue;
66+
}
67+
if (('A' <= ch && ch <= 'Z') ||
68+
('a' <= ch && ch <= 'z') ||
69+
ch == '-') {
70+
seen_head = 1;
71+
continue;
72+
}
73+
not_signoff = 1;
74+
}
75+
if (not_signoff || !seen_head || !seen_name)
76+
buf[at++] = '\n';
77+
}
78+
3779
strcpy(buf + at, signed_off_by);
3880
at += strlen(signed_off_by);
3981
strcpy(buf + at, signoff);

0 commit comments

Comments
 (0)