Add a newline before appending "Signed-off-by: " line
Whef the last line of the commit log message does not end with "^[-A-Za-z]+: [^@]+@", append a newline after it to separate the body of the commit log message from the run of sign-off and ack lines. e.g. "Signed-off-by: A U Thor <au.thor@example.com>" or "Acked-by: Me <myself@example.org>". Signed-off-by: Junio C Hamano <junkio@cox.net>
Franck Bui-Huu committed
Aug 13, 2006 at 11:30 UTC
c35f4c371ac12f4d29b08e46c519ddc0a6494f6e
1 file changed
+43
-1
log-tree.c
+43
-1
@@ -19,7 +19,7 @@ static int append_signoff(char *buf, int buf_sz, int at, const char *signoff)
19
char *cp = buf;
20
21
/* 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)
23
return at;
24
25
/* 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)
34
return at; /* we already have him */
35
}
36
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
+
79
strcpy(buf + at, signed_off_by);
80
at += strlen(signed_off_by);
81
strcpy(buf + at, signoff);