From 35ebfd6a0cd71795c4fa510b99e55ad89fb654f1 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 12 Apr 2007 22:30:05 -0700 Subject: Define 'crlf' attribute. This defines the semantics of 'crlf' attribute as an example. When a path has this attribute unset (i.e. '!crlf'), autocrlf line-end conversion is not applied. Eventually we would want to let users to build a pipeline of processing to munge blob data to filesystem format (and in the other direction) based on combination of attributes, and at that point the mechanism in convert_to_{git,working_tree}() that looks at 'crlf' attribute needs to be enhanced. Perhaps the existing 'crlf' would become the first step in the input chain, and the last step in the output chain. Signed-off-by: Junio C Hamano --- convert.c | 49 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 7 deletions(-) (limited to 'convert.c') diff --git a/convert.c b/convert.c index 898bfe3eb2..20c744aa23 100644 --- a/convert.c +++ b/convert.c @@ -1,4 +1,6 @@ #include "cache.h" +#include "attr.h" + /* * convert.c - convert a file when checking it out and checking it in. * @@ -72,17 +74,12 @@ static int is_binary(unsigned long size, struct text_stat *stats) return 0; } -int convert_to_git(const char *path, char **bufp, unsigned long *sizep) +static int autocrlf_to_git(const char *path, char **bufp, unsigned long *sizep) { char *buffer, *nbuf; unsigned long size, nsize; struct text_stat stats; - /* - * FIXME! Other pluggable conversions should go here, - * based on filename patterns. Right now we just do the - * stupid auto-CRLF one. - */ if (!auto_crlf) return 0; @@ -128,7 +125,7 @@ int convert_to_git(const char *path, char **bufp, unsigned long *sizep) return 1; } -int convert_to_working_tree(const char *path, char **bufp, unsigned long *sizep) +static int autocrlf_to_working_tree(const char *path, char **bufp, unsigned long *sizep) { char *buffer, *nbuf; unsigned long size, nsize; @@ -184,3 +181,41 @@ int convert_to_working_tree(const char *path, char **bufp, unsigned long *sizep) return 1; } + +static void setup_crlf_check(struct git_attr_check *check) +{ + static struct git_attr *attr_crlf; + + if (!attr_crlf) + attr_crlf = git_attr("crlf", 4); + check->attr = attr_crlf; +} + +static int git_path_is_binary(const char *path) +{ + struct git_attr_check attr_crlf_check; + + setup_crlf_check(&attr_crlf_check); + + /* + * If crlf is not mentioned, default to autocrlf; + * disable autocrlf only when crlf attribute is explicitly + * unset. + */ + return (!git_checkattr(path, 1, &attr_crlf_check) && + (0 == attr_crlf_check.isset)); +} + +int convert_to_git(const char *path, char **bufp, unsigned long *sizep) +{ + if (git_path_is_binary(path)) + return 0; + return autocrlf_to_git(path, bufp, sizep); +} + +int convert_to_working_tree(const char *path, char **bufp, unsigned long *sizep) +{ + if (git_path_is_binary(path)) + return 0; + return autocrlf_to_working_tree(path, bufp, sizep); +} -- cgit v1.2.1 From 201ac8efc79668353281583629aa15ac7f36e843 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 15 Apr 2007 13:35:45 -0700 Subject: Fix 'crlf' attribute semantics. Earlier we said 'crlf lets the path go through core.autocrlf process while !crlf disables it altogether'. This fixes the semantics to: - Lack of 'crlf' attribute makes core.autocrlf to apply (i.e. we guess based on the contents and if platform expresses its desire to have CRLF line endings via core.autocrlf, we do so). - Setting 'crlf' attribute to true forces CRLF line endings in working tree files, even if blob does not look like text (e.g. contains NUL or other bytes we consider binary). - Setting 'crlf' attribute to false disables conversion. Signed-off-by: Junio C Hamano --- convert.c | 122 +++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 78 insertions(+), 44 deletions(-) (limited to 'convert.c') diff --git a/convert.c b/convert.c index 20c744aa23..d0d4b81871 100644 --- a/convert.c +++ b/convert.c @@ -74,13 +74,13 @@ static int is_binary(unsigned long size, struct text_stat *stats) return 0; } -static int autocrlf_to_git(const char *path, char **bufp, unsigned long *sizep) +static int crlf_to_git(const char *path, char **bufp, unsigned long *sizep, int guess) { char *buffer, *nbuf; unsigned long size, nsize; struct text_stat stats; - if (!auto_crlf) + if (guess && !auto_crlf) return 0; size = *sizep; @@ -94,19 +94,21 @@ static int autocrlf_to_git(const char *path, char **bufp, unsigned long *sizep) if (!stats.cr) return 0; - /* - * We're currently not going to even try to convert stuff - * that has bare CR characters. Does anybody do that crazy - * stuff? - */ - if (stats.cr != stats.crlf) - return 0; - - /* - * And add some heuristics for binary vs text, of course... - */ - if (is_binary(size, &stats)) - return 0; + if (guess) { + /* + * We're currently not going to even try to convert stuff + * that has bare CR characters. Does anybody do that crazy + * stuff? + */ + if (stats.cr != stats.crlf) + return 0; + + /* + * And add some heuristics for binary vs text, of course... + */ + if (is_binary(size, &stats)) + return 0; + } /* * Ok, allocate a new buffer, fill it in, and return true @@ -116,28 +118,42 @@ static int autocrlf_to_git(const char *path, char **bufp, unsigned long *sizep) nbuf = xmalloc(nsize); *bufp = nbuf; *sizep = nsize; - do { - unsigned char c = *buffer++; - if (c != '\r') - *nbuf++ = c; - } while (--size); + + if (guess) { + do { + unsigned char c = *buffer++; + if (c != '\r') + *nbuf++ = c; + } while (--size); + } else { + do { + unsigned char c = *buffer++; + if (! (c == '\r' && (1 < size && *buffer == '\n'))) + *nbuf++ = c; + } while (--size); + } return 1; } -static int autocrlf_to_working_tree(const char *path, char **bufp, unsigned long *sizep) +static int autocrlf_to_git(const char *path, char **bufp, unsigned long *sizep) +{ + return crlf_to_git(path, bufp, sizep, 1); +} + +static int forcecrlf_to_git(const char *path, char **bufp, unsigned long *sizep) +{ + return crlf_to_git(path, bufp, sizep, 0); +} + +static int crlf_to_working_tree(const char *path, char **bufp, unsigned long *sizep, int guess) { char *buffer, *nbuf; unsigned long size, nsize; struct text_stat stats; unsigned char last; - /* - * FIXME! Other pluggable conversions should go here, - * based on filename patterns. Right now we just do the - * stupid auto-CRLF one. - */ - if (auto_crlf <= 0) + if (guess && auto_crlf <= 0) return 0; size = *sizep; @@ -155,12 +171,14 @@ static int autocrlf_to_working_tree(const char *path, char **bufp, unsigned long if (stats.lf == stats.crlf) return 0; - /* If we have any bare CR characters, we're not going to touch it */ - if (stats.cr != stats.crlf) - return 0; + if (guess) { + /* If we have any bare CR characters, we're not going to touch it */ + if (stats.cr != stats.crlf) + return 0; - if (is_binary(size, &stats)) - return 0; + if (is_binary(size, &stats)) + return 0; + } /* * Ok, allocate a new buffer, fill it in, and return true @@ -182,6 +200,16 @@ static int autocrlf_to_working_tree(const char *path, char **bufp, unsigned long return 1; } +static int autocrlf_to_working_tree(const char *path, char **bufp, unsigned long *sizep) +{ + return crlf_to_working_tree(path, bufp, sizep, 1); +} + +static int forcecrlf_to_working_tree(const char *path, char **bufp, unsigned long *sizep) +{ + return crlf_to_working_tree(path, bufp, sizep, 0); +} + static void setup_crlf_check(struct git_attr_check *check) { static struct git_attr *attr_crlf; @@ -191,31 +219,37 @@ static void setup_crlf_check(struct git_attr_check *check) check->attr = attr_crlf; } -static int git_path_is_binary(const char *path) +static int git_path_check_crlf(const char *path) { struct git_attr_check attr_crlf_check; setup_crlf_check(&attr_crlf_check); - /* - * If crlf is not mentioned, default to autocrlf; - * disable autocrlf only when crlf attribute is explicitly - * unset. - */ - return (!git_checkattr(path, 1, &attr_crlf_check) && - (0 == attr_crlf_check.isset)); + if (git_checkattr(path, 1, &attr_crlf_check)) + return -1; + return attr_crlf_check.isset; } int convert_to_git(const char *path, char **bufp, unsigned long *sizep) { - if (git_path_is_binary(path)) + switch (git_path_check_crlf(path)) { + case 0: return 0; - return autocrlf_to_git(path, bufp, sizep); + case 1: + return forcecrlf_to_git(path, bufp, sizep); + default: + return autocrlf_to_git(path, bufp, sizep); + } } int convert_to_working_tree(const char *path, char **bufp, unsigned long *sizep) { - if (git_path_is_binary(path)) + switch (git_path_check_crlf(path)) { + case 0: return 0; - return autocrlf_to_working_tree(path, bufp, sizep); + case 1: + return forcecrlf_to_working_tree(path, bufp, sizep); + default: + return autocrlf_to_working_tree(path, bufp, sizep); + } } -- cgit v1.2.1 From 515106fa1335462393c08fa8712dddd767dc147a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 16 Apr 2007 21:33:31 -0700 Subject: Allow more than true/false to attributes. This allows you to define three values (and possibly more) to each attribute: true, false, and unset. Typically the handlers that notice and act on attribute values treat "unset" attribute to mean "do your default thing" (e.g. crlf that is unset would trigger "guess from contents"), so being able to override a setting to an unset state is actually useful. - If you want to set the attribute value to true, have an entry in .gitattributes file that mentions the attribute name; e.g. *.o binary - If you want to set the attribute value explicitly to false, use '-'; e.g. *.a -diff - If you want to make the attribute value _unset_, perhaps to override an earlier entry, use '!'; e.g. *.a -diff c.i.a !diff This also allows string values to attributes, with the natural syntax: attrname=attrvalue but you cannot use it, as nobody takes notice and acts on it yet. Signed-off-by: Junio C Hamano --- convert.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'convert.c') diff --git a/convert.c b/convert.c index d0d4b81871..68bb70f12f 100644 --- a/convert.c +++ b/convert.c @@ -225,9 +225,19 @@ static int git_path_check_crlf(const char *path) setup_crlf_check(&attr_crlf_check); - if (git_checkattr(path, 1, &attr_crlf_check)) - return -1; - return attr_crlf_check.isset; + if (!git_checkattr(path, 1, &attr_crlf_check)) { + void *value = attr_crlf_check.value; + if (ATTR_TRUE(value)) + return 1; + else if (ATTR_FALSE(value)) + return 0; + else if (ATTR_UNSET(value)) + ; + else + die("unknown value %s given to 'crlf' attribute", + (char *)value); + } + return -1; } int convert_to_git(const char *path, char **bufp, unsigned long *sizep) -- cgit v1.2.1 From a5e92abde61d59a8612c5b87d0bae681e90f7fdb Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 18 Apr 2007 16:16:37 -0700 Subject: Fix funny types used in attribute value representation It was bothering me a lot that I abused small integer values casted to (void *) to represent non string values in gitattributes. This corrects it by making the type of attribute values (const char *), and using the address of a few statically allocated character buffer to denote true/false. Unset attributes are represented as having NULLs as their values. Added in-header documentation to explain how git_checkattr() routine should be called. Signed-off-by: Junio C Hamano --- convert.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'convert.c') diff --git a/convert.c b/convert.c index 68bb70f12f..a5f60c7c6b 100644 --- a/convert.c +++ b/convert.c @@ -226,7 +226,7 @@ static int git_path_check_crlf(const char *path) setup_crlf_check(&attr_crlf_check); if (!git_checkattr(path, 1, &attr_crlf_check)) { - void *value = attr_crlf_check.value; + const char *value = attr_crlf_check.value; if (ATTR_TRUE(value)) return 1; else if (ATTR_FALSE(value)) -- cgit v1.2.1 From 163b95919428cd7d782af91296e0b886683f2daa Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 19 Apr 2007 22:37:19 -0700 Subject: Update 'crlf' attribute semantics. This updates the semantics of 'crlf' so that .gitattributes file can say "this is text, even though it may look funny". Setting the `crlf` attribute on a path is meant to mark the path as a "text" file. 'core.autocrlf' conversion takes place without guessing the content type by inspection. Unsetting the `crlf` attribute on a path is meant to mark the path as a "binary" file. The path never goes through line endings conversion upon checkin/checkout. Unspecified `crlf` attribute tells git to apply the `core.autocrlf` conversion when the file content looks like text. Setting the `crlf` attribut to string value "input" is similar to setting the attribute to `true`, but also forces git to act as if `core.autocrlf` is set to `input` for the path. Signed-off-by: Junio C Hamano --- convert.c | 75 ++++++++++++++++++++++----------------------------------------- 1 file changed, 26 insertions(+), 49 deletions(-) (limited to 'convert.c') diff --git a/convert.c b/convert.c index a5f60c7c6b..da64253a16 100644 --- a/convert.c +++ b/convert.c @@ -10,6 +10,11 @@ * translation when the "auto_crlf" option is set. */ +#define CRLF_GUESS (-1) +#define CRLF_BINARY 0 +#define CRLF_TEXT 1 +#define CRLF_INPUT 2 + struct text_stat { /* CR, LF and CRLF counts */ unsigned cr, lf, crlf; @@ -74,13 +79,13 @@ static int is_binary(unsigned long size, struct text_stat *stats) return 0; } -static int crlf_to_git(const char *path, char **bufp, unsigned long *sizep, int guess) +static int crlf_to_git(const char *path, char **bufp, unsigned long *sizep, int action) { char *buffer, *nbuf; unsigned long size, nsize; struct text_stat stats; - if (guess && !auto_crlf) + if ((action == CRLF_BINARY) || (action == CRLF_GUESS && !auto_crlf)) return 0; size = *sizep; @@ -94,7 +99,7 @@ static int crlf_to_git(const char *path, char **bufp, unsigned long *sizep, int if (!stats.cr) return 0; - if (guess) { + if (action == CRLF_GUESS) { /* * We're currently not going to even try to convert stuff * that has bare CR characters. Does anybody do that crazy @@ -119,7 +124,12 @@ static int crlf_to_git(const char *path, char **bufp, unsigned long *sizep, int *bufp = nbuf; *sizep = nsize; - if (guess) { + if (action == CRLF_GUESS) { + /* + * If we guessed, we already know we rejected a file with + * lone CR, and we can strip a CR without looking at what + * follow it. + */ do { unsigned char c = *buffer++; if (c != '\r') @@ -136,24 +146,15 @@ static int crlf_to_git(const char *path, char **bufp, unsigned long *sizep, int return 1; } -static int autocrlf_to_git(const char *path, char **bufp, unsigned long *sizep) -{ - return crlf_to_git(path, bufp, sizep, 1); -} - -static int forcecrlf_to_git(const char *path, char **bufp, unsigned long *sizep) -{ - return crlf_to_git(path, bufp, sizep, 0); -} - -static int crlf_to_working_tree(const char *path, char **bufp, unsigned long *sizep, int guess) +static int crlf_to_worktree(const char *path, char **bufp, unsigned long *sizep, int action) { char *buffer, *nbuf; unsigned long size, nsize; struct text_stat stats; unsigned char last; - if (guess && auto_crlf <= 0) + if ((action == CRLF_BINARY) || (action == CRLF_INPUT) || + (action == CRLF_GUESS && auto_crlf <= 0)) return 0; size = *sizep; @@ -171,7 +172,7 @@ static int crlf_to_working_tree(const char *path, char **bufp, unsigned long *si if (stats.lf == stats.crlf) return 0; - if (guess) { + if (action == CRLF_GUESS) { /* If we have any bare CR characters, we're not going to touch it */ if (stats.cr != stats.crlf) return 0; @@ -200,16 +201,6 @@ static int crlf_to_working_tree(const char *path, char **bufp, unsigned long *si return 1; } -static int autocrlf_to_working_tree(const char *path, char **bufp, unsigned long *sizep) -{ - return crlf_to_working_tree(path, bufp, sizep, 1); -} - -static int forcecrlf_to_working_tree(const char *path, char **bufp, unsigned long *sizep) -{ - return crlf_to_working_tree(path, bufp, sizep, 0); -} - static void setup_crlf_check(struct git_attr_check *check) { static struct git_attr *attr_crlf; @@ -228,38 +219,24 @@ static int git_path_check_crlf(const char *path) if (!git_checkattr(path, 1, &attr_crlf_check)) { const char *value = attr_crlf_check.value; if (ATTR_TRUE(value)) - return 1; + return CRLF_TEXT; else if (ATTR_FALSE(value)) - return 0; + return CRLF_BINARY; else if (ATTR_UNSET(value)) ; - else - die("unknown value %s given to 'crlf' attribute", - (char *)value); + else if (!strcmp(value, "input")) + return CRLF_INPUT; + /* fallthru */ } - return -1; + return CRLF_GUESS; } int convert_to_git(const char *path, char **bufp, unsigned long *sizep) { - switch (git_path_check_crlf(path)) { - case 0: - return 0; - case 1: - return forcecrlf_to_git(path, bufp, sizep); - default: - return autocrlf_to_git(path, bufp, sizep); - } + return crlf_to_git(path, bufp, sizep, git_path_check_crlf(path)); } int convert_to_working_tree(const char *path, char **bufp, unsigned long *sizep) { - switch (git_path_check_crlf(path)) { - case 0: - return 0; - case 1: - return forcecrlf_to_working_tree(path, bufp, sizep); - default: - return autocrlf_to_working_tree(path, bufp, sizep); - } + return crlf_to_worktree(path, bufp, sizep, git_path_check_crlf(path)); } -- cgit v1.2.1 From ac78e548049f4e86b38368d2c4b4dbb546c64ac6 Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Thu, 19 Apr 2007 02:05:03 +0200 Subject: Simplify calling of CR/LF conversion routines Signed-off-by: Alex Riesen Signed-off-by: Junio C Hamano --- convert.c | 71 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 35 insertions(+), 36 deletions(-) (limited to 'convert.c') diff --git a/convert.c b/convert.c index da64253a16..742b895cfa 100644 --- a/convert.c +++ b/convert.c @@ -79,25 +79,24 @@ static int is_binary(unsigned long size, struct text_stat *stats) return 0; } -static int crlf_to_git(const char *path, char **bufp, unsigned long *sizep, int action) +static char *crlf_to_git(const char *path, const char *src, unsigned long *sizep, int action) { - char *buffer, *nbuf; + char *buffer, *dst; unsigned long size, nsize; struct text_stat stats; if ((action == CRLF_BINARY) || (action == CRLF_GUESS && !auto_crlf)) - return 0; + return NULL; size = *sizep; if (!size) - return 0; - buffer = *bufp; + return NULL; - gather_stats(buffer, size, &stats); + gather_stats(src, size, &stats); /* No CR? Nothing to convert, regardless. */ if (!stats.cr) - return 0; + return NULL; if (action == CRLF_GUESS) { /* @@ -106,13 +105,13 @@ static int crlf_to_git(const char *path, char **bufp, unsigned long *sizep, int * stuff? */ if (stats.cr != stats.crlf) - return 0; + return NULL; /* * And add some heuristics for binary vs text, of course... */ if (is_binary(size, &stats)) - return 0; + return NULL; } /* @@ -120,10 +119,10 @@ static int crlf_to_git(const char *path, char **bufp, unsigned long *sizep, int * to let the caller know that we switched buffers on it. */ nsize = size - stats.crlf; - nbuf = xmalloc(nsize); - *bufp = nbuf; + buffer = xmalloc(nsize); *sizep = nsize; + dst = buffer; if (action == CRLF_GUESS) { /* * If we guessed, we already know we rejected a file with @@ -131,54 +130,53 @@ static int crlf_to_git(const char *path, char **bufp, unsigned long *sizep, int * follow it. */ do { - unsigned char c = *buffer++; + unsigned char c = *src++; if (c != '\r') - *nbuf++ = c; + *dst++ = c; } while (--size); } else { do { - unsigned char c = *buffer++; + unsigned char c = *src++; if (! (c == '\r' && (1 < size && *buffer == '\n'))) - *nbuf++ = c; + *dst++ = c; } while (--size); } - return 1; + return buffer; } -static int crlf_to_worktree(const char *path, char **bufp, unsigned long *sizep, int action) +static char *crlf_to_worktree(const char *path, const char *src, unsigned long *sizep, int action) { - char *buffer, *nbuf; + char *buffer, *dst; unsigned long size, nsize; struct text_stat stats; unsigned char last; if ((action == CRLF_BINARY) || (action == CRLF_INPUT) || (action == CRLF_GUESS && auto_crlf <= 0)) - return 0; + return NULL; size = *sizep; if (!size) - return 0; - buffer = *bufp; + return NULL; - gather_stats(buffer, size, &stats); + gather_stats(src, size, &stats); /* No LF? Nothing to convert, regardless. */ if (!stats.lf) - return 0; + return NULL; /* Was it already in CRLF format? */ if (stats.lf == stats.crlf) - return 0; + return NULL; if (action == CRLF_GUESS) { /* If we have any bare CR characters, we're not going to touch it */ if (stats.cr != stats.crlf) - return 0; + return NULL; if (is_binary(size, &stats)) - return 0; + return NULL; } /* @@ -186,19 +184,20 @@ static int crlf_to_worktree(const char *path, char **bufp, unsigned long *sizep, * to let the caller know that we switched buffers on it. */ nsize = size + stats.lf - stats.crlf; - nbuf = xmalloc(nsize); - *bufp = nbuf; + buffer = xmalloc(nsize); *sizep = nsize; last = 0; + + dst = buffer; do { - unsigned char c = *buffer++; + unsigned char c = *src++; if (c == '\n' && last != '\r') - *nbuf++ = '\r'; - *nbuf++ = c; + *dst++ = '\r'; + *dst++ = c; last = c; } while (--size); - return 1; + return buffer; } static void setup_crlf_check(struct git_attr_check *check) @@ -231,12 +230,12 @@ static int git_path_check_crlf(const char *path) return CRLF_GUESS; } -int convert_to_git(const char *path, char **bufp, unsigned long *sizep) +char *convert_to_git(const char *path, const char *src, unsigned long *sizep) { - return crlf_to_git(path, bufp, sizep, git_path_check_crlf(path)); + return crlf_to_git(path, src, sizep, git_path_check_crlf(path)); } -int convert_to_working_tree(const char *path, char **bufp, unsigned long *sizep) +char *convert_to_working_tree(const char *path, const char *src, unsigned long *sizep) { - return crlf_to_worktree(path, bufp, sizep, git_path_check_crlf(path)); + return crlf_to_worktree(path, src, sizep, git_path_check_crlf(path)); } -- cgit v1.2.1 From 6073ee85719be6d959e74aa667024fcbec44a588 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 20 Apr 2007 23:44:02 -0700 Subject: 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 --- convert.c | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) (limited to 'convert.c') diff --git a/convert.c b/convert.c index 742b895cfa..37239ace83 100644 --- a/convert.c +++ b/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,33 +209,41 @@ 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; - - 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)) - return CRLF_BINARY; - else if (ATTR_UNSET(value)) - ; - else if (!strcmp(value, "input")) - return CRLF_INPUT; - /* fallthru */ - } + const char *value = check->value; + + if (ATTR_TRUE(value)) + return CRLF_TEXT; + else if (ATTR_FALSE(value)) + return CRLF_BINARY; + else if (ATTR_UNSET(value)) + ; + else if (!strcmp(value, "input")) + return CRLF_INPUT; 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); } -- cgit v1.2.1