Skip to content

Commit 38e9584

Browse files
jeffhostetlergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Matheus Tavares <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a5828ae commit 38e9584

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

convert.c

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,6 @@
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-
3827
struct 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

248237
static 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,
499488
static 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-
13081289
static 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

convert.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,30 @@ struct checkout_metadata {
6363
struct object_id blob;
6464
};
6565

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+
6690
extern enum eol core_eol;
6791
extern char *check_roundtrip_encoding;
6892
const char *get_cached_convert_stats_ascii(const struct index_state *istate,

0 commit comments

Comments
 (0)