{"thread":{"id":"19199","subject":"[PATCH 2/2] conversion of lonely cr chars in autocrlf","startedAt":"2009-05-06T15:10:18Z","lastAt":"2009-05-06T15:10:18Z","messageCount":1,"participants":["Heiko Voigt"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"113088","messageId":"20090506151018.GB2974@macbook.lan","threadId":"19199","inReplyTo":null,"subject":"[PATCH 2/2] conversion of lonely cr chars in autocrlf","fromName":"Heiko Voigt","fromEmail":"hvoigt@hvoigt.net","sentAt":"2009-05-06T15:10:18Z","receivedAt":"2009-05-06T15:10:18Z","isPatch":true,"sender":{"key":"hvoigt@hvoigt.net","avatar":"https://avatars.githubusercontent.com/u/184958?v=4"},"body":"This is was marked as crazy stuff but certainly done by our\ndevelopers in an 10 year old rcs like repository\n\nSigned-off-by: Heiko Voigt <heiko.voigt@mahr.de>\n---\nThis belongs to an conversion effort of quite matured repositories. I\ndo not know how many programs still write CR's as their line endings but\nthere certainly are/were some.\n\nAnybody interested in that crazy stuff?\n\n convert.c |   27 +++++++++++++--------------\n 1 files changed, 13 insertions(+), 14 deletions(-)\n\ndiff --git a/convert.c b/convert.c\nindex 0ced471..7164f09 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -133,14 +133,6 @@ static int crlf_to_git(const char *path, const char *src, size_t len,\n \n \tif (action == CRLF_GUESS) {\n \t\t/*\n-\t\t * We're currently not going to even try to convert stuff\n-\t\t * that has bare CR characters. Does anybody do that crazy\n-\t\t * stuff?\n-\t\t */\n-\t\tif (stats.cr != stats.crlf)\n-\t\t\treturn 0;\n-\n-\t\t/*\n \t\t * And add some heuristics for binary vs text, of course...\n \t\t */\n \t\tif (is_binary(len, &stats))\n@@ -158,15 +150,22 @@ static int crlf_to_git(const char *path, const char *src, size_t len,\n \t\tstrbuf_grow(buf, len - buf->len);\n \tdst = buf->buf;\n \tif (action == CRLF_GUESS) {\n-\t\t/*\n-\t\t * If we guessed, we already know we rejected a file with\n-\t\t * lone CR, and we can strip a CR without looking at what\n-\t\t * follow it.\n-\t\t */\n \t\tdo {\n \t\t\tunsigned char c = *src++;\n-\t\t\tif (c != '\\r')\n+\t\t\tif (c != '\\r') {\n+\t\t\t\t/* if its not cr copy this char */\n \t\t\t\t*dst++ = c;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\tif (c == '\\r' && (1 < len && *src == '\\n')) {\n+\t\t\t\t/* if its \\r\\n skip this char */\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\tif (c == '\\r' && !(1 < len && *src == '\\n')) {\n+\t\t\t\t/* if its a lonely cr substitute it */\n+\t\t\t\t*dst++ = '\\n';\n+\t\t\t}\n+\n \t\t} while (--len);\n \t} else {\n \t\tdo {\n-- \n1.6.2.1.423.g442d\n"}]}