{"thread":{"id":"7119","subject":"[PATCH 3/5] restrict the patch filtering v2","startedAt":"2007-03-06T22:59:57Z","lastAt":"2007-03-06T22:59:57Z","messageCount":1,"participants":["Don Zickus"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"36486","messageId":"11732219972409-git-send-email-dzickus@redhat.com","threadId":"7119","inReplyTo":null,"subject":"[PATCH 3/5] restrict the patch filtering v2","fromName":"Don Zickus","fromEmail":"dzickus@redhat.com","sentAt":"2007-03-06T22:59:57Z","receivedAt":"2007-03-06T22:59:57Z","isPatch":true,"sender":{"key":"dzickus@redhat.com","avatar":null},"body":"I have come across many emails that use long strings of '-'s as separators\nfor ideas.  This patch below limits the separator to only 3 '-', with the\nintent that long string of '-'s will stay in the commit msg and not in the\npatch file.\n\nSigned-off-by: Don Zickus <dzickus@redhat.com>\nAcked-by: Linus Torvalds <torvalds@linux-foundation.org>\n\n---\nI purposedly separated this patch out because I wasn't sure if anyone would\nhave objections to it.  I tested it on numerous emails with and with patches\nand didn't see any issues.\n\nUpdate: compiled and tested with my test mbox (~1200 emails).  output is\nidentical to the previous patch. \n\n---\n builtin-mailinfo.c |   37 ++++++++++++++++++++++++++++++++++---\n 1 files changed, 34 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin-mailinfo.c b/builtin-mailinfo.c\nindex 0532003..7b04179 100644\n--- a/builtin-mailinfo.c\n+++ b/builtin-mailinfo.c\n@@ -644,6 +644,39 @@ again:\n \treturn (fgets(line, sizeof(line), fin) != NULL);\n }\n \n+static inline int patchbreak(const char *line)\n+{\n+\t/* Beginning of a \"diff -\" header? */\n+\tif (!memcmp(\"diff -\", line, 6))\n+\t\treturn 1;\n+\n+\t/* CVS \"Index: \" line? */\n+\tif (!memcmp(\"Index: \", line, 7))\n+\t\treturn 1;\n+\n+\t/*\n+\t * \"--- <filename>\" starts patches without headers\n+\t * \"---<sp>*\" is a manual separator\n+\t */\n+\tif (!memcmp(\"---\", line, 3)) {\n+\t\tline += 3;\n+\t\t/* space followed by a filename? */\n+\t\tif (line[0] == ' ' && !isspace(line[1]))\n+\t\t\treturn 1;\n+\t\t/* Just whitespace? */\n+\t\tfor (;;) {\n+\t\t\tunsigned char c = *line++;\n+\t\t\tif (c == '\\n')\n+\t\t\t\treturn 1;\n+\t\t\tif (!isspace(c))\n+\t\t\t\tbreak;\n+\t\t}\n+\t\treturn 0;\n+\t}\n+\treturn 0;\n+}\n+\n+\n static int handle_commit_msg(char *line)\n {\n \tstatic int still_looking=1;\n@@ -665,9 +698,7 @@ static int handle_commit_msg(char *line)\n \t\t\treturn 0;\n \t}\n \n-\tif (!memcmp(\"diff -\", line, 6) ||\n-\t    !memcmp(\"---\", line, 3) ||\n-\t    !memcmp(\"Index: \", line, 7)) {\n+\tif (patchbreak(line)) {\n \t\tfclose(cmitmsg);\n \t\tcmitmsg = NULL;\n \t\treturn 1;\n-- \n1.5.0.2.213.g23f4-dirty\n"}]}