{"thread":{"id":"5231","subject":"[PATCH] Add a newline before appending \"Signed-off-by: \" line","startedAt":"2006-08-13T22:33:49Z","lastAt":"2006-08-29T11:37:06Z","messageCount":2,"participants":["Junio C Hamano","Franck Bui-Huu"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"25199","messageId":"7vr6zkjmeq.fsf@assigned-by-dhcp.cox.net","threadId":"5231","inReplyTo":null,"subject":"[PATCH] Add a newline before appending \"Signed-off-by: \" line","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-08-13T22:33:49Z","receivedAt":"2006-08-13T22:33:49Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"From: Franck Bui-Huu <vagabon.xyz@gmail.com>\n\nWhef the last line of the commit log message does not end with\n\"^[-A-Za-z]+: [^@]+@\", append a newline after it to separate\nthe body of the commit log message from the run of sign-off and\nack lines. e.g. \"Signed-off-by: A U Thor <au.thor@example.com>\" or\n\"Acked-by: Me <myself@example.org>\".\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n * This is based on one-month old patch from Franck, which was\n   not applied back then, with updates suggested by Linus, but I\n   did not do \"^\\S+:.*@.*$\", which would have caught the last\n   line of the commit log body of this commit itself.  RFC2822\n   \"field-name\" can contain anything other than controls, SP and\n   colon, but I think in practice \"alnum plus dash\" would be a\n   reasonable and safer pattern to use (and we are not dealing\n   with RFC2822 headers here anyway).\n\n   It probably is not worth to do this as a \"bugfix\", so it \n   is queued for \"next\", not for \"maint\".\n\n log-tree.c |   44 +++++++++++++++++++++++++++++++++++++++++++-\n 1 files changed, 43 insertions(+), 1 deletions(-)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex 05ede0c..031af88 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -19,7 +19,7 @@ static int append_signoff(char *buf, int\n \tchar *cp = buf;\n \n \t/* Do we have enough space to add it? */\n-\tif (buf_sz - at <= strlen(signed_off_by) + signoff_len + 2)\n+\tif (buf_sz - at <= strlen(signed_off_by) + signoff_len + 3)\n \t\treturn at;\n \n \t/* First see if we already have the sign-off by the signer */\n@@ -34,6 +34,48 @@ static int append_signoff(char *buf, int\n \t\t\treturn at; /* we already have him */\n \t}\n \n+\t/* Does the last line already end with \"^[-A-Za-z]+: [^@]+@\"?\n+\t * If not, add a blank line to separate the message from\n+\t * the run of Signed-off-by: and Acked-by: lines.\n+\t */\n+\t{\n+\t\tchar ch;\n+\t\tint seen_colon, seen_at, seen_name, seen_head, not_signoff;\n+\t\tseen_colon = 0;\n+\t\tseen_at = 0;\n+\t\tseen_name = 0;\n+\t\tseen_head = 0;\n+\t\tnot_signoff = 0;\n+\t\tcp = buf + at;\n+\t\twhile (buf <= --cp && (ch = *cp) == '\\n')\n+\t\t\t;\n+\t\twhile (!not_signoff && buf <= cp && (ch = *cp--) != '\\n') {\n+\t\t\tif (!seen_at) {\n+\t\t\t\tif (ch == '@')\n+\t\t\t\t\tseen_at = 1;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\tif (!seen_colon) {\n+\t\t\t\tif (ch == '@')\n+\t\t\t\t\tnot_signoff = 1;\n+\t\t\t\telse if (ch == ':')\n+\t\t\t\t\tseen_colon = 1;\n+\t\t\t\telse\n+\t\t\t\t\tseen_name = 1;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\tif (('A' <= ch && ch <= 'Z') ||\n+\t\t\t    ('a' <= ch && ch <= 'z') ||\n+\t\t\t    ch == '-') {\n+\t\t\t\tseen_head = 1;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\tnot_signoff = 1;\n+\t\t}\n+\t\tif (not_signoff || !seen_head || !seen_name)\n+\t\t\tbuf[at++] = '\\n';\n+\t}\n+\n \tstrcpy(buf + at, signed_off_by);\n \tat += strlen(signed_off_by);\n \tstrcpy(buf + at, signoff);\n-- \n1.4.2.g10a6\n"},{"id":"26089","messageId":"44F426E2.7040902@innova-card.com","threadId":"5231","inReplyTo":"7vr6zkjmeq.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Add a newline before appending \"Signed-off-by: \" line","fromName":"Franck Bui-Huu","fromEmail":"vagabon.xyz@gmail.com","sentAt":"2006-08-29T11:37:06Z","receivedAt":"2006-08-29T11:37:06Z","isPatch":true,"sender":{"key":"vagabon.xyz@gmail.com","avatar":null},"body":"Junio,\n\nSorry for replying sooooooo lately.\n\nJunio C Hamano wrote:\n> From: Franck Bui-Huu <vagabon.xyz@gmail.com>\n> \n> Whef the last line of the commit log message does not end with\n> \"^[-A-Za-z]+: [^@]+@\", append a newline after it to separate\n> the body of the commit log message from the run of sign-off and\n> ack lines. e.g. \"Signed-off-by: A U Thor <au.thor@example.com>\" or\n> \"Acked-by: Me <myself@example.org>\".\n> \n> Signed-off-by: Junio C Hamano <junkio@cox.net>\n\nwhat about this patch on top of yours ?\n\n\t\tFranck\n\n-- >8 --\n\nSubject: log-tree.c: cleanup a bit append_signoff()\n\nThis patch clean up append_signoff() by moving specific code that\nlooks up for \"^[-A-Za-z]+: [^@]+@\" pattern into a function.\n\nIt also stops the primary search when the cursor oversteps\n'buf + at' limit.\n\nThis patch changes slightly append_signoff() behaviour too. If we\ndetect any Signed-off-by pattern during the primary search, we\nneedn't to do a pattern research after.\n\nSigned-off-by: Franck Bui-Huu <vagabon.xyz@gmail.com>\n---\n log-tree.c |  116 ++++++++++++++++++++++++++++++++++--------------------------\n 1 files changed, 66 insertions(+), 50 deletions(-)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex 54cdaa4..36f0d75 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -12,10 +12,58 @@ static void show_parents(struct commit *\n \t}\n }\n \n+/*\n+ * Search for \"^[-A-Za-z]+: [^@]+@\" pattern. It usually matches\n+ * Signed-off-by: and Acked-by: lines.\n+ */\n+static int detect_any_signoff(char *letter, int size)\n+{\n+\tchar ch, *cp;\n+\tint seen_colon = 0;\n+\tint seen_at = 0;\n+\tint seen_name = 0;\n+\tint seen_head = 0;\n+\n+\tcp = letter + size;\n+\twhile (letter <= --cp && (ch = *cp) == '\\n')\n+\t\tcontinue;\n+\n+\twhile (letter <= cp) {\n+\t\tch = *cp--;\n+\t\tif (ch == '\\n')\n+\t\t\tbreak;\n+\t\t\n+\t\tif (!seen_at) {\n+\t\t\tif (ch == '@')\n+\t\t\t\tseen_at = 1;\n+\t\t\tcontinue;\n+\t\t}\n+\t\tif (!seen_colon) {\n+\t\t\tif (ch == '@')\n+\t\t\t\treturn 0;\n+\t\t\telse if (ch == ':')\n+\t\t\t\tseen_colon = 1;\n+\t\t\telse\n+\t\t\t\tseen_name = 1;\n+\t\t\tcontinue;\n+\t\t}\n+\t\tif (('A' <= ch && ch <= 'Z') ||\n+\t\t    ('a' <= ch && ch <= 'z') ||\n+\t\t    ch == '-') {\n+\t\t\tseen_head = 1;\n+\t\t\tcontinue;\n+\t\t}\n+\t\t/* no empty last line doens't match */\n+\t\treturn 0;\n+\t}\n+\treturn seen_head && seen_name;\n+}\n+\n static int append_signoff(char *buf, int buf_sz, int at, const char *signoff)\n {\n-\tint signoff_len = strlen(signoff);\n \tstatic const char signed_off_by[] = \"Signed-off-by: \";\n+\tint signoff_len = strlen(signoff);\n+\tint has_signoff = 0;\n \tchar *cp = buf;\n \n \t/* Do we have enough space to add it? */\n@@ -23,58 +71,26 @@ static int append_signoff(char *buf, int\n \t\treturn at;\n \n \t/* First see if we already have the sign-off by the signer */\n-\twhile (1) {\n-\t\tcp = strstr(cp, signed_off_by);\n-\t\tif (!cp)\n-\t\t\tbreak;\n+\twhile ((cp = strstr(cp, signed_off_by))) {\n+\n+\t\thas_signoff = 1;\n+\t\t\n \t\tcp += strlen(signed_off_by);\n-\t\tif ((cp + signoff_len < buf + at) &&\n-\t\t    !strncmp(cp, signoff, signoff_len) &&\n-\t\t    isspace(cp[signoff_len]))\n-\t\t\treturn at; /* we already have him */\n+\t\tif (cp + signoff_len >= buf + at)\n+\t\t\tbreak;\n+\t\tif (strncmp(cp, signoff, signoff_len))\n+\t\t\tcontinue;\n+\t\tif (!isspace(cp[signoff_len]))\n+\t\t\tcontinue;\n+\t\t/* we already have him */\n+\t\treturn at;\n \t}\n \n-\t/* Does the last line already end with \"^[-A-Za-z]+: [^@]+@\"?\n-\t * If not, add a blank line to separate the message from\n-\t * the run of Signed-off-by: and Acked-by: lines.\n-\t */\n-\t{\n-\t\tchar ch;\n-\t\tint seen_colon, seen_at, seen_name, seen_head, not_signoff;\n-\t\tseen_colon = 0;\n-\t\tseen_at = 0;\n-\t\tseen_name = 0;\n-\t\tseen_head = 0;\n-\t\tnot_signoff = 0;\n-\t\tcp = buf + at;\n-\t\twhile (buf <= --cp && (ch = *cp) == '\\n')\n-\t\t\t;\n-\t\twhile (!not_signoff && buf <= cp && (ch = *cp--) != '\\n') {\n-\t\t\tif (!seen_at) {\n-\t\t\t\tif (ch == '@')\n-\t\t\t\t\tseen_at = 1;\n-\t\t\t\tcontinue;\n-\t\t\t}\n-\t\t\tif (!seen_colon) {\n-\t\t\t\tif (ch == '@')\n-\t\t\t\t\tnot_signoff = 1;\n-\t\t\t\telse if (ch == ':')\n-\t\t\t\t\tseen_colon = 1;\n-\t\t\t\telse\n-\t\t\t\t\tseen_name = 1;\n-\t\t\t\tcontinue;\n-\t\t\t}\n-\t\t\tif (('A' <= ch && ch <= 'Z') ||\n-\t\t\t    ('a' <= ch && ch <= 'z') ||\n-\t\t\t    ch == '-') {\n-\t\t\t\tseen_head = 1;\n-\t\t\t\tcontinue;\n-\t\t\t}\n-\t\t\tnot_signoff = 1;\n-\t\t}\n-\t\tif (not_signoff || !seen_head || !seen_name)\n-\t\t\tbuf[at++] = '\\n';\n-\t}\n+\tif (!has_signoff)\n+\t\thas_signoff = detect_any_signoff(buf, at);\n+\n+\tif (!has_signoff)\n+\t\tbuf[at++] = '\\n';\n \n \tstrcpy(buf + at, signed_off_by);\n \tat += strlen(signed_off_by);\n-- \n1.4.2\n"}]}