]> git.proxmox.com Git - libgit2.git/commitdiff
crlf: give Unix the glory of autocrlf=true
authorEdward Thomson <ethomson@edwardthomson.com>
Tue, 9 Jun 2015 00:42:28 +0000 (00:42 +0000)
committerEdward Thomson <ethomson@microsoft.com>
Mon, 22 Jun 2015 16:00:30 +0000 (12:00 -0400)
Perform LF->CRLF for core.autocrlf=true on non-Win32 because core
git does.

src/crlf.c

index 2fe8a5f55406f72d56f0188d53b74172d08316c1..f391137c1b4e7770fb06ef1f01e53f1ec82a27e3 100644 (file)
@@ -193,28 +193,29 @@ static const char *line_ending(struct crlf_attrs *ca)
        case GIT_CRLF_CRLF:
                return "\r\n";
 
+       case GIT_CRLF_GUESS:
+               if (ca->auto_crlf == GIT_AUTO_CRLF_FALSE)
+                       return "\n";
+               break;
+
        case GIT_CRLF_AUTO:
        case GIT_CRLF_TEXT:
-       case GIT_CRLF_GUESS:
                break;
 
        default:
                goto line_ending_error;
        }
 
-       switch (ca->eol) {
-       case GIT_EOL_UNSET:
-               return GIT_EOL_NATIVE == GIT_EOL_CRLF ? "\r\n" : "\n";
-
-       case GIT_EOL_CRLF:
+       if (ca->auto_crlf == GIT_AUTO_CRLF_TRUE)
                return "\r\n";
-
-       case GIT_EOL_LF:
+       else if (ca->auto_crlf == GIT_AUTO_CRLF_INPUT)
                return "\n";
-
-       default:
-               goto line_ending_error;
-       }
+       else if (ca->eol == GIT_EOL_UNSET)
+               return GIT_EOL_NATIVE == GIT_EOL_CRLF ? "\r\n" : "\n";
+       else if (ca->eol == GIT_EOL_LF)
+               return "\n";
+       else if (ca->eol == GIT_EOL_CRLF)
+               return "\r\n";
 
 line_ending_error:
        giterr_set(GITERR_INVALID, "Invalid input to line ending filter");
@@ -299,7 +300,7 @@ static int crlf_check(
                return GIT_PASSTHROUGH;
 
        if (ca.crlf_action == GIT_CRLF_GUESS ||
-               (ca.crlf_action == GIT_CRLF_AUTO &&
+               ((ca.crlf_action == GIT_CRLF_AUTO || ca.crlf_action == GIT_CRLF_TEXT) &&
                git_filter_source_mode(src) == GIT_FILTER_SMUDGE)) {
 
                error = git_repository__cvar(