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

[PATCH v3 1/3] mailinfo: separate in-body header processing

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

The check_header function contains logic specific to in-body headers, although it is invoked during both the processing of actual headers and in-body headers. Separate out the in-body header part into its own function.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
---
 mailinfo.c | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)
diff --git a/mailinfo.c b/mailinfo.c
index e19abe3..0c4738a 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -495,21 +495,6 @@ static int check_header(struct mailinfo *mi,
 		goto check_header_out;
 	}
 
-	/* for inbody stuff */
-	if (starts_with(line->buf, ">From") && isspace(line->buf[5])) {
-		ret = is_format_patch_separator(line->buf + 1, line->len - 1);
-		goto check_header_out;
-	}
-	if (starts_with(line->buf, "[PATCH]") && isspace(line->buf[7])) {
-		for (i = 0; header[i]; i++) {
-			if (!strcmp("Subject", header[i])) {
-				handle_header(&hdr_data[i], line);
-				ret = 1;
-				goto check_header_out;
-			}
-		}
-	}
-
 check_header_out:
 	strbuf_release(&sb);
 	return ret;
@@ -623,6 +608,22 @@ static int is_scissors_line(const struct strbuf *line)
 		gap * 2 < perforation);
 }
 
+static int check_inbody_header(struct mailinfo *mi, const struct strbuf *line)
+{
+	if (starts_with(line->buf, ">From") && isspace(line->buf[5]))
+		return is_format_patch_separator(line->buf + 1, line->len - 1);
+	if (starts_with(line->buf, "[PATCH]") && isspace(line->buf[7])) {
+		int i;
+		for (i = 0; header[i]; i++)
+			if (!strcmp("Subject", header[i])) {
+				handle_header(&mi->s_hdr_data[i], line);
+				return 1;
+			}
+		return 0;
+	}
+	return check_header(mi, line, mi->s_hdr_data, 0);
+}
+
 static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
 {
 	assert(!mi->filter_stage);
@@ -633,7 +634,7 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
 	}
 
 	if (mi->use_inbody_headers && mi->header_stage) {
-		mi->header_stage = check_header(mi, line, mi->s_hdr_data, 0);
+		mi->header_stage = check_inbody_header(mi, line);
 		if (mi->header_stage)
 			return 0;
 	} else
-- 
2.10.0.rc2.20.g5b18e70
Previous: Jonathan TanNext: Jonathan Tan
Message 8 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.