mailinfo: separate in-body header processing

The check_header function contains logic specific to in-body headers, although it is invoked during both the processing of actual headers and in-body headers. Separate out the in-body header part into its own function. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Sep 19, 2016 at 14:08 UTC 334192b411312c1ffab01af346d2d64d23597d84
1 file changed +17 -16
mailinfo.c
+17 -16
@@ -495,21 +495,6 @@ static int check_header(struct mailinfo *mi,
495 goto check_header_out;
496 }
497
498 - /* for inbody stuff */
499 - if (starts_with(line->buf, ">From") && isspace(line->buf[5])) {
500 - ret = is_format_patch_separator(line->buf + 1, line->len - 1);
501 - goto check_header_out;
502 - }
503 - if (starts_with(line->buf, "[PATCH]") && isspace(line->buf[7])) {
504 - for (i = 0; header[i]; i++) {
505 - if (!strcmp("Subject", header[i])) {
506 - handle_header(&hdr_data[i], line);
507 - ret = 1;
508 - goto check_header_out;
509 - }
510 - }
511 - }
512 -
498 check_header_out:
499 strbuf_release(&sb);
500 return ret;
@@ -623,6 +608,22 @@ static int is_scissors_line(const struct strbuf *line)
608 gap * 2 < perforation);
609 }
610
611 +static int check_inbody_header(struct mailinfo *mi, const struct strbuf *line)
612 +{
613 + if (starts_with(line->buf, ">From") && isspace(line->buf[5]))
614 + return is_format_patch_separator(line->buf + 1, line->len - 1);
615 + if (starts_with(line->buf, "[PATCH]") && isspace(line->buf[7])) {
616 + int i;
617 + for (i = 0; header[i]; i++)
618 + if (!strcmp("Subject", header[i])) {
619 + handle_header(&mi->s_hdr_data[i], line);
620 + return 1;
621 + }
622 + return 0;
623 + }
624 + return check_header(mi, line, mi->s_hdr_data, 0);
625 +}
626 +
627 static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
628 {
629 assert(!mi->filter_stage);
@@ -633,7 +634,7 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
634 }
635
636 if (mi->use_inbody_headers && mi->header_stage) {
636 - mi->header_stage = check_header(mi, line, mi->s_hdr_data, 0);
637 + mi->header_stage = check_inbody_header(mi, line);
638 if (mi->header_stage)
639 return 0;
640 } else