summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-10-13 11:03:20 -0700
committerJunio C Hamano <gitster@pobox.com>2015-10-21 15:20:49 -0700
commit39afcd38196fa3594924a73896e5fa2bca21dd63 (patch)
tree21369a1254a508cb431c464eb5b79e88e10c95b3
parent12d19e80b049dbedd51e9e6a70260383b9db4dd0 (diff)
downloadgit-39afcd38196fa3594924a73896e5fa2bca21dd63.tar.gz
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 <gitster@pobox.com>
-rw-r--r--builtin/mailinfo.c114
1 files changed, 56 insertions, 58 deletions
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;