Skip to content

Commit 334192b

Browse files
jonathantanmygitster
authored andcommitted
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>
1 parent f6727b0 commit 334192b

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

mailinfo.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -495,21 +495,6 @@ static int check_header(struct mailinfo *mi,
495495
goto check_header_out;
496496
}
497497

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-
513498
check_header_out:
514499
strbuf_release(&sb);
515500
return ret;
@@ -623,6 +608,22 @@ static int is_scissors_line(const struct strbuf *line)
623608
gap * 2 < perforation);
624609
}
625610

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+
626627
static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
627628
{
628629
assert(!mi->filter_stage);
@@ -633,7 +634,7 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
633634
}
634635

635636
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);
637638
if (mi->header_stage)
638639
return 0;
639640
} else

0 commit comments

Comments
 (0)