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>
This commit is contained in:

committed by
Junio C Hamano

parent
a5828ae6b5
commit
38e95844e8
35
convert.c
35
convert.c
@ -24,17 +24,6 @@
|
|||||||
#define CONVERT_STAT_BITS_TXT_CRLF 0x2
|
#define CONVERT_STAT_BITS_TXT_CRLF 0x2
|
||||||
#define CONVERT_STAT_BITS_BIN 0x4
|
#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 {
|
struct text_stat {
|
||||||
/* NUL, CR, LF and CRLF counts */
|
/* NUL, CR, LF and CRLF counts */
|
||||||
unsigned nul, lonecr, lonelf, crlf;
|
unsigned nul, lonecr, lonelf, crlf;
|
||||||
@ -172,7 +161,7 @@ static int text_eol_is_crlf(void)
|
|||||||
return 0;
|
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) {
|
switch (crlf_action) {
|
||||||
case CRLF_BINARY:
|
case CRLF_BINARY:
|
||||||
@ -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,
|
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)
|
if (output_eol(crlf_action) != EOL_CRLF)
|
||||||
return 0;
|
return 0;
|
||||||
@ -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,
|
static int crlf_to_git(const struct index_state *istate,
|
||||||
const char *path, const char *src, size_t len,
|
const char *path, const char *src, size_t len,
|
||||||
struct strbuf *buf,
|
struct strbuf *buf,
|
||||||
enum crlf_action crlf_action, int conv_flags)
|
enum convert_crlf_action crlf_action, int conv_flags)
|
||||||
{
|
{
|
||||||
struct text_stat stats;
|
struct text_stat stats;
|
||||||
char *dst;
|
char *dst;
|
||||||
@ -585,8 +574,8 @@ static int crlf_to_git(const struct index_state *istate,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int crlf_to_worktree(const char *src, size_t len,
|
static int crlf_to_worktree(const char *src, size_t len, struct strbuf *buf,
|
||||||
struct strbuf *buf, enum crlf_action crlf_action)
|
enum convert_crlf_action crlf_action)
|
||||||
{
|
{
|
||||||
char *to_free = NULL;
|
char *to_free = NULL;
|
||||||
struct text_stat stats;
|
struct text_stat stats;
|
||||||
@ -1247,7 +1236,7 @@ static const char *git_path_check_encoding(struct attr_check_item *check)
|
|||||||
return value;
|
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;
|
const char *value = check->value;
|
||||||
|
|
||||||
@ -1297,18 +1286,10 @@ static int git_path_check_ident(struct attr_check_item *check)
|
|||||||
return !!ATTR_TRUE(value);
|
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 struct attr_check *check;
|
||||||
|
|
||||||
static void convert_attrs(const struct index_state *istate,
|
void convert_attrs(const struct index_state *istate,
|
||||||
struct conv_attrs *ca, const char *path)
|
struct conv_attrs *ca, const char *path)
|
||||||
{
|
{
|
||||||
struct attr_check_item *ccheck = NULL;
|
struct attr_check_item *ccheck = NULL;
|
||||||
|
|
||||||
|
24
convert.h
24
convert.h
@ -63,6 +63,30 @@ struct checkout_metadata {
|
|||||||
struct object_id blob;
|
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 enum eol core_eol;
|
||||||
extern char *check_roundtrip_encoding;
|
extern char *check_roundtrip_encoding;
|
||||||
const char *get_cached_convert_stats_ascii(const struct index_state *istate,
|
const char *get_cached_convert_stats_ascii(const struct index_state *istate,
|
||||||
|
Reference in New Issue
Block a user