Skip to content

Commit

Permalink
convert: make convert_attrs() and convert structs public
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jeffhostetler authored and gitster committed Mar 18, 2021
1 parent a5828ae commit 38e9584
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 27 deletions.
35 changes: 8 additions & 27 deletions convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,6 @@
#define CONVERT_STAT_BITS_TXT_CRLF 0x2
#define CONVERT_STAT_BITS_BIN 0x4

enum crlf_action {
CRLF_UNDEFINED,
CRLF_BINARY,
CRLF_TEXT,
CRLF_TEXT_INPUT,
CRLF_TEXT_CRLF,
CRLF_AUTO,
CRLF_AUTO_INPUT,
CRLF_AUTO_CRLF
};

struct text_stat {
/* NUL, CR, LF and CRLF counts */
unsigned nul, lonecr, lonelf, crlf;
Expand Down Expand Up @@ -172,7 +161,7 @@ static int text_eol_is_crlf(void)
return 0;
}

static enum eol output_eol(enum crlf_action crlf_action)
static enum eol output_eol(enum convert_crlf_action crlf_action)
{
switch (crlf_action) {
case CRLF_BINARY:
Expand Down Expand Up @@ -246,7 +235,7 @@ static int has_crlf_in_index(const struct index_state *istate, const char *path)
}

static int will_convert_lf_to_crlf(struct text_stat *stats,
enum crlf_action crlf_action)
enum convert_crlf_action crlf_action)
{
if (output_eol(crlf_action) != EOL_CRLF)
return 0;
Expand Down Expand Up @@ -499,7 +488,7 @@ static int encode_to_worktree(const char *path, const char *src, size_t src_len,
static int crlf_to_git(const struct index_state *istate,
const char *path, const char *src, size_t len,
struct strbuf *buf,
enum crlf_action crlf_action, int conv_flags)
enum convert_crlf_action crlf_action, int conv_flags)
{
struct text_stat stats;
char *dst;
Expand Down Expand Up @@ -585,8 +574,8 @@ static int crlf_to_git(const struct index_state *istate,
return 1;
}

static int crlf_to_worktree(const char *src, size_t len,
struct strbuf *buf, enum crlf_action crlf_action)
static int crlf_to_worktree(const char *src, size_t len, struct strbuf *buf,
enum convert_crlf_action crlf_action)
{
char *to_free = NULL;
struct text_stat stats;
Expand Down Expand Up @@ -1247,7 +1236,7 @@ static const char *git_path_check_encoding(struct attr_check_item *check)
return value;
}

static enum crlf_action git_path_check_crlf(struct attr_check_item *check)
static enum convert_crlf_action git_path_check_crlf(struct attr_check_item *check)
{
const char *value = check->value;

Expand Down Expand Up @@ -1297,18 +1286,10 @@ static int git_path_check_ident(struct attr_check_item *check)
return !!ATTR_TRUE(value);
}

struct conv_attrs {
struct convert_driver *drv;
enum crlf_action attr_action; /* What attr says */
enum crlf_action crlf_action; /* When no attr is set, use core.autocrlf */
int ident;
const char *working_tree_encoding; /* Supported encoding or default encoding if NULL */
};

static struct attr_check *check;

static void convert_attrs(const struct index_state *istate,
struct conv_attrs *ca, const char *path)
void convert_attrs(const struct index_state *istate,
struct conv_attrs *ca, const char *path)
{
struct attr_check_item *ccheck = NULL;

Expand Down
24 changes: 24 additions & 0 deletions convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@ struct checkout_metadata {
struct object_id blob;
};

enum convert_crlf_action {
CRLF_UNDEFINED,
CRLF_BINARY,
CRLF_TEXT,
CRLF_TEXT_INPUT,
CRLF_TEXT_CRLF,
CRLF_AUTO,
CRLF_AUTO_INPUT,
CRLF_AUTO_CRLF
};

struct convert_driver;

struct conv_attrs {
struct convert_driver *drv;
enum convert_crlf_action attr_action; /* What attr says */
enum convert_crlf_action crlf_action; /* When no attr is set, use core.autocrlf */
int ident;
const char *working_tree_encoding; /* Supported encoding or default encoding if NULL */
};

void convert_attrs(const struct index_state *istate,
struct conv_attrs *ca, const char *path);

extern enum eol core_eol;
extern char *check_roundtrip_encoding;
const char *get_cached_convert_stats_ascii(const struct index_state *istate,
Expand Down

0 comments on commit 38e9584

Please sign in to comment.