Skip to content

Commit

Permalink
Merge branch 'jk/mbox-from-line' into maint
Browse files Browse the repository at this point in the history
Some MUAs mangled a line in a message that begins with "From " to
">From " when writing to a mailbox file and feeding such an input to
"git am" used to lose such a line.

* jk/mbox-from-line:
  mailinfo: work around -Wstring-plus-int warning
  mailinfo: make ">From" in-body header check more robust
  • Loading branch information
Junio C Hamano committed Oct 7, 2014
2 parents 80b616d + 85de86a commit b6e8269
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 1 deletion.
18 changes: 17 additions & 1 deletion builtin/mailinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,22 @@ static inline int cmp_header(const struct strbuf *line, const char *hdr)
line->buf[len] == ':' && isspace(line->buf[len + 1]);
}

static int is_format_patch_separator(const char *line, int len)
{
static const char SAMPLE[] =
"From e6807f3efca28b30decfecb1732a56c7db1137ee Mon Sep 17 00:00:00 2001\n";
const char *cp;

if (len != strlen(SAMPLE))
return 0;
if (!skip_prefix(line, "From ", &cp))
return 0;
if (strspn(cp, "0123456789abcdef") != 40)
return 0;
cp += 40;
return !memcmp(SAMPLE + (cp - line), cp, strlen(SAMPLE) - (cp - line));
}

static int check_header(const struct strbuf *line,
struct strbuf *hdr_data[], int overwrite)
{
Expand Down Expand Up @@ -329,7 +345,7 @@ static int check_header(const struct strbuf *line,

/* for inbody stuff */
if (starts_with(line->buf, ">From") && isspace(line->buf[5])) {
ret = 1; /* Should this return 0? */
ret = is_format_patch_separator(line->buf + 1, line->len - 1);
goto check_header_out;
}
if (starts_with(line->buf, "[PATCH]") && isspace(line->buf[7])) {
Expand Down
18 changes: 18 additions & 0 deletions t/t5100-mailinfo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,22 @@ test_expect_success 'mailinfo on from header without name works' '
'

test_expect_success 'mailinfo finds headers after embedded From line' '
mkdir embed-from &&
git mailsplit -oembed-from "$TEST_DIRECTORY"/t5100/embed-from.in &&
test_cmp "$TEST_DIRECTORY"/t5100/embed-from.in embed-from/0001 &&
git mailinfo embed-from/msg embed-from/patch \
<embed-from/0001 >embed-from/out &&
test_cmp "$TEST_DIRECTORY"/t5100/embed-from.expect embed-from/out
'

test_expect_success 'mailinfo on message with quoted >From' '
mkdir quoted-from &&
git mailsplit -oquoted-from "$TEST_DIRECTORY"/t5100/quoted-from.in &&
test_cmp "$TEST_DIRECTORY"/t5100/quoted-from.in quoted-from/0001 &&
git mailinfo quoted-from/msg quoted-from/patch \
<quoted-from/0001 >quoted-from/out &&
test_cmp "$TEST_DIRECTORY"/t5100/quoted-from.expect quoted-from/msg
'

test_done
5 changes: 5 additions & 0 deletions t/t5100/embed-from.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Author: Commit Author
Email: commit@example.com
Subject: patch subject
Date: Sat, 13 Sep 2014 21:13:23 -0400

13 changes: 13 additions & 0 deletions t/t5100/embed-from.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
From 1234567890123456789012345678901234567890 Mon Sep 17 00:00:00 2001
From: Email Author <email@example.com>
Date: Sun, 25 May 2008 00:38:18 -0700
Subject: [PATCH] email subject

>From 1234567890123456789012345678901234567890 Mon Sep 17 00:00:00 2001
From: Commit Author <commit@example.com>
Date: Sat, 13 Sep 2014 21:13:23 -0400
Subject: patch subject

patch body
---
patch
3 changes: 3 additions & 0 deletions t/t5100/quoted-from.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
>From the depths of history, we are stuck with the
flaky mbox format.

10 changes: 10 additions & 0 deletions t/t5100/quoted-from.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
From 1234567890123456789012345678901234567890 Mon Sep 17 00:00:00 2001
From: Author Name <somebody@example.com>
Date: Sun, 25 May 2008 00:38:18 -0700
Subject: [PATCH] testing quoted >From

>From the depths of history, we are stuck with the
flaky mbox format.

---
patch

0 comments on commit b6e8269

Please sign in to comment.