mailinfo: do not let handle_body() touch global "line" directly

This function has a single caller, and called with the global "line" holding the first line of the e-mail body after the caller finished processing the e-mail headers. The function then goes into a loop to process each line of the input, starting from what was given by its caller, and fills the same global "line" variable from the input as it needs to process more lines. Let the caller explicitly pass a pointer to this global "line" variable as an argument, and have the function itself use that strbuf throughout, instead of referring to the global "line" itself. There are helper functions that this function calls that still touch the global directly; they will be updated as the series progresses. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Oct 18, 2015 at 15:36 UTC fde00d50f6b084680085b9924b198e7f3138fc9e
1 file changed +8 -8
builtin/mailinfo.c
+8 -8
@@ -842,7 +842,7 @@ again:
842 return 1;
843 }
844
845 -static void handle_body(void)
845 +static void handle_body(struct strbuf *line)
846 {
847 struct strbuf prev = STRBUF_INIT;
848 int filter_stage = 0;
@@ -856,7 +856,7 @@ static void handle_body(void)
856
857 do {
858 /* process any boundary lines */
859 - if (*content_top && is_multipart_boundary(&line)) {
859 + if (*content_top && is_multipart_boundary(line)) {
860 /* flush any leftover */
861 if (prev.len) {
862 handle_filter(&prev, &filter_stage, &header_stage);
@@ -867,7 +867,7 @@ static void handle_body(void)
867 }
868
869 /* Unwrap transfer encoding */
870 - decode_transfer_encoding(&line);
870 + decode_transfer_encoding(line);
871
872 switch (transfer_encoding) {
873 case TE_BASE64:
@@ -876,7 +876,7 @@ static void handle_body(void)
876 struct strbuf **lines, **it, *sb;
877
878 /* Prepend any previous partial lines */
879 - strbuf_insert(&line, 0, prev.buf, prev.len);
879 + strbuf_insert(line, 0, prev.buf, prev.len);
880 strbuf_reset(&prev);
881
882 /*
@@ -884,7 +884,7 @@ static void handle_body(void)
884 * multiple new lines. Pass only one chunk
885 * at a time to handle_filter()
886 */
887 - lines = strbuf_split(&line, '\n');
887 + lines = strbuf_split(line, '\n');
888 for (it = lines; (sb = *it); it++) {
889 if (*(it + 1) == NULL) /* The last line */
890 if (sb->buf[sb->len - 1] != '\n') {
@@ -902,10 +902,10 @@ static void handle_body(void)
902 break;
903 }
904 default:
905 - handle_filter(&line, &filter_stage, &header_stage);
905 + handle_filter(line, &filter_stage, &header_stage);
906 }
907
908 - } while (!strbuf_getwholeline(&line, fin, '\n'));
908 + } while (!strbuf_getwholeline(line, fin, '\n'));
909
910 handle_body_out:
911 strbuf_release(&prev);
@@ -991,7 +991,7 @@ static int mailinfo(FILE *in, FILE *out, const char *msg, const char *patch)
991 while (read_one_header_line(&line, fin))
992 check_header(&line, p_hdr_data, 1);
993
994 - handle_body();
994 + handle_body(&line);
995 fclose(patchfile);
996
997 handle_info();