convert.c: restructure the attribute checking part.
This separates the checkattr() call and interpretation of the returned value specific to the 'crlf' attribute into separate routines, so that we can run a single call to checkattr() to check for more than one attributes, and then interprete what the returned settings mean separately. Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
e87b1c943a
commit
6073ee8571
30
convert.c
30
convert.c
@ -200,7 +200,7 @@ static char *crlf_to_worktree(const char *path, const char *src, unsigned long *
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static void setup_crlf_check(struct git_attr_check *check)
|
||||
static void setup_convert_check(struct git_attr_check *check)
|
||||
{
|
||||
static struct git_attr *attr_crlf;
|
||||
|
||||
@ -209,14 +209,10 @@ static void setup_crlf_check(struct git_attr_check *check)
|
||||
check->attr = attr_crlf;
|
||||
}
|
||||
|
||||
static int git_path_check_crlf(const char *path)
|
||||
static int git_path_check_crlf(const char *path, struct git_attr_check *check)
|
||||
{
|
||||
struct git_attr_check attr_crlf_check;
|
||||
const char *value = check->value;
|
||||
|
||||
setup_crlf_check(&attr_crlf_check);
|
||||
|
||||
if (!git_checkattr(path, 1, &attr_crlf_check)) {
|
||||
const char *value = attr_crlf_check.value;
|
||||
if (ATTR_TRUE(value))
|
||||
return CRLF_TEXT;
|
||||
else if (ATTR_FALSE(value))
|
||||
@ -225,17 +221,29 @@ static int git_path_check_crlf(const char *path)
|
||||
;
|
||||
else if (!strcmp(value, "input"))
|
||||
return CRLF_INPUT;
|
||||
/* fallthru */
|
||||
}
|
||||
return CRLF_GUESS;
|
||||
}
|
||||
|
||||
char *convert_to_git(const char *path, const char *src, unsigned long *sizep)
|
||||
{
|
||||
return crlf_to_git(path, src, sizep, git_path_check_crlf(path));
|
||||
struct git_attr_check check[1];
|
||||
int crlf = CRLF_GUESS;
|
||||
|
||||
setup_convert_check(check);
|
||||
if (!git_checkattr(path, 1, check)) {
|
||||
crlf = git_path_check_crlf(path, check);
|
||||
}
|
||||
return crlf_to_git(path, src, sizep, crlf);
|
||||
}
|
||||
|
||||
char *convert_to_working_tree(const char *path, const char *src, unsigned long *sizep)
|
||||
{
|
||||
return crlf_to_worktree(path, src, sizep, git_path_check_crlf(path));
|
||||
struct git_attr_check check[1];
|
||||
int crlf = CRLF_GUESS;
|
||||
|
||||
setup_convert_check(check);
|
||||
if (!git_checkattr(path, 1, check)) {
|
||||
crlf = git_path_check_crlf(path, check);
|
||||
}
|
||||
return crlf_to_worktree(path, src, sizep, crlf);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user