git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 2/3] mailinfo: make is_scissors_line take plain char *

From
JTJonathan Tan <jonathantanmy@google.com>
Date
Sep 20, 2016, 17:17 UTC
Message-ID
<820980e95ee640013b2cf9c30b616ced39af67fa.1474391594.git.jonathantanmy@google.com>
In-Reply-To
<cover.1474391594.git.jonathantanmy@google.com>

The is_scissors_line takes a struct strbuf * when a char * would suffice. Make it take char *.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
---
 mailinfo.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)
diff --git a/mailinfo.c b/mailinfo.c
index 0c4738a..69391aa 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -557,37 +557,35 @@ static inline int patchbreak(const struct strbuf *line)
 	return 0;
 }
 
-static int is_scissors_line(const struct strbuf *line)
+static int is_scissors_line(const char *line)
 {
-	size_t i, len = line->len;
+	const char *c;
 	int scissors = 0, gap = 0;
-	int first_nonblank = -1;
-	int last_nonblank = 0, visible, perforation = 0, in_perforation = 0;
-	const char *buf = line->buf;
+	const char *first_nonblank = NULL, *last_nonblank = NULL;
+	int visible, perforation = 0, in_perforation = 0;
 
-	for (i = 0; i < len; i++) {
-		if (isspace(buf[i])) {
+	for (c = line; *c; c++) {
+		if (isspace(*c)) {
 			if (in_perforation) {
 				perforation++;
 				gap++;
 			}
 			continue;
 		}
-		last_nonblank = i;
-		if (first_nonblank < 0)
-			first_nonblank = i;
-		if (buf[i] == '-') {
+		last_nonblank = c;
+		if (first_nonblank == NULL)
+			first_nonblank = c;
+		if (*c == '-') {
 			in_perforation = 1;
 			perforation++;
 			continue;
 		}
-		if (i + 1 < len &&
-		    (!memcmp(buf + i, ">8", 2) || !memcmp(buf + i, "8<", 2) ||
-		     !memcmp(buf + i, ">%", 2) || !memcmp(buf + i, "%<", 2))) {
+		if ((!memcmp(c, ">8", 2) || !memcmp(c, "8<", 2) ||
+		     !memcmp(c, ">%", 2) || !memcmp(c, "%<", 2))) {
 			in_perforation = 1;
 			perforation += 2;
 			scissors += 2;
-			i++;
+			c++;
 			continue;
 		}
 		in_perforation = 0;
@@ -602,7 +600,10 @@ static int is_scissors_line(const struct strbuf *line)
 	 * than half of the perforation.
 	 */
 
-	visible = last_nonblank - first_nonblank + 1;
+	if (first_nonblank && last_nonblank)
+		visible = last_nonblank - first_nonblank + 1;
+	else
+		visible = 0;
 	return (scissors && 8 <= visible &&
 		visible < perforation * 3 &&
 		gap * 2 < perforation);
@@ -647,7 +648,7 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
 	if (convert_to_utf8(mi, line, mi->charset.buf))
 		return 0; /* mi->input_error already set */
 
-	if (mi->use_scissors && is_scissors_line(line)) {
+	if (mi->use_scissors && is_scissors_line(line->buf)) {
 		int i;
 
 		strbuf_setlen(&mi->log_message, 0);
-- 
2.10.0.rc2.20.g5b18e70
Previous: Jonathan TanNext: Jonathan Tan
Message 9 of 12 in “handle multiline in-body headers”
  1. 0/4 handle multiline in-body headersJonathan Tan, Sep 19, 2016
  2. 1/4 mailinfo: separate in-body header processingJonathan Tan, Sep 19, 2016
  3. 3/4 mailinfo: make is_scissors_line take plain char *Jonathan Tan, Sep 19, 2016
  4. 2/4 mailinfo: refactor to support utf8 decode attemptsJonathan Tan, Sep 19, 2016
  5. 4/4 mailinfo: handle in-body header continuationsJonathan Tan, Sep 19, 2016
  6. Junio C HamanoSep 19, 2016
  7. 0/3 handle multiline in-body headersJonathan Tan, Sep 20, 2016
  8. 1/3 mailinfo: separate in-body header processingJonathan Tan, Sep 20, 2016
  9. 2/3 mailinfo: make is_scissors_line take plain char *Jonathan Tan, Sep 20, 2016
  10. 3/3 mailinfo: handle in-body header continuationsJonathan Tan, Sep 20, 2016
  11. Jeff KingSep 20, 2016
  12. Junio C HamanoSep 21, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.