convert: add get_stream_filter_ca() variant

Like the previous patch, we will also need to call get_stream_filter() with a precomputed `struct conv_attrs`, when we add support for parallel checkout workers. So add the _ca() variant which takes the conversion attributes struct as a parameter. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff Hostetler committed Dec 16, 2020 at 11:50 UTC 3e9e82c0d897814d77cc755d25acb9df6e8bf48f
2 files changed +19 -11
convert.c
+17 -11
@@ -1942,34 +1942,31 @@ static struct stream_filter *ident_filter(const struct object_id *oid)
1942 }
1943
1944 /*
1945 - * Return an appropriately constructed filter for the path, or NULL if
1945 + * Return an appropriately constructed filter for the given ca, or NULL if
1946 * the contents cannot be filtered without reading the whole thing
1947 * in-core.
1948 *
1949 * Note that you would be crazy to set CRLF, smudge/clean or ident to a
1950 * large binary blob you would want us not to slurp into the memory!
1951 */
1952 -struct stream_filter *get_stream_filter(const struct index_state *istate,
1953 - const char *path,
1954 - const struct object_id *oid)
1952 +struct stream_filter *get_stream_filter_ca(const struct conv_attrs *ca,
1953 + const struct object_id *oid)
1954 {
1956 - struct conv_attrs ca;
1955 struct stream_filter *filter = NULL;
1956
1959 - convert_attrs(istate, &ca, path);
1960 - if (ca.drv && (ca.drv->process || ca.drv->smudge || ca.drv->clean))
1957 + if (ca->drv && (ca->drv->process || ca->drv->smudge || ca->drv->clean))
1958 return NULL;
1959
1963 - if (ca.working_tree_encoding)
1960 + if (ca->working_tree_encoding)
1961 return NULL;
1962
1966 - if (ca.crlf_action == CRLF_AUTO || ca.crlf_action == CRLF_AUTO_CRLF)
1963 + if (ca->crlf_action == CRLF_AUTO || ca->crlf_action == CRLF_AUTO_CRLF)
1964 return NULL;
1965
1969 - if (ca.ident)
1966 + if (ca->ident)
1967 filter = ident_filter(oid);
1968
1972 - if (output_eol(ca.crlf_action) == EOL_CRLF)
1969 + if (output_eol(ca->crlf_action) == EOL_CRLF)
1970 filter = cascade_filter(filter, lf_to_crlf_filter());
1971 else
1972 filter = cascade_filter(filter, &null_filter_singleton);
@@ -1977,6 +1974,15 @@ struct stream_filter *get_stream_filter(const struct index_state *istate,
1974 return filter;
1975 }
1976
1977 +struct stream_filter *get_stream_filter(const struct index_state *istate,
1978 + const char *path,
1979 + const struct object_id *oid)
1980 +{
1981 + struct conv_attrs ca;
1982 + convert_attrs(istate, &ca, path);
1983 + return get_stream_filter_ca(&ca, oid);
1984 +}
1985 +
1986 void free_stream_filter(struct stream_filter *filter)
1987 {
1988 filter->vtbl->free(filter);
convert.h
+2
@@ -179,6 +179,8 @@ struct stream_filter; /* opaque */
179 struct stream_filter *get_stream_filter(const struct index_state *istate,
180 const char *path,
181 const struct object_id *);
182 +struct stream_filter *get_stream_filter_ca(const struct conv_attrs *ca,
183 + const struct object_id *oid);
184 void free_stream_filter(struct stream_filter *);
185 int is_null_stream_filter(struct stream_filter *);
186