{"thread":{"id":"22393","subject":"[PATCHv3 1/3] tests: consolidate CR removal/addition functions","startedAt":"2010-01-26T00:33:56Z","lastAt":"2010-01-26T01:19:26Z","messageCount":5,"participants":["Stephen Boyd","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"132652","messageId":"1264466039-22431-1-git-send-email-bebarino@gmail.com","threadId":"22393","inReplyTo":null,"subject":"[PATCHv3 0/3] Fix patch detection for thunderbird saved mails","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2010-01-26T00:33:56Z","receivedAt":"2010-01-26T00:33:56Z","isPatch":false,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"The original patch for this is a bit old (~1 month) but I'd like to see it\nmake it in. The first two patches are cleanup before the original patch in\nthe third spot. Now the test in patch 3 uses append_cr() instead of a hand\ncrafted version.\n\nStephen Boyd (3):\n  tests: consolidate CR removal/addition functions\n  t0022: replace non-portable literal CR\n  am: fix patch format detection for Thunderbird \"Save As\" emails\n\n git-am.sh                     |    3 +-\n t/t0020-crlf.sh               |   55 +++++++++++++++-------------------------\n t/t0022-crlf-rename.sh        |    2 +-\n t/t3400-rebase.sh             |    4 ---\n t/t4012-diff-binary.sh        |    4 ---\n t/t4150-am.sh                 |   15 +++++++++++\n t/t6033-merge-crlf.sh         |    8 ------\n t/t9401-git-cvsserver-crlf.sh |    8 ------\n t/test-lib.sh                 |   16 ++++++++++++\n 9 files changed, 55 insertions(+), 60 deletions(-)\n"},{"id":"132651","messageId":"1264466039-22431-2-git-send-email-bebarino@gmail.com","threadId":"22393","inReplyTo":"1264466039-22431-1-git-send-email-bebarino@gmail.com","subject":"[PATCHv3 1/3] tests: consolidate CR removal/addition functions","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2010-01-26T00:33:57Z","receivedAt":"2010-01-26T00:33:57Z","isPatch":false,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"append_cr(), remove_cr(), q_to_nul() and q_to_cr() are defined in multiple\ntests. Consolidate them into test-lib.sh so we can stop redefining them.\nThe use of remove_cr() in t0020 to test for a CR is replaced with a new\nfunction has_cr() to accurately reflect what is intended (the output of\nremove_cr() was being thrown away).\n\nSigned-off-by: Stephen Boyd <bebarino@gmail.com>\n---\n t/t0020-crlf.sh               |   55 +++++++++++++++-------------------------\n t/t3400-rebase.sh             |    4 ---\n t/t4012-diff-binary.sh        |    4 ---\n t/t6033-merge-crlf.sh         |    8 ------\n t/t9401-git-cvsserver-crlf.sh |    8 ------\n t/test-lib.sh                 |   16 ++++++++++++\n 6 files changed, 37 insertions(+), 58 deletions(-)\n\ndiff --git a/t/t0020-crlf.sh b/t/t0020-crlf.sh\nindex 4e72b53..c3e7e32 100755\n--- a/t/t0020-crlf.sh\n+++ b/t/t0020-crlf.sh\n@@ -4,21 +4,8 @@ test_description='CRLF conversion'\n \n . ./test-lib.sh\n \n-q_to_nul () {\n-\tperl -pe 'y/Q/\\000/'\n-}\n-\n-q_to_cr () {\n-\ttr Q '\\015'\n-}\n-\n-append_cr () {\n-\tsed -e 's/$/Q/' | tr Q '\\015'\n-}\n-\n-remove_cr () {\n-\ttr '\\015' Q <\"$1\" | grep Q >/dev/null &&\n-\ttr '\\015' Q <\"$1\" | sed -ne 's/Q$//p'\n+has_cr() {\n+\ttr '\\015' Q <\"$1\" | grep Q >/dev/null\n }\n \n test_expect_success setup '\n@@ -156,7 +143,7 @@ test_expect_success 'checkout with autocrlf=true' '\n \n \tfor f in one dir/two\n \tdo\n-\t\tremove_cr \"$f\" >tmp && mv -f tmp $f &&\n+\t\tremove_cr <\"$f\" >tmp && mv -f tmp $f &&\n \t\tgit update-index -- $f || {\n \t\t\techo \"Eh? $f\"\n \t\t\tfalse\n@@ -180,7 +167,7 @@ test_expect_success 'checkout with autocrlf=input' '\n \n \tfor f in one dir/two\n \tdo\n-\t\tif remove_cr \"$f\" >/dev/null\n+\t\tif has_cr \"$f\"\n \t\tthen\n \t\t\techo \"Eh? $f\"\n \t\t\tfalse\n@@ -245,7 +232,7 @@ test_expect_success 'apply patch (autocrlf=true)' '\n \tgit read-tree --reset -u HEAD &&\n \n \tgit apply patch.file &&\n-\ttest \"$patched\" = \"`remove_cr one | git hash-object --stdin`\" || {\n+\ttest \"$patched\" = \"`remove_cr <one | git hash-object --stdin`\" || {\n \t\techo \"Eh?  apply without index\"\n \t\tfalse\n \t}\n@@ -272,7 +259,7 @@ test_expect_success 'apply patch --index (autocrlf=true)' '\n \n \tgit apply --index patch.file &&\n \ttest \"$patched\" = `git rev-parse :one` &&\n-\ttest \"$patched\" = \"`remove_cr one | git hash-object --stdin`\" || {\n+\ttest \"$patched\" = \"`remove_cr <one | git hash-object --stdin`\" || {\n \t\techo \"Eh?  apply with --index\"\n \t\tfalse\n \t}\n@@ -285,7 +272,7 @@ test_expect_success '.gitattributes says two is binary' '\n \tgit config core.autocrlf true &&\n \tgit read-tree --reset -u HEAD &&\n \n-\tif remove_cr dir/two >/dev/null\n+\tif has_cr dir/two\n \tthen\n \t\techo \"Huh?\"\n \t\tfalse\n@@ -293,7 +280,7 @@ test_expect_success '.gitattributes says two is binary' '\n \t\t: happy\n \tfi &&\n \n-\tif remove_cr one >/dev/null\n+\tif has_cr one\n \tthen\n \t\t: happy\n \telse\n@@ -301,7 +288,7 @@ test_expect_success '.gitattributes says two is binary' '\n \t\tfalse\n \tfi &&\n \n-\tif remove_cr three >/dev/null\n+\tif has_cr three\n \tthen\n \t\techo \"Huh?\"\n \t\tfalse\n@@ -316,7 +303,7 @@ test_expect_success '.gitattributes says two is input' '\n \techo \"two crlf=input\" >.gitattributes &&\n \tgit read-tree --reset -u HEAD &&\n \n-\tif remove_cr dir/two >/dev/null\n+\tif has_cr dir/two\n \tthen\n \t\techo \"Huh?\"\n \t\tfalse\n@@ -331,7 +318,7 @@ test_expect_success '.gitattributes says two and three are text' '\n \techo \"t* crlf\" >.gitattributes &&\n \tgit read-tree --reset -u HEAD &&\n \n-\tif remove_cr dir/two >/dev/null\n+\tif has_cr dir/two\n \tthen\n \t\t: happy\n \telse\n@@ -339,7 +326,7 @@ test_expect_success '.gitattributes says two and three are text' '\n \t\tfalse\n \tfi &&\n \n-\tif remove_cr three >/dev/null\n+\tif has_cr three\n \tthen\n \t\t: happy\n \telse\n@@ -357,14 +344,14 @@ test_expect_success 'in-tree .gitattributes (1)' '\n \trm -rf tmp one dir .gitattributes patch.file three &&\n \tgit read-tree --reset -u HEAD &&\n \n-\tif remove_cr one >/dev/null\n+\tif has_cr one\n \tthen\n \t\techo \"Eh? one should not have CRLF\"\n \t\tfalse\n \telse\n \t\t: happy\n \tfi &&\n-\tremove_cr three >/dev/null || {\n+\thas_cr three || {\n \t\techo \"Eh? three should still have CRLF\"\n \t\tfalse\n \t}\n@@ -376,14 +363,14 @@ test_expect_success 'in-tree .gitattributes (2)' '\n \tgit read-tree --reset HEAD &&\n \tgit checkout-index -f -q -u -a &&\n \n-\tif remove_cr one >/dev/null\n+\tif has_cr one\n \tthen\n \t\techo \"Eh? one should not have CRLF\"\n \t\tfalse\n \telse\n \t\t: happy\n \tfi &&\n-\tremove_cr three >/dev/null || {\n+\thas_cr three || {\n \t\techo \"Eh? three should still have CRLF\"\n \t\tfalse\n \t}\n@@ -396,14 +383,14 @@ test_expect_success 'in-tree .gitattributes (3)' '\n \tgit checkout-index -u .gitattributes &&\n \tgit checkout-index -u one dir/two three &&\n \n-\tif remove_cr one >/dev/null\n+\tif has_cr one\n \tthen\n \t\techo \"Eh? one should not have CRLF\"\n \t\tfalse\n \telse\n \t\t: happy\n \tfi &&\n-\tremove_cr three >/dev/null || {\n+\thas_cr three || {\n \t\techo \"Eh? three should still have CRLF\"\n \t\tfalse\n \t}\n@@ -416,14 +403,14 @@ test_expect_success 'in-tree .gitattributes (4)' '\n \tgit checkout-index -u one dir/two three &&\n \tgit checkout-index -u .gitattributes &&\n \n-\tif remove_cr one >/dev/null\n+\tif has_cr one\n \tthen\n \t\techo \"Eh? one should not have CRLF\"\n \t\tfalse\n \telse\n \t\t: happy\n \tfi &&\n-\tremove_cr three >/dev/null || {\n+\thas_cr three || {\n \t\techo \"Eh? three should still have CRLF\"\n \t\tfalse\n \t}\n@@ -456,7 +443,7 @@ test_expect_success 'checkout when deleting .gitattributes' '\n \n \tgit checkout master~1 &&\n \tgit checkout master &&\n-\tremove_cr .file2 >/dev/null\n+\thas_cr .file2\n \n '\n \ndiff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh\nindex 4e6a44b..4314ad2 100755\n--- a/t/t3400-rebase.sh\n+++ b/t/t3400-rebase.sh\n@@ -134,10 +134,6 @@ test_expect_success 'rebase -q is quiet' '\n      test ! -s output.out\n '\n \n-q_to_cr () {\n-\ttr Q '\\015'\n-}\n-\n test_expect_success 'Rebase a commit that sprinkles CRs in' '\n \t(\n \t\techo \"One\"\ndiff --git a/t/t4012-diff-binary.sh b/t/t4012-diff-binary.sh\nindex f64aa48..bc46563 100755\n--- a/t/t4012-diff-binary.sh\n+++ b/t/t4012-diff-binary.sh\n@@ -77,10 +77,6 @@ test_expect_success 'apply binary patch' \\\n \t tree1=`git write-tree` &&\n \t test \"$tree1\" = \"$tree0\"'\n \n-q_to_nul() {\n-\tperl -pe 'y/Q/\\000/'\n-}\n-\n nul_to_q() {\n \tperl -pe 'y/\\000/Q/'\n }\ndiff --git a/t/t6033-merge-crlf.sh b/t/t6033-merge-crlf.sh\nindex 75d9602..e8d65ee 100755\n--- a/t/t6033-merge-crlf.sh\n+++ b/t/t6033-merge-crlf.sh\n@@ -1,13 +1,5 @@\n #!/bin/sh\n \n-append_cr () {\n-\tsed -e 's/$/Q/' | tr Q '\\015'\n-}\n-\n-remove_cr () {\n-\ttr '\\015' Q | sed -e 's/Q$//'\n-}\n-\n test_description='merge conflict in crlf repo\n \n \t\tb---M\ndiff --git a/t/t9401-git-cvsserver-crlf.sh b/t/t9401-git-cvsserver-crlf.sh\nindex 40637d6..ed7b513 100755\n--- a/t/t9401-git-cvsserver-crlf.sh\n+++ b/t/t9401-git-cvsserver-crlf.sh\n@@ -11,14 +11,6 @@ repository using cvs CLI client via git-cvsserver server'\n \n . ./test-lib.sh\n \n-q_to_nul () {\n-    perl -pe 'y/Q/\\000/'\n-}\n-\n-q_to_cr () {\n-    tr Q '\\015'\n-}\n-\n marked_as () {\n     foundEntry=\"$(grep \"^/$2/\" \"$1/CVS/Entries\")\"\n     if [ x\"$foundEntry\" = x\"\" ] ; then\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex baa4093..afd3053 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -230,6 +230,22 @@ test_decode_color () {\n \t\t-e 's/.\\[m/<RESET>/g'\n }\n \n+q_to_nul () {\n+\tperl -pe 'y/Q/\\000/'\n+}\n+\n+q_to_cr () {\n+\ttr Q '\\015'\n+}\n+\n+append_cr () {\n+\tsed -e 's/$/Q/' | tr Q '\\015'\n+}\n+\n+remove_cr () {\n+\ttr '\\015' Q | sed -e 's/Q$//'\n+}\n+\n test_tick () {\n \tif test -z \"${test_tick+set}\"\n \tthen\n-- \n1.7.0.rc0\n"},{"id":"132653","messageId":"1264466039-22431-3-git-send-email-bebarino@gmail.com","threadId":"22393","inReplyTo":"1264466039-22431-1-git-send-email-bebarino@gmail.com","subject":"[PATCHv3 2/3] t0022: replace non-portable literal CR","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2010-01-26T00:33:58Z","receivedAt":"2010-01-26T00:33:58Z","isPatch":false,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"We shouldn't have literal CR's in tests as they aren't portable.\n\nSigned-off-by: Stephen Boyd <bebarino@gmail.com>\n---\n\nHopefully this isn't botched over the wire.\n\n t/t0022-crlf-rename.sh |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/t/t0022-crlf-rename.sh b/t/t0022-crlf-rename.sh\nindex f1e1d48..7af3fbc 100755\n--- a/t/t0022-crlf-rename.sh\n+++ b/t/t0022-crlf-rename.sh\n@@ -12,7 +12,7 @@ test_expect_success setup '\n \ttest_tick &&\n \tgit commit -m Initial &&\n \n-\tsed -e \"s/\\$/\n/\" \"$TEST_DIRECTORY\"/t0022-crlf-rename.sh >elpmas &&\n+\tappend_cr <\"$TEST_DIRECTORY\"/t0022-crlf-rename.sh >elpmas &&\n \tgit add elpmas &&\n \trm -f sample &&\n \n-- \n1.7.0.rc0\n"},{"id":"132654","messageId":"1264466039-22431-4-git-send-email-bebarino@gmail.com","threadId":"22393","inReplyTo":"1264466039-22431-1-git-send-email-bebarino@gmail.com","subject":"[PATCHv3 3/3] am: fix patch format detection for Thunderbird \"Save As\" emails","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2010-01-26T00:33:59Z","receivedAt":"2010-01-26T00:33:59Z","isPatch":false,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"The patch detection wants to inspect all the headers of a rfc2822 message\nand ensure that they look like header fields. The headers are always\nseparated from the message body with a blank line. When Thunderbird saves\nthe message the blank line separating the headers from the body includes a\nCR. The patch detection is failing because a CRLF doesn't match /^$/. Fix\nthis by allowing a CR to exist on the separating line.\n\nSigned-off-by: Stephen Boyd <bebarino@gmail.com>\n---\n\nI gave up trying to make it portable and now just use append_cr() from\ntest-lib. Hopefully this is a much better and simpler approach.\n\n git-am.sh     |    3 ++-\n t/t4150-am.sh |   15 +++++++++++++++\n 2 files changed, 17 insertions(+), 1 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex 2f46fda..c8b9cbb 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -205,7 +205,8 @@ check_patch_format () {\n \t\t\t# discarding the indented remainder of folded lines,\n \t\t\t# and see if it looks like that they all begin with the\n \t\t\t# header field names...\n-\t\t\tsed -n -e '/^$/q' -e '/^[ \t]/d' -e p \"$1\" |\n+\t\t\ttr -d '\\015' <\"$1\" |\n+\t\t\tsed -n -e '/^$/q' -e '/^[ \t]/d' -e p |\n \t\t\tsane_egrep -v '^[!-9;-~]+:' >/dev/null ||\n \t\t\tpatch_format=mbox\n \t\tfi\ndiff --git a/t/t4150-am.sh b/t/t4150-am.sh\nindex 8296605..a034918 100755\n--- a/t/t4150-am.sh\n+++ b/t/t4150-am.sh\n@@ -83,6 +83,12 @@ test_expect_success setup '\n \t\techo \"X-Fake-Field: Line Three\" &&\n \t\tgit format-patch --stdout first | sed -e \"1d\"\n \t} > patch1.eml &&\n+\t{\n+\t\techo \"X-Fake-Field: Line One\" &&\n+\t\techo \"X-Fake-Field: Line Two\" &&\n+\t\techo \"X-Fake-Field: Line Three\" &&\n+\t\tgit format-patch --stdout first | sed -e \"1d\"\n+\t} | append_cr >patch1-crlf.eml &&\n \tsed -n -e \"3,\\$p\" msg >file &&\n \tgit add file &&\n \ttest_tick &&\n@@ -123,6 +129,15 @@ test_expect_success 'am applies patch e-mail not in a mbox' '\n \ttest \"$(git rev-parse second^)\" = \"$(git rev-parse HEAD^)\"\n '\n \n+test_expect_success 'am applies patch e-mail not in a mbox with CRLF' '\n+\tgit checkout first &&\n+\tgit am patch1-crlf.eml &&\n+\t! test -d .git/rebase-apply &&\n+\ttest -z \"$(git diff second)\" &&\n+\ttest \"$(git rev-parse second)\" = \"$(git rev-parse HEAD)\" &&\n+\ttest \"$(git rev-parse second^)\" = \"$(git rev-parse HEAD^)\"\n+'\n+\n GIT_AUTHOR_NAME=\"Another Thor\"\n GIT_AUTHOR_EMAIL=\"a.thor@example.com\"\n GIT_COMMITTER_NAME=\"Co M Miter\"\n-- \n1.7.0.rc0\n"},{"id":"132656","messageId":"7vwrz51x41.fsf@alter.siamese.dyndns.org","threadId":"22393","inReplyTo":"1264466039-22431-1-git-send-email-bebarino@gmail.com","subject":"Re: [PATCHv3 0/3] Fix patch detection for thunderbird saved mails","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-01-26T01:19:26Z","receivedAt":"2010-01-26T01:19:26Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Looks sensible; thanks.\n"}]}