19
19
#define CONVERT_STAT_BITS_BIN 0x4
20
20
21
21
enum crlf_action {
22
- CRLF_GUESS = -1 ,
23
- CRLF_BINARY = 0 ,
22
+ CRLF_UNDEFINED ,
23
+ CRLF_BINARY ,
24
24
CRLF_TEXT ,
25
- CRLF_INPUT ,
26
- CRLF_CRLF ,
27
- CRLF_AUTO
25
+ CRLF_TEXT_INPUT ,
26
+ CRLF_TEXT_CRLF ,
27
+ CRLF_AUTO ,
28
+ CRLF_AUTO_INPUT ,
29
+ CRLF_AUTO_CRLF
28
30
};
29
31
30
32
struct text_stat {
@@ -167,18 +169,19 @@ static enum eol output_eol(enum crlf_action crlf_action)
167
169
switch (crlf_action ) {
168
170
case CRLF_BINARY :
169
171
return EOL_UNSET ;
170
- case CRLF_CRLF :
172
+ case CRLF_TEXT_CRLF :
171
173
return EOL_CRLF ;
172
- case CRLF_INPUT :
174
+ case CRLF_TEXT_INPUT :
173
175
return EOL_LF ;
174
- case CRLF_GUESS :
175
- if (!auto_crlf )
176
- return EOL_UNSET ;
177
- /* fall through */
176
+ case CRLF_UNDEFINED :
177
+ case CRLF_AUTO_CRLF :
178
+ case CRLF_AUTO_INPUT :
178
179
case CRLF_TEXT :
179
180
case CRLF_AUTO :
181
+ /* fall through */
180
182
return text_eol_is_crlf () ? EOL_CRLF : EOL_LF ;
181
183
}
184
+ warning ("Illegal crlf_action %d\n" , (int )crlf_action );
182
185
return core_eol ;
183
186
}
184
187
@@ -235,7 +238,6 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
235
238
char * dst ;
236
239
237
240
if (crlf_action == CRLF_BINARY ||
238
- (crlf_action == CRLF_GUESS && auto_crlf == AUTO_CRLF_FALSE ) ||
239
241
(src && !len ))
240
242
return 0 ;
241
243
@@ -248,11 +250,11 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
248
250
249
251
gather_stats (src , len , & stats );
250
252
251
- if (crlf_action == CRLF_AUTO || crlf_action == CRLF_GUESS ) {
253
+ if (crlf_action == CRLF_AUTO || crlf_action == CRLF_AUTO_INPUT || crlf_action == CRLF_AUTO_CRLF ) {
252
254
if (convert_is_binary (len , & stats ))
253
255
return 0 ;
254
256
255
- if (crlf_action == CRLF_GUESS ) {
257
+ if (crlf_action == CRLF_AUTO_INPUT || crlf_action == CRLF_AUTO_CRLF ) {
256
258
/*
257
259
* If the file in the index has any CR in it, do not convert.
258
260
* This is the new safer autocrlf handling.
@@ -279,7 +281,7 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
279
281
if (strbuf_avail (buf ) + buf -> len < len )
280
282
strbuf_grow (buf , len - buf -> len );
281
283
dst = buf -> buf ;
282
- if (crlf_action == CRLF_AUTO || crlf_action == CRLF_GUESS ) {
284
+ if (crlf_action == CRLF_AUTO || crlf_action == CRLF_AUTO_INPUT || crlf_action == CRLF_AUTO_CRLF ) {
283
285
/*
284
286
* If we guessed, we already know we rejected a file with
285
287
* lone CR, and we can strip a CR without looking at what
@@ -320,8 +322,8 @@ static int crlf_to_worktree(const char *path, const char *src, size_t len,
320
322
if (stats .lf == stats .crlf )
321
323
return 0 ;
322
324
323
- if (crlf_action == CRLF_AUTO || crlf_action == CRLF_GUESS ) {
324
- if (crlf_action == CRLF_GUESS ) {
325
+ if (crlf_action == CRLF_AUTO || crlf_action == CRLF_AUTO_INPUT || crlf_action == CRLF_AUTO_CRLF ) {
326
+ if (crlf_action == CRLF_AUTO_INPUT || crlf_action == CRLF_AUTO_CRLF ) {
325
327
/* If we have any CR or CRLF line endings, we do not touch it */
326
328
/* This is the new safer autocrlf-handling */
327
329
if (stats .cr > 0 || stats .crlf > 0 )
@@ -709,16 +711,16 @@ static enum crlf_action git_path_check_crlf(struct git_attr_check *check)
709
711
const char * value = check -> value ;
710
712
711
713
if (ATTR_TRUE (value ))
712
- return CRLF_TEXT ;
714
+ return text_eol_is_crlf () ? CRLF_TEXT_CRLF : CRLF_TEXT_INPUT ;
713
715
else if (ATTR_FALSE (value ))
714
716
return CRLF_BINARY ;
715
717
else if (ATTR_UNSET (value ))
716
718
;
717
719
else if (!strcmp (value , "input" ))
718
- return CRLF_INPUT ;
720
+ return CRLF_TEXT_INPUT ;
719
721
else if (!strcmp (value , "auto" ))
720
722
return CRLF_AUTO ;
721
- return CRLF_GUESS ;
723
+ return CRLF_UNDEFINED ;
722
724
}
723
725
724
726
static enum eol git_path_check_eol (struct git_attr_check * check )
@@ -781,7 +783,7 @@ static void convert_attrs(struct conv_attrs *ca, const char *path)
781
783
if (!git_check_attr (path , NUM_CONV_ATTRS , ccheck )) {
782
784
enum eol eol_attr ;
783
785
ca -> crlf_action = git_path_check_crlf (ccheck + 4 );
784
- if (ca -> crlf_action == CRLF_GUESS )
786
+ if (ca -> crlf_action == CRLF_UNDEFINED )
785
787
ca -> crlf_action = git_path_check_crlf (ccheck + 0 );
786
788
ca -> attr_action = ca -> crlf_action ;
787
789
ca -> ident = git_path_check_ident (ccheck + 1 );
@@ -790,14 +792,22 @@ static void convert_attrs(struct conv_attrs *ca, const char *path)
790
792
return ;
791
793
eol_attr = git_path_check_eol (ccheck + 3 );
792
794
if (eol_attr == EOL_LF )
793
- ca -> crlf_action = CRLF_INPUT ;
795
+ ca -> crlf_action = CRLF_TEXT_INPUT ;
794
796
else if (eol_attr == EOL_CRLF )
795
- ca -> crlf_action = CRLF_CRLF ;
797
+ ca -> crlf_action = CRLF_TEXT_CRLF ;
796
798
} else {
797
799
ca -> drv = NULL ;
798
- ca -> crlf_action = CRLF_GUESS ;
800
+ ca -> crlf_action = CRLF_UNDEFINED ;
799
801
ca -> ident = 0 ;
800
802
}
803
+ if (ca -> crlf_action == CRLF_TEXT )
804
+ ca -> crlf_action = text_eol_is_crlf () ? CRLF_TEXT_CRLF : CRLF_TEXT_INPUT ;
805
+ if (ca -> crlf_action == CRLF_UNDEFINED && auto_crlf == AUTO_CRLF_FALSE )
806
+ ca -> crlf_action = CRLF_BINARY ;
807
+ if (ca -> crlf_action == CRLF_UNDEFINED && auto_crlf == AUTO_CRLF_TRUE )
808
+ ca -> crlf_action = CRLF_AUTO_CRLF ;
809
+ if (ca -> crlf_action == CRLF_UNDEFINED && auto_crlf == AUTO_CRLF_INPUT )
810
+ ca -> crlf_action = CRLF_AUTO_INPUT ;
801
811
}
802
812
803
813
int would_convert_to_git_filter_fd (const char * path )
@@ -825,18 +835,22 @@ const char *get_convert_attr_ascii(const char *path)
825
835
826
836
convert_attrs (& ca , path );
827
837
switch (ca .attr_action ) {
828
- case CRLF_GUESS :
838
+ case CRLF_UNDEFINED :
829
839
return "" ;
830
840
case CRLF_BINARY :
831
841
return "-text" ;
832
842
case CRLF_TEXT :
833
843
return "text" ;
834
- case CRLF_INPUT :
844
+ case CRLF_TEXT_INPUT :
835
845
return "text eol=lf" ;
836
- case CRLF_CRLF :
837
- return "text=auto eol=crlf" ;
846
+ case CRLF_TEXT_CRLF :
847
+ return "text eol=crlf" ;
838
848
case CRLF_AUTO :
839
849
return "text=auto" ;
850
+ case CRLF_AUTO_CRLF :
851
+ return "text=auto eol=crlf" ; /* This is not supported yet */
852
+ case CRLF_AUTO_INPUT :
853
+ return "text=auto eol=lf" ; /* This is not supported yet */
840
854
}
841
855
return "" ;
842
856
}
@@ -1382,12 +1396,13 @@ struct stream_filter *get_stream_filter(const char *path, const unsigned char *s
1382
1396
1383
1397
crlf_action = ca .crlf_action ;
1384
1398
1385
- if ((crlf_action == CRLF_BINARY ) || (crlf_action == CRLF_INPUT ) ||
1386
- (crlf_action == CRLF_GUESS && auto_crlf == AUTO_CRLF_FALSE ))
1399
+ if ((crlf_action == CRLF_BINARY ) ||
1400
+ crlf_action == CRLF_AUTO_INPUT ||
1401
+ (crlf_action == CRLF_TEXT_INPUT ))
1387
1402
filter = cascade_filter (filter , & null_filter_singleton );
1388
1403
1389
1404
else if (output_eol (crlf_action ) == EOL_CRLF &&
1390
- !(crlf_action == CRLF_AUTO || crlf_action == CRLF_GUESS ))
1405
+ !(crlf_action == CRLF_AUTO || crlf_action == CRLF_AUTO_CRLF ))
1391
1406
filter = cascade_filter (filter , lf_to_crlf_filter ());
1392
1407
1393
1408
return filter ;
0 commit comments