From: Heiko Voigt <hvoigt@hvoigt.net>
To: git@vger.kernel.org
Cc: gitster@pobox.com
Subject: [PATCH 2/2] conversion of lonely cr chars in autocrlf
Date: Wed, 6 May 2009 17:10:18 +0200 [thread overview]
Message-ID: <20090506151018.GB2974@macbook.lan> (raw)
This is was marked as crazy stuff but certainly done by our
developers in an 10 year old rcs like repository
Signed-off-by: Heiko Voigt <heiko.voigt@mahr.de>
---
This belongs to an conversion effort of quite matured repositories. I
do not know how many programs still write CR's as their line endings but
there certainly are/were some.
Anybody interested in that crazy stuff?
convert.c | 27 +++++++++++++--------------
1 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/convert.c b/convert.c
index 0ced471..7164f09 100644
--- a/convert.c
+++ b/convert.c
@@ -133,14 +133,6 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
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
- * stuff?
- */
- if (stats.cr != stats.crlf)
- return 0;
-
- /*
* And add some heuristics for binary vs text, of course...
*/
if (is_binary(len, &stats))
@@ -158,15 +150,22 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
strbuf_grow(buf, len - buf->len);
dst = buf->buf;
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 = *src++;
- if (c != '\r')
+ if (c != '\r') {
+ /* if its not cr copy this char */
*dst++ = c;
+ continue;
+ }
+ if (c == '\r' && (1 < len && *src == '\n')) {
+ /* if its \r\n skip this char */
+ continue;
+ }
+ if (c == '\r' && !(1 < len && *src == '\n')) {
+ /* if its a lonely cr substitute it */
+ *dst++ = '\n';
+ }
+
} while (--len);
} else {
do {
--
1.6.2.1.423.g442d
reply other threads:[~2009-05-06 15:10 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090506151018.GB2974@macbook.lan \
--to=hvoigt@hvoigt.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).