summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-06-08 13:51:28 -0400
committerEdward Thomson <ethomson@microsoft.com>2015-06-22 12:00:23 -0400
commit8293c8f9a3ea18131af98b71fa9100dcba0ad438 (patch)
tree0c3d808ceed1e665af0dee8be148466c7f2b05ea /src
parent47e9a6cb0573aa2190ddabadb94c0a89ae14ba52 (diff)
downloadlibgit2-8293c8f9a3ea18131af98b71fa9100dcba0ad438.tar.gz
git_buf_text_lf_to_crlf: allow mixed line endings
Allow files to have mixed line endings instead of skipping processing on them.
Diffstat (limited to 'src')
-rw-r--r--src/buf_text.c10
-rw-r--r--src/buf_text.h3
2 files changed, 5 insertions, 8 deletions
diff --git a/src/buf_text.c b/src/buf_text.c
index 864e39cab..7e6779d2d 100644
--- a/src/buf_text.c
+++ b/src/buf_text.c
@@ -131,17 +131,15 @@ int git_buf_text_lf_to_crlf(git_buf *tgt, const git_buf *src)
for (; next; scan = next + 1, next = memchr(scan, '\n', end - scan)) {
size_t copylen = next - scan;
- /* if we find mixed line endings, bail */
- if (next > start && next[-1] == '\r') {
- git_buf_free(tgt);
- return GIT_PASSTHROUGH;
- }
+ /* if we find mixed line endings, carry on */
+ if (copylen && next[-1] == '\r')
+ copylen--;
GITERR_CHECK_ALLOC_ADD(&alloclen, copylen, 3);
if (git_buf_grow_by(tgt, alloclen) < 0)
return -1;
- if (next > scan) {
+ if (copylen) {
memcpy(tgt->ptr + tgt->size, scan, copylen);
tgt->size += copylen;
}
diff --git a/src/buf_text.h b/src/buf_text.h
index e753a0244..c9c55af89 100644
--- a/src/buf_text.h
+++ b/src/buf_text.h
@@ -58,8 +58,7 @@ extern void git_buf_text_unescape(git_buf *buf);
/**
* Replace all \r\n with \n.
*
- * @return 0 on success, -1 on memory error, GIT_PASSTHROUGH if the
- * source buffer has mixed line endings.
+ * @return 0 on success, -1 on memory error
*/
extern int git_buf_text_crlf_to_lf(git_buf *tgt, const git_buf *src);