Initialize member in initializer list
[TortoiseGit.git] / ext / libgit2-0005-Make-CRLF-filter-behave-like-vanilla-git-for-adding-.patch
blob8da80ff3711284bfe49af0c97d926f178f9d660a
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 5/8] 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 CHANGELOG.md | 8 ++++----
12 src/crlf.c | 57 +++++++++++++++++++++++++++++++++------------------------
13 2 files changed, 37 insertions(+), 28 deletions(-)
15 diff --git a/CHANGELOG.md b/CHANGELOG.md
16 index 23702a3cb..99473edd7 100644
17 --- a/CHANGELOG.md
18 +++ b/CHANGELOG.md
19 @@ -7,10 +7,10 @@ v0.25 + 1
20 This aligns this structure with the default by `git_merge` and
21 `git_merge_trees` when `NULL` was provided for the options.
23 -* LF -> CRLF filter now correctly honors core.safecrlf=true errors
24 - * LF only files were accepted with core.autocrlf=true on CRLF platforms
25 - * files containig CRLF in combination with core.autocrlf=input were accepted
26 - * adding files containing CR and CRLF but not the same number failed
27 +* LF -> CRLF filter now handles files on adding to index the way vanilla git does
28 + * skip files marked as "binary" (-crlf)
29 + * especially files containing single CR chars are added as is now
30 + * honor "text" attribute for forcing a file being interpreted as text
32 ### API additions
34 diff --git a/src/crlf.c b/src/crlf.c
35 index 858a94484..468f33b4c 100644
36 --- a/src/crlf.c
37 +++ b/src/crlf.c
38 @@ -124,18 +124,21 @@ static int crlf_apply_to_odb(
39 const git_buf *from,
40 const git_filter_source *src)
42 + git_buf_text_stats stats;
43 + bool is_binary;
45 /* Empty file? Nothing to do */
46 if (!git_buf_len(from))
47 return 0;
49 + is_binary = git_buf_text_gather_stats(&stats, from, false);
51 /* Heuristics to see if we can skip the conversion.
52 * Straight from Core Git.
54 if (ca->crlf_action == GIT_CRLF_AUTO || ca->crlf_action == GIT_CRLF_GUESS) {
55 - git_buf_text_stats stats;
57 - /* Check heuristics for binary vs text - returns true if binary */
58 - if (git_buf_text_gather_stats(&stats, from, false))
59 + /* Check heuristics for binary vs text */
60 + if (is_binary)
61 return GIT_PASSTHROUGH;
64 @@ -146,16 +149,26 @@ static int crlf_apply_to_odb(
65 if (stats.cr != stats.crlf)
66 return GIT_PASSTHROUGH;
68 - /* If there are no CR characters to filter out and CrLf is not set to "true", then just pass */
69 - if (!stats.cr && ca->auto_crlf != GIT_AUTO_CRLF_TRUE)
70 - return GIT_PASSTHROUGH;
71 + if (ca->crlf_action == GIT_CRLF_GUESS) {
72 + /*
73 + * If the file in the index has any CR in it, do not convert.
74 + * This is the new safer autocrlf handling.
75 + */
76 + if (has_cr_in_index(src))
77 + return GIT_PASSTHROUGH;
78 + }
79 + }
81 - /* If safecrlf is enabled, sanity-check the result. */
82 - if (stats.lf != stats.crlf) {
83 + /* If safecrlf is enabled, sanity-check the result. */
84 + if (ca->crlf_action == GIT_CRLF_INPUT ||
85 + (ca->auto_crlf == GIT_AUTO_CRLF_INPUT &&
86 + (ca->crlf_action == GIT_CRLF_GUESS || ca->crlf_action == GIT_CRLF_AUTO ||
87 + (ca->crlf_action == GIT_CRLF_TEXT && ca->eol==GIT_EOL_UNSET)))) {
88 + if (stats.crlf) {
89 switch (ca->safe_crlf) {
90 case GIT_SAFE_CRLF_FAIL:
91 giterr_set(
92 - GITERR_FILTER, "LF would be replaced by CRLF in '%s'",
93 + GITERR_FILTER, "CRLF would be replaced by LF in '%s'",
94 git_filter_source_path(src));
95 return -1;
96 case GIT_SAFE_CRLF_WARN:
97 @@ -164,11 +177,15 @@ static int crlf_apply_to_odb(
98 default:
99 break;
101 - } else if (stats.crlf && ca->auto_crlf == GIT_AUTO_CRLF_INPUT) {
103 + } else if (ca->crlf_action == GIT_CRLF_CRLF ||
104 + (ca->auto_crlf == GIT_AUTO_CRLF_TRUE && ca->crlf_action == GIT_CRLF_GUESS ||
105 + ((ca->crlf_action == GIT_CRLF_TEXT || ca->crlf_action == GIT_CRLF_AUTO) && ca->eol == GIT_EOL_UNSET))) {
106 + if (stats.lf != stats.crlf) {
107 switch (ca->safe_crlf) {
108 case GIT_SAFE_CRLF_FAIL:
109 giterr_set(
110 - GITERR_FILTER, "CRLF would be replaced by LF in '%s'",
111 + GITERR_FILTER, "LF would be replaced by CRLF in '%s'",
112 git_filter_source_path(src));
113 return -1;
114 case GIT_SAFE_CRLF_WARN:
115 @@ -178,20 +195,12 @@ static int crlf_apply_to_odb(
116 break;
120 - if (ca->crlf_action == GIT_CRLF_GUESS) {
121 - /*
122 - * If the file in the index has any CR in it, do not convert.
123 - * This is the new safer autocrlf handling.
124 - */
125 - if (has_cr_in_index(src))
126 - return GIT_PASSTHROUGH;
129 - if (!stats.cr)
130 - return GIT_PASSTHROUGH;
133 + /* If there are no CR characters to filter out, then just pass */
134 + if (!stats.cr)
135 + return GIT_PASSTHROUGH;
137 /* Actually drop the carriage returns */
138 return git_buf_text_crlf_to_lf(to, from);
141 2.11.0.windows.3