1 From 5cff6a6469599a012b94b2f9d7519900ab19fd2f Mon Sep 17 00:00:00 2001
2 From: Sven Strickroth <email@cs-ware.de>
3 Date: Fri, 23 Jan 2015 17:15:16 +0100
4 Subject: [PATCH 4/6] Make files with #CR!=#CRLF not fail with
7 Signed-off-by: Sven Strickroth <email@cs-ware.de>
10 src/crlf.c | 18 +++++++++---------
11 tests/filter/crlf.c | 7 +++++++
12 3 files changed, 17 insertions(+), 9 deletions(-)
14 diff --git a/CHANGELOG.md b/CHANGELOG.md
15 index c31d921..d210632 100644
18 @@ -13,6 +13,7 @@ v0.22 + 1
19 * LF -> CRLF filter now correctly honors core.safecrlf=true errors
20 * LF only files were accepted with core.autocrlf=true on CRLF platforms
21 * files containig CRLF in combination with core.autocrlf=input were accepted
22 + * adding files containing CR and CRLF but not the same number failed
24 * Rename and copy detection is enabled for small files.
26 diff --git a/src/crlf.c b/src/crlf.c
27 index 29bbb5f..2de107c 100644
30 @@ -138,12 +138,20 @@ static int crlf_apply_to_odb(
31 if (git_buf_text_gather_stats(&stats, from, false))
32 return GIT_PASSTHROUGH;
35 + * We're currently not going to even try to convert stuff
36 + * that has bare CR characters. Does anybody do that crazy
39 + if (stats.cr != stats.crlf)
40 + return GIT_PASSTHROUGH;
42 /* If there are no CR characters to filter out and CrLf is not set to "true", then just pass */
43 if (!stats.cr && ca->auto_crlf != GIT_AUTO_CRLF_TRUE)
44 return GIT_PASSTHROUGH;
46 /* If safecrlf is enabled, sanity-check the result. */
47 - if (stats.cr != stats.crlf || stats.lf != stats.crlf) {
48 + if (stats.lf != stats.crlf) {
49 switch (ca->safe_crlf) {
50 case GIT_SAFE_CRLF_FAIL:
52 @@ -171,14 +179,6 @@ static int crlf_apply_to_odb(
57 - * We're currently not going to even try to convert stuff
58 - * that has bare CR characters. Does anybody do that crazy
61 - if (stats.cr != stats.crlf)
62 - return GIT_PASSTHROUGH;
64 if (ca->crlf_action == GIT_CRLF_GUESS) {
66 * If the file in the index has any CR in it, do not convert.
67 diff --git a/tests/filter/crlf.c b/tests/filter/crlf.c
68 index 3490f1e..d1bf7a4 100644
69 --- a/tests/filter/crlf.c
70 +++ b/tests/filter/crlf.c
71 @@ -106,6 +106,13 @@ void test_filter_crlf__with_safecrlf(void)
72 cl_git_fail(git_filter_list_apply_to_data(&out, fl, &in));
73 cl_assert_equal_i(giterr_last()->klass, GITERR_FILTER);
75 + /* String with \r but without \r\n does not fail with safecrlf */
76 + in.ptr = "Normal\nCR only\rand some more\nline-endings.\n";
77 + in.size = strlen(in.ptr);
79 + cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
80 + cl_assert_equal_s("Normal\nCR only\rand some more\nline-endings.\n", out.ptr);
82 git_filter_list_free(fl);