{"thread":{"id":"20782","subject":"[PATCH] Majorly simplify the definition of scissors line","startedAt":"2009-08-29T07:17:00Z","lastAt":"2009-08-29T07:17:00Z","messageCount":1,"participants":["しらいし ななこ"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"122079","messageId":"20090829161700.6117@nanako3.lavabit.com","threadId":"20782","inReplyTo":null,"subject":"[PATCH] Majorly simplify the definition of scissors line","fromName":"しらいし ななこ","fromEmail":"nanako3@lavabit.com","sentAt":"2009-08-29T07:17:00Z","receivedAt":"2009-08-29T07:17:00Z","isPatch":true,"sender":{"key":"nanako3@lavabit.com","avatar":"https://gravatar.com/avatar/3777b9e201c5883a62b1a6fdf7c53f2d712d1d80989146063ea861e33aad72a8?d=mp&s=160"},"body":"The definition of scissors line was \"a line that mainly consists of\nscissors and perforation\". While it is easy to explain to new people,\nthis does not exactly define where the line between \"mainly consists\nof\" and \"contains some amount of\" lies.\n\nMake the definition more strict and allow only lines that begin with\na '-- >8 --' (or its left-handed equivalent '-- 8< --'), which is\nequally easy to explain to new people. More important, the rule is\nmuch shorter and more precise, so it is easier to remember.\n\nThis pattern also is how Nicolas Sebrecht initially thought what the\ndefinition was, without reading what Junio's code really did, so we\nhave an empirical evidence that this matches at least one newcomer's\nintuition.\n\nSigned-off-by: しらいし ななこ <nanako3@lavabit.com>\n---\n Documentation/git-mailinfo.txt |    4 +-\n builtin-mailinfo.c             |   48 +++------------------------------------\n t/t5100/msg0014                |    4 +-\n t/t5100/sample.mbox            |    4 +-\n 4 files changed, 10 insertions(+), 50 deletions(-)\n\ndiff --git a/Documentation/git-mailinfo.txt b/Documentation/git-mailinfo.txt\nindex 71b93ad..1c2c414 100644\n--- a/Documentation/git-mailinfo.txt\n+++ b/Documentation/git-mailinfo.txt\n@@ -56,8 +56,8 @@ conversion, even with this flag.\n \n --scissors::\n \tRemove everything in body before a scissors line.  A line that\n-\tmainly consists of scissors (either \">8\" or \"8<\") and perforation\n-\t(dash \"-\") marks is called a scissors line, and is used to request\n+\tbegins with \"-- >8 --\" or \"-- 8< --\" is called a scissors line,\n+\tand is used to request\n \tthe reader to cut the message at that line.  If such a line\n \tappears in the body of the message before the patch, everything\n \tbefore it (including the scissors line itself) is ignored when\ndiff --git a/builtin-mailinfo.c b/builtin-mailinfo.c\nindex 508bdf0..1bbad4e 100644\n--- a/builtin-mailinfo.c\n+++ b/builtin-mailinfo.c\n@@ -722,52 +722,12 @@ static inline int patchbreak(const struct strbuf *line)\n \n static int is_scissors_line(const struct strbuf *line)\n {\n-\tsize_t i, len = line->len;\n-\tint scissors = 0, gap = 0;\n-\tint first_nonblank = -1;\n-\tint last_nonblank = 0, visible, perforation = 0, in_perforation = 0;\n \tconst char *buf = line->buf;\n+\tsize_t len = line->len;\n \n-\tfor (i = 0; i < len; i++) {\n-\t\tif (isspace(buf[i])) {\n-\t\t\tif (in_perforation) {\n-\t\t\t\tperforation++;\n-\t\t\t\tgap++;\n-\t\t\t}\n-\t\t\tcontinue;\n-\t\t}\n-\t\tlast_nonblank = i;\n-\t\tif (first_nonblank < 0)\n-\t\t\tfirst_nonblank = i;\n-\t\tif (buf[i] == '-') {\n-\t\t\tin_perforation = 1;\n-\t\t\tperforation++;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (i + 1 < len &&\n-\t\t    (!memcmp(buf + i, \">8\", 2) || !memcmp(buf + i, \"8<\", 2))) {\n-\t\t\tin_perforation = 1;\n-\t\t\tperforation += 2;\n-\t\t\tscissors += 2;\n-\t\t\ti++;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tin_perforation = 0;\n-\t}\n-\n-\t/*\n-\t * The mark must be at least 8 bytes long (e.g. \"-- >8 --\").\n-\t * Even though there can be arbitrary cruft on the same line\n-\t * (e.g. \"cut here\"), in order to avoid misidentification, the\n-\t * perforation must occupy more than a third of the visible\n-\t * width of the line, and dashes and scissors must occupy more\n-\t * than half of the perforation.\n-\t */\n-\n-\tvisible = last_nonblank - first_nonblank + 1;\n-\treturn (scissors && 8 <= visible &&\n-\t\tvisible < perforation * 3 &&\n-\t\tgap * 2 < perforation);\n+\tif (len < 8)\n+\t\treturn 0;\n+\treturn (!memcmp(\"-- >8 --\", buf, 8) || !memcmp(\"-- 8< --\", buf, 8));\n }\n \n static int handle_commit_msg(struct strbuf *line)\ndiff --git a/t/t5100/msg0014 b/t/t5100/msg0014\nindex 62e5cd2..187ff57 100644\n--- a/t/t5100/msg0014\n+++ b/t/t5100/msg0014\n@@ -6,8 +6,8 @@ Subject: [PATCH] BLAH TWO\n \n And then we will see the scissors.\n \n- This line is not a scissors mark -- >8 -- but talks about it.\n- - - >8 - - please remove everything above this line - - >8 - -\n+ This is not a scissors line -- >8 -- but talks about it.\n+-- >8 -- please remove everything above this line -- >8 --\n \n Subject: [PATCH] Teach mailinfo to ignore everything before -- >8 -- mark\n From: Junio C Hamano <gitster@pobox.com>\ndiff --git a/t/t5100/sample.mbox b/t/t5100/sample.mbox\nindex 13fa4ae..563f713 100644\n--- a/t/t5100/sample.mbox\n+++ b/t/t5100/sample.mbox\n@@ -576,8 +576,8 @@ Subject: [PATCH] BLAH TWO\n \n And then we will see the scissors.\n \n- This line is not a scissors mark -- >8 -- but talks about it.\n- - - >8 - - please remove everything above this line - - >8 - -\n+ This is not a scissors line -- >8 -- but talks about it.\n+-- >8 -- please remove everything above this line -- >8 --\n \n Subject: [PATCH] Teach mailinfo to ignore everything before -- >8 -- mark\n From: Junio C Hamano <gitster@pobox.com>\n-- \n1.6.4.1\n\n-- \nNanako Shiraishi\nhttp://ivory.ap.teacup.com/nanako3/\n"}]}