12
* translation when the "text" attribute or "auto_crlf" option is set.
13
*/
14
15
-enum action {
15
+enum crlf_action {
16
CRLF_GUESS = -1,
17
CRLF_BINARY = 0,
18
CRLF_TEXT,
94
return 0;
95
}
96
97
-static enum eol determine_output_conversion(enum action action)
97
+static enum eol output_eol(enum crlf_action crlf_action)
98
{
99
- switch (action) {
99
+ switch (crlf_action) {
100
case CRLF_BINARY:
101
return EOL_UNSET;
102
case CRLF_CRLF:
119
return core_eol;
120
}
121
122
-static void check_safe_crlf(const char *path, enum action action,
122
+static void check_safe_crlf(const char *path, enum crlf_action crlf_action,
123
struct text_stat *stats, enum safe_crlf checksafe)
124
{
125
if (!checksafe)
126
return;
127
128
- if (determine_output_conversion(action) == EOL_LF) {
128
+ if (output_eol(crlf_action) == EOL_LF) {
129
/*
130
* CRLFs would not be restored by checkout:
131
* check if we'd remove CRLFs
136
else /* i.e. SAFE_CRLF_FAIL */
137
die("CRLF would be replaced by LF in %s.", path);
138
}
139
- } else if (determine_output_conversion(action) == EOL_CRLF) {
139
+ } else if (output_eol(crlf_action) == EOL_CRLF) {
140
/*
141
* CRLFs would be added by checkout:
142
* check if we have "naked" LFs
188
}
189
190
static int crlf_to_git(const char *path, const char *src, size_t len,
191
- struct strbuf *buf, enum action action, enum safe_crlf checksafe)
191
+ struct strbuf *buf,
192
+ enum crlf_action crlf_action, enum safe_crlf checksafe)
193
{
194
struct text_stat stats;
195
char *dst;
196
196
- if (action == CRLF_BINARY ||
197
- (action == CRLF_GUESS && auto_crlf == AUTO_CRLF_FALSE) || !len)
197
+ if (crlf_action == CRLF_BINARY ||
198
+ (crlf_action == CRLF_GUESS && auto_crlf == AUTO_CRLF_FALSE) || !len)
199
return 0;
200
201
gather_stats(src, len, &stats);
202
202
- if (action == CRLF_AUTO || action == CRLF_GUESS) {
203
+ if (crlf_action == CRLF_AUTO || crlf_action == CRLF_GUESS) {
204
/*
205
* We're currently not going to even try to convert stuff
206
* that has bare CR characters. Does anybody do that crazy
215
if (is_binary(len, &stats))
216
return 0;
217
217
- if (action == CRLF_GUESS) {
218
+ if (crlf_action == CRLF_GUESS) {
219
/*
220
* If the file in the index has any CR in it, do not convert.
221
* This is the new safer autocrlf handling.
225
}
226
}
227
227
- check_safe_crlf(path, action, &stats, checksafe);
228
+ check_safe_crlf(path, crlf_action, &stats, checksafe);
229
230
/* Optimization: No CR? Nothing to convert, regardless. */
231
if (!stats.cr)
235
if (strbuf_avail(buf) + buf->len < len)
236
strbuf_grow(buf, len - buf->len);
237
dst = buf->buf;
237
- if (action == CRLF_AUTO || action == CRLF_GUESS) {
238
+ if (crlf_action == CRLF_AUTO || crlf_action == CRLF_GUESS) {
239
/*
240
* If we guessed, we already know we rejected a file with
241
* lone CR, and we can strip a CR without looking at what
258
}
259
260
static int crlf_to_worktree(const char *path, const char *src, size_t len,
260
- struct strbuf *buf, enum action action)
261
+ struct strbuf *buf, enum crlf_action crlf_action)
262
{
263
char *to_free = NULL;
264
struct text_stat stats;
265
265
- if (!len || determine_output_conversion(action) != EOL_CRLF)
266
+ if (!len || output_eol(crlf_action) != EOL_CRLF)
267
return 0;
268
269
gather_stats(src, len, &stats);
276
if (stats.lf == stats.crlf)
277
return 0;
278
278
- if (action == CRLF_AUTO || action == CRLF_GUESS) {
279
- if (action == CRLF_GUESS) {
279
+ if (crlf_action == CRLF_AUTO || crlf_action == CRLF_GUESS) {
280
+ if (crlf_action == CRLF_GUESS) {
281
/* If we have any CR or CRLF line endings, we do not touch it */
282
/* This is the new safer autocrlf-handling */
283
if (stats.cr > 0 || stats.crlf > 0)
716
return !!ATTR_TRUE(value);
717
}
718
718
-static enum action determine_action(enum action text_attr, enum eol eol_attr)
719
+static enum crlf_action input_crlf_action(enum crlf_action text_attr, enum eol eol_attr)
720
{
721
if (text_attr == CRLF_BINARY)
722
return CRLF_BINARY;
731
struct strbuf *dst, enum safe_crlf checksafe)
732
{
733
struct git_attr_check check[5];
733
- enum action action = CRLF_GUESS;
734
+ enum crlf_action crlf_action = CRLF_GUESS;
735
enum eol eol_attr = EOL_UNSET;
736
int ident = 0, ret = 0;
737
const char *filter = NULL;
739
setup_convert_check(check);
740
if (!git_checkattr(path, ARRAY_SIZE(check), check)) {
741
struct convert_driver *drv;
741
- action = git_path_check_crlf(path, check + 4);
742
- if (action == CRLF_GUESS)
743
- action = git_path_check_crlf(path, check + 0);
742
+ crlf_action = git_path_check_crlf(path, check + 4);
743
+ if (crlf_action == CRLF_GUESS)
744
+ crlf_action = git_path_check_crlf(path, check + 0);
745
ident = git_path_check_ident(path, check + 1);
746
drv = git_path_check_convert(path, check + 2);
747
eol_attr = git_path_check_eol(path, check + 3);
754
src = dst->buf;
755
len = dst->len;
756
}
756
- action = determine_action(action, eol_attr);
757
- ret |= crlf_to_git(path, src, len, dst, action, checksafe);
757
+ crlf_action = input_crlf_action(crlf_action, eol_attr);
758
+ ret |= crlf_to_git(path, src, len, dst, crlf_action, checksafe);
759
if (ret) {
760
src = dst->buf;
761
len = dst->len;
768
int normalizing)
769
{
770
struct git_attr_check check[5];
770
- enum action action = CRLF_GUESS;
771
+ enum crlf_action crlf_action = CRLF_GUESS;
772
enum eol eol_attr = EOL_UNSET;
773
int ident = 0, ret = 0;
774
const char *filter = NULL;
776
setup_convert_check(check);
777
if (!git_checkattr(path, ARRAY_SIZE(check), check)) {
778
struct convert_driver *drv;
778
- action = git_path_check_crlf(path, check + 4);
779
- if (action == CRLF_GUESS)
780
- action = git_path_check_crlf(path, check + 0);
779
+ crlf_action = git_path_check_crlf(path, check + 4);
780
+ if (crlf_action == CRLF_GUESS)
781
+ crlf_action = git_path_check_crlf(path, check + 0);
782
ident = git_path_check_ident(path, check + 1);
783
drv = git_path_check_convert(path, check + 2);
784
eol_attr = git_path_check_eol(path, check + 3);
796
* is a smudge filter. The filter might expect CRLFs.
797
*/
798
if (filter || !normalizing) {
798
- action = determine_action(action, eol_attr);
799
- ret |= crlf_to_worktree(path, src, len, dst, action);
799
+ crlf_action = input_crlf_action(crlf_action, eol_attr);
800
+ ret |= crlf_to_worktree(path, src, len, dst, crlf_action);
801
if (ret) {
802
src = dst->buf;
803
len = dst->len;