24
24
#define CONVERT_STAT_BITS_TXT_CRLF 0x2
25
25
#define CONVERT_STAT_BITS_BIN 0x4
26
26
27
- enum crlf_action {
28
- CRLF_UNDEFINED ,
29
- CRLF_BINARY ,
30
- CRLF_TEXT ,
31
- CRLF_TEXT_INPUT ,
32
- CRLF_TEXT_CRLF ,
33
- CRLF_AUTO ,
34
- CRLF_AUTO_INPUT ,
35
- CRLF_AUTO_CRLF
36
- };
37
-
38
27
struct text_stat {
39
28
/* NUL, CR, LF and CRLF counts */
40
29
unsigned nul , lonecr , lonelf , crlf ;
@@ -172,7 +161,7 @@ static int text_eol_is_crlf(void)
172
161
return 0 ;
173
162
}
174
163
175
- static enum eol output_eol (enum crlf_action crlf_action )
164
+ static enum eol output_eol (enum convert_crlf_action crlf_action )
176
165
{
177
166
switch (crlf_action ) {
178
167
case CRLF_BINARY :
@@ -246,7 +235,7 @@ static int has_crlf_in_index(const struct index_state *istate, const char *path)
246
235
}
247
236
248
237
static int will_convert_lf_to_crlf (struct text_stat * stats ,
249
- enum crlf_action crlf_action )
238
+ enum convert_crlf_action crlf_action )
250
239
{
251
240
if (output_eol (crlf_action ) != EOL_CRLF )
252
241
return 0 ;
@@ -499,7 +488,7 @@ static int encode_to_worktree(const char *path, const char *src, size_t src_len,
499
488
static int crlf_to_git (const struct index_state * istate ,
500
489
const char * path , const char * src , size_t len ,
501
490
struct strbuf * buf ,
502
- enum crlf_action crlf_action , int conv_flags )
491
+ enum convert_crlf_action crlf_action , int conv_flags )
503
492
{
504
493
struct text_stat stats ;
505
494
char * dst ;
@@ -585,8 +574,8 @@ static int crlf_to_git(const struct index_state *istate,
585
574
return 1 ;
586
575
}
587
576
588
- static int crlf_to_worktree (const char * src , size_t len ,
589
- struct strbuf * buf , enum crlf_action crlf_action )
577
+ static int crlf_to_worktree (const char * src , size_t len , struct strbuf * buf ,
578
+ enum convert_crlf_action crlf_action )
590
579
{
591
580
char * to_free = NULL ;
592
581
struct text_stat stats ;
@@ -1247,7 +1236,7 @@ static const char *git_path_check_encoding(struct attr_check_item *check)
1247
1236
return value ;
1248
1237
}
1249
1238
1250
- static enum crlf_action git_path_check_crlf (struct attr_check_item * check )
1239
+ static enum convert_crlf_action git_path_check_crlf (struct attr_check_item * check )
1251
1240
{
1252
1241
const char * value = check -> value ;
1253
1242
@@ -1297,18 +1286,10 @@ static int git_path_check_ident(struct attr_check_item *check)
1297
1286
return !!ATTR_TRUE (value );
1298
1287
}
1299
1288
1300
- struct conv_attrs {
1301
- struct convert_driver * drv ;
1302
- enum crlf_action attr_action ; /* What attr says */
1303
- enum crlf_action crlf_action ; /* When no attr is set, use core.autocrlf */
1304
- int ident ;
1305
- const char * working_tree_encoding ; /* Supported encoding or default encoding if NULL */
1306
- };
1307
-
1308
1289
static struct attr_check * check ;
1309
1290
1310
- static void convert_attrs (const struct index_state * istate ,
1311
- struct conv_attrs * ca , const char * path )
1291
+ void convert_attrs (const struct index_state * istate ,
1292
+ struct conv_attrs * ca , const char * path )
1312
1293
{
1313
1294
struct attr_check_item * ccheck = NULL ;
1314
1295
@@ -1465,19 +1446,16 @@ void convert_to_git_filter_fd(const struct index_state *istate,
1465
1446
ident_to_git (dst -> buf , dst -> len , dst , ca .ident );
1466
1447
}
1467
1448
1468
- static int convert_to_working_tree_internal (const struct index_state * istate ,
1469
- const char * path , const char * src ,
1470
- size_t len , struct strbuf * dst ,
1471
- int normalizing ,
1472
- const struct checkout_metadata * meta ,
1473
- struct delayed_checkout * dco )
1449
+ static int convert_to_working_tree_ca_internal (const struct conv_attrs * ca ,
1450
+ const char * path , const char * src ,
1451
+ size_t len , struct strbuf * dst ,
1452
+ int normalizing ,
1453
+ const struct checkout_metadata * meta ,
1454
+ struct delayed_checkout * dco )
1474
1455
{
1475
1456
int ret = 0 , ret_filter = 0 ;
1476
- struct conv_attrs ca ;
1477
-
1478
- convert_attrs (istate , & ca , path );
1479
1457
1480
- ret |= ident_to_worktree (src , len , dst , ca . ident );
1458
+ ret |= ident_to_worktree (src , len , dst , ca -> ident );
1481
1459
if (ret ) {
1482
1460
src = dst -> buf ;
1483
1461
len = dst -> len ;
@@ -1487,49 +1465,56 @@ static int convert_to_working_tree_internal(const struct index_state *istate,
1487
1465
* is a smudge or process filter (even if the process filter doesn't
1488
1466
* support smudge). The filters might expect CRLFs.
1489
1467
*/
1490
- if ((ca . drv && (ca . drv -> smudge || ca . drv -> process )) || !normalizing ) {
1491
- ret |= crlf_to_worktree (src , len , dst , ca . crlf_action );
1468
+ if ((ca -> drv && (ca -> drv -> smudge || ca -> drv -> process )) || !normalizing ) {
1469
+ ret |= crlf_to_worktree (src , len , dst , ca -> crlf_action );
1492
1470
if (ret ) {
1493
1471
src = dst -> buf ;
1494
1472
len = dst -> len ;
1495
1473
}
1496
1474
}
1497
1475
1498
- ret |= encode_to_worktree (path , src , len , dst , ca . working_tree_encoding );
1476
+ ret |= encode_to_worktree (path , src , len , dst , ca -> working_tree_encoding );
1499
1477
if (ret ) {
1500
1478
src = dst -> buf ;
1501
1479
len = dst -> len ;
1502
1480
}
1503
1481
1504
1482
ret_filter = apply_filter (
1505
- path , src , len , -1 , dst , ca . drv , CAP_SMUDGE , meta , dco );
1506
- if (!ret_filter && ca . drv && ca . drv -> required )
1507
- die (_ ("%s: smudge filter %s failed" ), path , ca . drv -> name );
1483
+ path , src , len , -1 , dst , ca -> drv , CAP_SMUDGE , meta , dco );
1484
+ if (!ret_filter && ca -> drv && ca -> drv -> required )
1485
+ die (_ ("%s: smudge filter %s failed" ), path , ca -> drv -> name );
1508
1486
1509
1487
return ret | ret_filter ;
1510
1488
}
1511
1489
1512
- int async_convert_to_working_tree (const struct index_state * istate ,
1513
- const char * path , const char * src ,
1514
- size_t len , struct strbuf * dst ,
1515
- const struct checkout_metadata * meta ,
1516
- void * dco )
1490
+ int async_convert_to_working_tree_ca (const struct conv_attrs * ca ,
1491
+ const char * path , const char * src ,
1492
+ size_t len , struct strbuf * dst ,
1493
+ const struct checkout_metadata * meta ,
1494
+ void * dco )
1517
1495
{
1518
- return convert_to_working_tree_internal (istate , path , src , len , dst , 0 , meta , dco );
1496
+ return convert_to_working_tree_ca_internal (ca , path , src , len , dst , 0 ,
1497
+ meta , dco );
1519
1498
}
1520
1499
1521
- int convert_to_working_tree (const struct index_state * istate ,
1522
- const char * path , const char * src ,
1523
- size_t len , struct strbuf * dst ,
1524
- const struct checkout_metadata * meta )
1500
+ int convert_to_working_tree_ca (const struct conv_attrs * ca ,
1501
+ const char * path , const char * src ,
1502
+ size_t len , struct strbuf * dst ,
1503
+ const struct checkout_metadata * meta )
1525
1504
{
1526
- return convert_to_working_tree_internal (istate , path , src , len , dst , 0 , meta , NULL );
1505
+ return convert_to_working_tree_ca_internal (ca , path , src , len , dst , 0 ,
1506
+ meta , NULL );
1527
1507
}
1528
1508
1529
1509
int renormalize_buffer (const struct index_state * istate , const char * path ,
1530
1510
const char * src , size_t len , struct strbuf * dst )
1531
1511
{
1532
- int ret = convert_to_working_tree_internal (istate , path , src , len , dst , 1 , NULL , NULL );
1512
+ struct conv_attrs ca ;
1513
+ int ret ;
1514
+
1515
+ convert_attrs (istate , & ca , path );
1516
+ ret = convert_to_working_tree_ca_internal (& ca , path , src , len , dst , 1 ,
1517
+ NULL , NULL );
1533
1518
if (ret ) {
1534
1519
src = dst -> buf ;
1535
1520
len = dst -> len ;
@@ -1956,41 +1941,41 @@ static struct stream_filter *ident_filter(const struct object_id *oid)
1956
1941
}
1957
1942
1958
1943
/*
1959
- * Return an appropriately constructed filter for the path , or NULL if
1944
+ * Return an appropriately constructed filter for the given ca , or NULL if
1960
1945
* the contents cannot be filtered without reading the whole thing
1961
1946
* in-core.
1962
1947
*
1963
1948
* Note that you would be crazy to set CRLF, smudge/clean or ident to a
1964
1949
* large binary blob you would want us not to slurp into the memory!
1965
1950
*/
1966
- struct stream_filter * get_stream_filter (const struct index_state * istate ,
1967
- const char * path ,
1968
- const struct object_id * oid )
1951
+ struct stream_filter * get_stream_filter_ca (const struct conv_attrs * ca ,
1952
+ const struct object_id * oid )
1969
1953
{
1970
- struct conv_attrs ca ;
1971
1954
struct stream_filter * filter = NULL ;
1972
1955
1973
- convert_attrs (istate , & ca , path );
1974
- if (ca .drv && (ca .drv -> process || ca .drv -> smudge || ca .drv -> clean ))
1975
- return NULL ;
1976
-
1977
- if (ca .working_tree_encoding )
1956
+ if (classify_conv_attrs (ca ) != CA_CLASS_STREAMABLE )
1978
1957
return NULL ;
1979
1958
1980
- if (ca .crlf_action == CRLF_AUTO || ca .crlf_action == CRLF_AUTO_CRLF )
1981
- return NULL ;
1982
-
1983
- if (ca .ident )
1959
+ if (ca -> ident )
1984
1960
filter = ident_filter (oid );
1985
1961
1986
- if (output_eol (ca . crlf_action ) == EOL_CRLF )
1962
+ if (output_eol (ca -> crlf_action ) == EOL_CRLF )
1987
1963
filter = cascade_filter (filter , lf_to_crlf_filter ());
1988
1964
else
1989
1965
filter = cascade_filter (filter , & null_filter_singleton );
1990
1966
1991
1967
return filter ;
1992
1968
}
1993
1969
1970
+ struct stream_filter * get_stream_filter (const struct index_state * istate ,
1971
+ const char * path ,
1972
+ const struct object_id * oid )
1973
+ {
1974
+ struct conv_attrs ca ;
1975
+ convert_attrs (istate , & ca , path );
1976
+ return get_stream_filter_ca (& ca , oid );
1977
+ }
1978
+
1994
1979
void free_stream_filter (struct stream_filter * filter )
1995
1980
{
1996
1981
filter -> vtbl -> free (filter );
@@ -2024,3 +2009,21 @@ void clone_checkout_metadata(struct checkout_metadata *dst,
2024
2009
if (blob )
2025
2010
oidcpy (& dst -> blob , blob );
2026
2011
}
2012
+
2013
+ enum conv_attrs_classification classify_conv_attrs (const struct conv_attrs * ca )
2014
+ {
2015
+ if (ca -> drv ) {
2016
+ if (ca -> drv -> process )
2017
+ return CA_CLASS_INCORE_PROCESS ;
2018
+ if (ca -> drv -> smudge || ca -> drv -> clean )
2019
+ return CA_CLASS_INCORE_FILTER ;
2020
+ }
2021
+
2022
+ if (ca -> working_tree_encoding )
2023
+ return CA_CLASS_INCORE ;
2024
+
2025
+ if (ca -> crlf_action == CRLF_AUTO || ca -> crlf_action == CRLF_AUTO_CRLF )
2026
+ return CA_CLASS_INCORE ;
2027
+
2028
+ return CA_CLASS_STREAMABLE ;
2029
+ }
0 commit comments