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>
Junio C Hamano committed
Oct 13, 2015 at 11:03 UTC
39afcd38196fa3594924a73896e5fa2bca21dd63
1 file changed
+56
-58
builtin/mailinfo.c
+56
-58
@@ -628,64 +628,6 @@ static void decode_transfer_encoding(struct strbuf *line)
628
free(ret);
629
}
630
631
-static void handle_filter(struct strbuf *line);
632
-
633
-static int find_boundary(void)
634
-{
635
- while (!strbuf_getline(&line, fin, '\n')) {
636
- if (*content_top && is_multipart_boundary(&line))
637
- return 1;
638
- }
639
- return 0;
640
-}
641
-
642
-static int handle_boundary(void)
643
-{
644
- struct strbuf newline = STRBUF_INIT;
645
-
646
- strbuf_addch(&newline, '\n');
647
-again:
648
- if (line.len >= (*content_top)->len + 2 &&
649
- !memcmp(line.buf + (*content_top)->len, "--", 2)) {
650
- /* we hit an end boundary */
651
- /* pop the current boundary off the stack */
652
- strbuf_release(*content_top);
653
- free(*content_top);
654
- *content_top = NULL;
655
-
656
- /* technically won't happen as is_multipart_boundary()
657
- will fail first. But just in case..
658
- */
659
- if (--content_top < content) {
660
- fprintf(stderr, "Detected mismatched boundaries, "
661
- "can't recover\n");
662
- exit(1);
663
- }
664
- handle_filter(&newline);
665
- strbuf_release(&newline);
666
-
667
- /* skip to the next boundary */
668
- if (!find_boundary())
669
- return 0;
670
- goto again;
671
- }
672
-
673
- /* set some defaults */
674
- transfer_encoding = TE_DONTCARE;
675
- strbuf_reset(&charset);
676
-
677
- /* slurp in this section's info */
678
- while (read_one_header_line(&line, fin))
679
- check_header(&line, p_hdr_data, 0);
680
-
681
- strbuf_release(&newline);
682
- /* replenish line */
683
- if (strbuf_getline(&line, fin, '\n'))
684
- return 0;
685
- strbuf_addch(&line, '\n');
686
- return 1;
687
-}
688
-
631
static inline int patchbreak(const struct strbuf *line)
632
{
633
size_t i;
@@ -853,6 +795,62 @@ static void handle_filter(struct strbuf *line)
795
}
796
}
797
798
+static int find_boundary(void)
799
+{
800
+ while (!strbuf_getline(&line, fin, '\n')) {
801
+ if (*content_top && is_multipart_boundary(&line))
802
+ return 1;
803
+ }
804
+ return 0;
805
+}
806
+
807
+static int handle_boundary(void)
808
+{
809
+ struct strbuf newline = STRBUF_INIT;
810
+
811
+ strbuf_addch(&newline, '\n');
812
+again:
813
+ if (line.len >= (*content_top)->len + 2 &&
814
+ !memcmp(line.buf + (*content_top)->len, "--", 2)) {
815
+ /* we hit an end boundary */
816
+ /* pop the current boundary off the stack */
817
+ strbuf_release(*content_top);
818
+ free(*content_top);
819
+ *content_top = NULL;
820
+
821
+ /* technically won't happen as is_multipart_boundary()
822
+ will fail first. But just in case..
823
+ */
824
+ if (--content_top < content) {
825
+ fprintf(stderr, "Detected mismatched boundaries, "
826
+ "can't recover\n");
827
+ exit(1);
828
+ }
829
+ handle_filter(&newline);
830
+ strbuf_release(&newline);
831
+
832
+ /* skip to the next boundary */
833
+ if (!find_boundary())
834
+ return 0;
835
+ goto again;
836
+ }
837
+
838
+ /* set some defaults */
839
+ transfer_encoding = TE_DONTCARE;
840
+ strbuf_reset(&charset);
841
+
842
+ /* slurp in this section's info */
843
+ while (read_one_header_line(&line, fin))
844
+ check_header(&line, p_hdr_data, 0);
845
+
846
+ strbuf_release(&newline);
847
+ /* replenish line */
848
+ if (strbuf_getline(&line, fin, '\n'))
849
+ return 0;
850
+ strbuf_addch(&line, '\n');
851
+ return 1;
852
+}
853
+
854
static void handle_body(void)
855
{
856
struct strbuf prev = STRBUF_INIT;