From: Junio C Hamano Date: Tue, 13 Oct 2015 18:03:20 +0000 (-0700) Subject: mailinfo: move handle_boundary() lower X-Git-Tag: v2.7.0-rc0~64^2~28 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/39afcd38196fa3594924a73896e5fa2bca21dd63 mailinfo: move handle_boundary() lower This function wants to call find_boundary() and is called only from one place without any recursing, so it becomes easier to read if it appears after the called function. Signed-off-by: Junio C Hamano --- diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c index a183cd49fd..ed9c568a20 100644 --- a/builtin/mailinfo.c +++ b/builtin/mailinfo.c @@ -628,64 +628,6 @@ static void decode_transfer_encoding(struct strbuf *line) free(ret); } -static void handle_filter(struct strbuf *line); - -static int find_boundary(void) -{ - while (!strbuf_getline(&line, fin, '\n')) { - if (*content_top && is_multipart_boundary(&line)) - return 1; - } - return 0; -} - -static int handle_boundary(void) -{ - struct strbuf newline = STRBUF_INIT; - - strbuf_addch(&newline, '\n'); -again: - if (line.len >= (*content_top)->len + 2 && - !memcmp(line.buf + (*content_top)->len, "--", 2)) { - /* we hit an end boundary */ - /* pop the current boundary off the stack */ - strbuf_release(*content_top); - free(*content_top); - *content_top = NULL; - - /* technically won't happen as is_multipart_boundary() - will fail first. But just in case.. - */ - if (--content_top < content) { - fprintf(stderr, "Detected mismatched boundaries, " - "can't recover\n"); - exit(1); - } - handle_filter(&newline); - strbuf_release(&newline); - - /* skip to the next boundary */ - if (!find_boundary()) - return 0; - goto again; - } - - /* set some defaults */ - transfer_encoding = TE_DONTCARE; - strbuf_reset(&charset); - - /* slurp in this section's info */ - while (read_one_header_line(&line, fin)) - check_header(&line, p_hdr_data, 0); - - strbuf_release(&newline); - /* replenish line */ - if (strbuf_getline(&line, fin, '\n')) - return 0; - strbuf_addch(&line, '\n'); - return 1; -} - static inline int patchbreak(const struct strbuf *line) { size_t i; @@ -853,6 +795,62 @@ static void handle_filter(struct strbuf *line) } } +static int find_boundary(void) +{ + while (!strbuf_getline(&line, fin, '\n')) { + if (*content_top && is_multipart_boundary(&line)) + return 1; + } + return 0; +} + +static int handle_boundary(void) +{ + struct strbuf newline = STRBUF_INIT; + + strbuf_addch(&newline, '\n'); +again: + if (line.len >= (*content_top)->len + 2 && + !memcmp(line.buf + (*content_top)->len, "--", 2)) { + /* we hit an end boundary */ + /* pop the current boundary off the stack */ + strbuf_release(*content_top); + free(*content_top); + *content_top = NULL; + + /* technically won't happen as is_multipart_boundary() + will fail first. But just in case.. + */ + if (--content_top < content) { + fprintf(stderr, "Detected mismatched boundaries, " + "can't recover\n"); + exit(1); + } + handle_filter(&newline); + strbuf_release(&newline); + + /* skip to the next boundary */ + if (!find_boundary()) + return 0; + goto again; + } + + /* set some defaults */ + transfer_encoding = TE_DONTCARE; + strbuf_reset(&charset); + + /* slurp in this section's info */ + while (read_one_header_line(&line, fin)) + check_header(&line, p_hdr_data, 0); + + strbuf_release(&newline); + /* replenish line */ + if (strbuf_getline(&line, fin, '\n')) + return 0; + strbuf_addch(&line, '\n'); + return 1; +} + static void handle_body(void) { struct strbuf prev = STRBUF_INIT;