2424#define CONVERT_STAT_BITS_TXT_CRLF 0x2
2525#define CONVERT_STAT_BITS_BIN 0x4
2626
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-
3827struct text_stat {
3928 /* NUL, CR, LF and CRLF counts */
4029 unsigned nul , lonecr , lonelf , crlf ;
@@ -172,7 +161,7 @@ static int text_eol_is_crlf(void)
172161 return 0 ;
173162}
174163
175- static enum eol output_eol (enum crlf_action crlf_action )
164+ static enum eol output_eol (enum convert_crlf_action crlf_action )
176165{
177166 switch (crlf_action ) {
178167 case CRLF_BINARY :
@@ -246,7 +235,7 @@ static int has_crlf_in_index(const struct index_state *istate, const char *path)
246235}
247236
248237static int will_convert_lf_to_crlf (struct text_stat * stats ,
249- enum crlf_action crlf_action )
238+ enum convert_crlf_action crlf_action )
250239{
251240 if (output_eol (crlf_action ) != EOL_CRLF )
252241 return 0 ;
@@ -499,7 +488,7 @@ static int encode_to_worktree(const char *path, const char *src, size_t src_len,
499488static int crlf_to_git (const struct index_state * istate ,
500489 const char * path , const char * src , size_t len ,
501490 struct strbuf * buf ,
502- enum crlf_action crlf_action , int conv_flags )
491+ enum convert_crlf_action crlf_action , int conv_flags )
503492{
504493 struct text_stat stats ;
505494 char * dst ;
@@ -585,8 +574,8 @@ static int crlf_to_git(const struct index_state *istate,
585574 return 1 ;
586575}
587576
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 )
590579{
591580 char * to_free = NULL ;
592581 struct text_stat stats ;
@@ -1247,7 +1236,7 @@ static const char *git_path_check_encoding(struct attr_check_item *check)
12471236 return value ;
12481237}
12491238
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 )
12511240{
12521241 const char * value = check -> value ;
12531242
@@ -1297,18 +1286,10 @@ static int git_path_check_ident(struct attr_check_item *check)
12971286 return !!ATTR_TRUE (value );
12981287}
12991288
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-
13081289static struct attr_check * check ;
13091290
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 )
13121293{
13131294 struct attr_check_item * ccheck = NULL ;
13141295
@@ -1465,19 +1446,16 @@ void convert_to_git_filter_fd(const struct index_state *istate,
14651446 ident_to_git (dst -> buf , dst -> len , dst , ca .ident );
14661447}
14671448
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 )
14741455{
14751456 int ret = 0 , ret_filter = 0 ;
1476- struct conv_attrs ca ;
1477-
1478- convert_attrs (istate , & ca , path );
14791457
1480- ret |= ident_to_worktree (src , len , dst , ca . ident );
1458+ ret |= ident_to_worktree (src , len , dst , ca -> ident );
14811459 if (ret ) {
14821460 src = dst -> buf ;
14831461 len = dst -> len ;
@@ -1487,49 +1465,56 @@ static int convert_to_working_tree_internal(const struct index_state *istate,
14871465 * is a smudge or process filter (even if the process filter doesn't
14881466 * support smudge). The filters might expect CRLFs.
14891467 */
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 );
14921470 if (ret ) {
14931471 src = dst -> buf ;
14941472 len = dst -> len ;
14951473 }
14961474 }
14971475
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 );
14991477 if (ret ) {
15001478 src = dst -> buf ;
15011479 len = dst -> len ;
15021480 }
15031481
15041482 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 );
15081486
15091487 return ret | ret_filter ;
15101488}
15111489
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 )
15171495{
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 );
15191498}
15201499
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 )
15251504{
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 );
15271507}
15281508
15291509int renormalize_buffer (const struct index_state * istate , const char * path ,
15301510 const char * src , size_t len , struct strbuf * dst )
15311511{
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 );
15331518 if (ret ) {
15341519 src = dst -> buf ;
15351520 len = dst -> len ;
@@ -1956,41 +1941,41 @@ static struct stream_filter *ident_filter(const struct object_id *oid)
19561941}
19571942
19581943/*
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
19601945 * the contents cannot be filtered without reading the whole thing
19611946 * in-core.
19621947 *
19631948 * Note that you would be crazy to set CRLF, smudge/clean or ident to a
19641949 * large binary blob you would want us not to slurp into the memory!
19651950 */
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 )
19691953{
1970- struct conv_attrs ca ;
19711954 struct stream_filter * filter = NULL ;
19721955
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 )
19781957 return NULL ;
19791958
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 )
19841960 filter = ident_filter (oid );
19851961
1986- if (output_eol (ca . crlf_action ) == EOL_CRLF )
1962+ if (output_eol (ca -> crlf_action ) == EOL_CRLF )
19871963 filter = cascade_filter (filter , lf_to_crlf_filter ());
19881964 else
19891965 filter = cascade_filter (filter , & null_filter_singleton );
19901966
19911967 return filter ;
19921968}
19931969
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+
19941979void free_stream_filter (struct stream_filter * filter )
19951980{
19961981 filter -> vtbl -> free (filter );
@@ -2024,3 +2009,21 @@ void clone_checkout_metadata(struct checkout_metadata *dst,
20242009 if (blob )
20252010 oidcpy (& dst -> blob , blob );
20262011}
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