convert: make convert_attrs() and convert structs public

Move convert_attrs() declaration from convert.c to convert.h, together with the conv_attrs struct and the crlf_action enum. This function and the data structures will be used outside convert.c in the upcoming parallel checkout implementation. Note that crlf_action is renamed to convert_crlf_action, which is more appropriate for the global namespace. 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 38e95844e8f9bfefb34443650e99f740581a394b
2 files changed +32 -27
convert.c
+8 -27
@@ -24,17 +24,6 @@
24 #define CONVERT_STAT_BITS_TXT_CRLF 0x2
25 #define CONVERT_STAT_BITS_BIN 0x4
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 -
27 struct text_stat {
28 /* NUL, CR, LF and CRLF counts */
29 unsigned nul, lonecr, lonelf, crlf;
@@ -172,7 +161,7 @@ static int text_eol_is_crlf(void)
161 return 0;
162 }
163
175 -static enum eol output_eol(enum crlf_action crlf_action)
164 +static enum eol output_eol(enum convert_crlf_action crlf_action)
165 {
166 switch (crlf_action) {
167 case CRLF_BINARY:
@@ -246,7 +235,7 @@ static int has_crlf_in_index(const struct index_state *istate, const char *path)
235 }
236
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)
239 {
240 if (output_eol(crlf_action) != EOL_CRLF)
241 return 0;
@@ -499,7 +488,7 @@ static int encode_to_worktree(const char *path, const char *src, size_t src_len,
488 static int crlf_to_git(const struct index_state *istate,
489 const char *path, const char *src, size_t len,
490 struct strbuf *buf,
502 - enum crlf_action crlf_action, int conv_flags)
491 + enum convert_crlf_action crlf_action, int conv_flags)
492 {
493 struct text_stat stats;
494 char *dst;
@@ -585,8 +574,8 @@ static int crlf_to_git(const struct index_state *istate,
574 return 1;
575 }
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)
579 {
580 char *to_free = NULL;
581 struct text_stat stats;
@@ -1247,7 +1236,7 @@ static const char *git_path_check_encoding(struct attr_check_item *check)
1236 return value;
1237 }
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)
1240 {
1241 const char *value = check->value;
1242
@@ -1297,18 +1286,10 @@ static int git_path_check_ident(struct attr_check_item *check)
1286 return !!ATTR_TRUE(value);
1287 }
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 -
1289 static struct attr_check *check;
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)
1293 {
1294 struct attr_check_item *ccheck = NULL;
1295
convert.h
+24
@@ -63,6 +63,30 @@ struct checkout_metadata {
63 struct object_id blob;
64 };
65
66 +enum convert_crlf_action {
67 + CRLF_UNDEFINED,
68 + CRLF_BINARY,
69 + CRLF_TEXT,
70 + CRLF_TEXT_INPUT,
71 + CRLF_TEXT_CRLF,
72 + CRLF_AUTO,
73 + CRLF_AUTO_INPUT,
74 + CRLF_AUTO_CRLF
75 +};
76 +
77 +struct convert_driver;
78 +
79 +struct conv_attrs {
80 + struct convert_driver *drv;
81 + enum convert_crlf_action attr_action; /* What attr says */
82 + enum convert_crlf_action crlf_action; /* When no attr is set, use core.autocrlf */
83 + int ident;
84 + const char *working_tree_encoding; /* Supported encoding or default encoding if NULL */
85 +};
86 +
87 +void convert_attrs(const struct index_state *istate,
88 + struct conv_attrs *ca, const char *path);
89 +
90 extern enum eol core_eol;
91 extern char *check_roundtrip_encoding;
92 const char *get_cached_convert_stats_ascii(const struct index_state *istate,