summaryrefslogtreecommitdiff
path: root/src/crlf.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2013-03-21 14:02:25 -0700
committerRussell Belfer <rb@github.com>2013-03-25 14:03:16 -0700
commit4a15ea869ca097dca0b45b1202429cc12cb94219 (patch)
treecc85fd20d1b762643d27d9343c82356ffd361099 /src/crlf.c
parent1098cfaecae823ede02881f995f18aee2908b89f (diff)
downloadlibgit2-4a15ea869ca097dca0b45b1202429cc12cb94219.tar.gz
don't convert CRLF to CRCRLF
Diffstat (limited to 'src/crlf.c')
-rw-r--r--src/crlf.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/crlf.c b/src/crlf.c
index 84347ac6c..cd6d9825f 100644
--- a/src/crlf.c
+++ b/src/crlf.c
@@ -223,12 +223,17 @@ static int crlf_apply_to_odb(
static int convert_line_endings(git_buf *dest, const git_buf *source, const char *ending)
{
const char *scan = git_buf_cstr(source),
- *next,
- *scan_end = git_buf_cstr(source) + git_buf_len(source);
+ *next,
+ *line_end,
+ *scan_end = git_buf_cstr(source) + git_buf_len(source);
while ((next = memchr(scan, '\n', scan_end - scan)) != NULL) {
- if (next > scan)
- git_buf_put(dest, scan, next-scan);
+ if (next > scan) {
+ line_end = *(next - 1) == '\r' ? next - 1 : next;
+ git_buf_put(dest, scan, line_end - scan);
+ scan = next + 1;
+ }
+
git_buf_puts(dest, ending);
scan = next + 1;
}