@matheusbsbs / matheus-bagliano / commits / c2ca1d79db
Fork 0

Allow mailsplit (and hence git-am) to handle mails with CRLF line-endings

It is not that uncommon to have mails with DOS line-ending, notably Thunderbird and web mailers like Gmail (when saving what they call "original" message). So modify mailsplit to convert CRLF line-endings to just LF. Since git-rebase is built on top of git-am, add an option to mailsplit to be used by git-am when it is acting on behalf of git-rebase, to refrain from doing this conversion. And add a test to make sure that rebase still works. Signed-off-by: Brandon Casey <drafnel@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Aug 4, 2009 at 22:31 UTC c2ca1d79dbd54b06a05e5d14a897699e59dc9f9f
3 files changed +40 -3
builtin-mailsplit.c
+9
@@ -44,6 +44,7 @@ static int is_from_line(const char *line, int len)
44 }
45
46 static struct strbuf buf = STRBUF_INIT;
47 +static int keep_cr;
48
49 /* Called with the first line (potentially partial)
50 * already in buf[] -- normally that should begin with
@@ -69,6 +70,12 @@ static int split_one(FILE *mbox, const char *name, int allow_bare)
70 * "From " and having something that looks like a date format.
71 */
72 for (;;) {
73 + if (!keep_cr && buf.len > 1 && buf.buf[buf.len-1] == '\n' &&
74 + buf.buf[buf.len-2] == '\r') {
75 + strbuf_setlen(&buf, buf.len-2);
76 + strbuf_addch(&buf, '\n');
77 + }
78 +
79 if (fwrite(buf.buf, 1, buf.len, output) != buf.len)
80 die_errno("cannot write output");
81
@@ -226,6 +233,8 @@ int cmd_mailsplit(int argc, const char **argv, const char *prefix)
233 nr = strtol(arg+2, NULL, 10);
234 } else if ( arg[1] == 'b' && !arg[2] ) {
235 allow_bare = 1;
236 + } else if (!strcmp(arg, "--keep-cr")) {
237 + keep_cr = 1;
238 } else if ( arg[1] == 'o' && arg[2] ) {
239 dir = arg+2;
240 } else if ( arg[1] == '-' && !arg[2] ) {
git-am.sh
+7 -1
@@ -197,7 +197,13 @@ check_patch_format () {
197 split_patches () {
198 case "$patch_format" in
199 mbox)
200 - git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" ||
200 + case "$rebasing" in
201 + '')
202 + keep_cr= ;;
203 + ?*)
204 + keep_cr=--keep-cr ;;
205 + esac
206 + git mailsplit -d"$prec" -o"$dotest" -b $keep_cr -- "$@" > "$dotest/last" ||
207 clean_abort
208 ;;
209 stgit-series)
t/t3400-rebase.sh
+24 -2
@@ -3,9 +3,10 @@
3 # Copyright (c) 2005 Amos Waterland
4 #
5
6 -test_description='git rebase should not destroy author information
6 +test_description='git rebase assorted tests
7
8 -This test runs git rebase and checks that the author information is not lost.
8 +This test runs git rebase and checks that the author information is not lost
9 +among other things.
10 '
11 . ./test-lib.sh
12
@@ -133,4 +134,25 @@ test_expect_success 'rebase -q is quiet' '
134 test ! -s output.out
135 '
136
137 +q_to_cr () {
138 + tr Q '\015'
139 +}
140 +
141 +test_expect_success 'Rebase a commit that sprinkles CRs in' '
142 + (
143 + echo "One"
144 + echo "TwoQ"
145 + echo "Three"
146 + echo "FQur"
147 + echo "Five"
148 + ) | q_to_cr >CR &&
149 + git add CR &&
150 + test_tick &&
151 + git commit -a -m "A file with a line with CR" &&
152 + git tag file-with-cr &&
153 + git checkout HEAD^0 &&
154 + git rebase --onto HEAD^^ HEAD^ &&
155 + git diff --exit-code file-with-cr:CR HEAD:CR
156 +'
157 +
158 test_done