Use GitHash instead of CString
[TortoiseGit.git] / ext / libgit2-0004-Make-files-with-CR-CRLF-not-fail-with-core.safecrlf-.patch
blobf25fe0f0953991d283ead6a4aa8e004f0e77a7fb
1 From 78b6049046afcb041d785b56641664f5ffa99e9f 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/8] Make files with #CR!=#CRLF not fail with
5 core.safecrlf=true
7 Signed-off-by: Sven Strickroth <email@cs-ware.de>
8 ---
9 CHANGELOG.md | 1 +
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 e06155e2a..23702a3cb 100644
16 --- a/CHANGELOG.md
17 +++ b/CHANGELOG.md
18 @@ -10,6 +10,7 @@ v0.25 + 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 ### API additions
26 diff --git a/src/crlf.c b/src/crlf.c
27 index dd5a7625c..858a94484 100644
28 --- a/src/crlf.c
29 +++ b/src/crlf.c
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;
34 + /*
35 + * We're currently not going to even try to convert stuff
36 + * that has bare CR characters. Does anybody do that crazy
37 + * stuff?
38 + */
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:
51 giterr_set(
52 @@ -171,14 +179,6 @@ static int crlf_apply_to_odb(
56 - /*
57 - * We're currently not going to even try to convert stuff
58 - * that has bare CR characters. Does anybody do that crazy
59 - * stuff?
60 - */
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 3490f1e0d..d1bf7a450 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);
83 git_buf_free(&out);
85 --
86 2.11.0.windows.3