mirror of
https://github.com/git/git
synced 2024-08-27 19:49:21 +00:00
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>
This commit is contained in:
parent
12d19e80b0
commit
39afcd3819
|
@ -628,64 +628,6 @@ static void decode_transfer_encoding(struct strbuf *line)
|
||||||
free(ret);
|
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)
|
static inline int patchbreak(const struct strbuf *line)
|
||||||
{
|
{
|
||||||
size_t i;
|
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)
|
static void handle_body(void)
|
||||||
{
|
{
|
||||||
struct strbuf prev = STRBUF_INIT;
|
struct strbuf prev = STRBUF_INIT;
|
||||||
|
|
Loading…
Reference in a new issue