Fix warning
[TortoiseGit.git] / ext / libgit2-0005-Make-CRLF-filter-behave-like-vanilla-git-for-adding-.patch
blobe2ed01781d8418f6c3e19c0f39d0322a765b3ad4
1 From 1855ca47e678e00ba9151f9734d7e682b7c67f6d Mon Sep 17 00:00:00 2001
2 From: Sven Strickroth <email@cs-ware.de>
3 Date: Sun, 1 Feb 2015 13:39:31 +0100
4 Subject: [PATCH] Make CRLF filter behave like vanilla git for adding files
5 in combination with attributes
7 Based on lots of manual testing (even with "malformed" files and binary) with vanilla git executable...
9 Signed-off-by: Sven Strickroth <email@cs-ware.de>
10 ---
11 src/crlf.c | 57 +++++++++++++++++++++++++++++++++------------------------
12 1 files changed, 29 insertions(+), 28 deletions(-)
14 diff --git a/src/crlf.c b/src/crlf.c
15 index 858a94484..468f33b4c 100644
16 --- a/src/crlf.c
17 +++ b/src/crlf.c
18 @@ -124,18 +124,21 @@ static int crlf_apply_to_odb(
19 const git_buf *from,
20 const git_filter_source *src)
22 + git_buf_text_stats stats;
23 + bool is_binary;
25 /* Empty file? Nothing to do */
26 if (!git_buf_len(from))
27 return 0;
29 + is_binary = git_buf_text_gather_stats(&stats, from, false);
31 /* Heuristics to see if we can skip the conversion.
32 * Straight from Core Git.
34 if (ca->crlf_action == GIT_CRLF_AUTO || ca->crlf_action == GIT_CRLF_GUESS) {
35 - git_buf_text_stats stats;
37 - /* Check heuristics for binary vs text - returns true if binary */
38 - if (git_buf_text_gather_stats(&stats, from, false))
39 + /* Check heuristics for binary vs text */
40 + if (is_binary)
41 return GIT_PASSTHROUGH;
44 @@ -146,16 +149,26 @@ static int crlf_apply_to_odb(
45 if (stats.cr != stats.crlf)
46 return GIT_PASSTHROUGH;
48 - /* If there are no CR characters to filter out and CrLf is not set to "true", then just pass */
49 - if (!stats.cr && ca->auto_crlf != GIT_AUTO_CRLF_TRUE)
50 - return GIT_PASSTHROUGH;
51 + if (ca->crlf_action == GIT_CRLF_GUESS) {
52 + /*
53 + * If the file in the index has any CR in it, do not convert.
54 + * This is the new safer autocrlf handling.
55 + */
56 + if (has_cr_in_index(src))
57 + return GIT_PASSTHROUGH;
58 + }
59 + }
61 - /* If safecrlf is enabled, sanity-check the result. */
62 - if (stats.lf != stats.crlf) {
63 + /* If safecrlf is enabled, sanity-check the result. */
64 + if (ca->crlf_action == GIT_CRLF_INPUT ||
65 + (ca->auto_crlf == GIT_AUTO_CRLF_INPUT &&
66 + (ca->crlf_action == GIT_CRLF_GUESS || ca->crlf_action == GIT_CRLF_AUTO ||
67 + (ca->crlf_action == GIT_CRLF_TEXT && ca->eol==GIT_EOL_UNSET)))) {
68 + if (stats.crlf) {
69 switch (ca->safe_crlf) {
70 case GIT_SAFE_CRLF_FAIL:
71 giterr_set(
72 - GITERR_FILTER, "LF would be replaced by CRLF in '%s'",
73 + GITERR_FILTER, "CRLF would be replaced by LF in '%s'",
74 git_filter_source_path(src));
75 return -1;
76 case GIT_SAFE_CRLF_WARN:
77 @@ -164,11 +177,15 @@ static int crlf_apply_to_odb(
78 default:
79 break;
81 - } else if (stats.crlf && ca->auto_crlf == GIT_AUTO_CRLF_INPUT) {
82 + }
83 + } else if (ca->crlf_action == GIT_CRLF_CRLF ||
84 + (ca->auto_crlf == GIT_AUTO_CRLF_TRUE && ca->crlf_action == GIT_CRLF_GUESS ||
85 + ((ca->crlf_action == GIT_CRLF_TEXT || ca->crlf_action == GIT_CRLF_AUTO) && ca->eol == GIT_EOL_UNSET))) {
86 + if (stats.lf != stats.crlf) {
87 switch (ca->safe_crlf) {
88 case GIT_SAFE_CRLF_FAIL:
89 giterr_set(
90 - GITERR_FILTER, "CRLF would be replaced by LF in '%s'",
91 + GITERR_FILTER, "LF would be replaced by CRLF in '%s'",
92 git_filter_source_path(src));
93 return -1;
94 case GIT_SAFE_CRLF_WARN:
95 @@ -178,20 +195,12 @@ static int crlf_apply_to_odb(
96 break;
100 - if (ca->crlf_action == GIT_CRLF_GUESS) {
101 - /*
102 - * If the file in the index has any CR in it, do not convert.
103 - * This is the new safer autocrlf handling.
104 - */
105 - if (has_cr_in_index(src))
106 - return GIT_PASSTHROUGH;
109 - if (!stats.cr)
110 - return GIT_PASSTHROUGH;
113 + /* If there are no CR characters to filter out, then just pass */
114 + if (!stats.cr)
115 + return GIT_PASSTHROUGH;
117 /* Actually drop the carriage returns */
118 return git_buf_text_crlf_to_lf(to, from);
121 2.11.0.windows.3