Re: CRLF problems with Git on Win32
- From
- Junio C Hamano <gitster-e+axbwqsrlaavxtiumwx3w@public.gmane.org>
- Date
- Jan 8, 2008, 21:15 UTC
- Message-ID
- <7vy7b0qarq.fsf@gitster.siamese.dyndns.org>
- In-Reply-To
- <20080108205054.GN6951-EQL4cN526mwi5CQI31g/s0B+6BGkLq7r@public.gmane.org>
Dmitry Potapov <dpotapov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
Show 17 quoted lines
> On Tue, Jan 08, 2008 at 07:58:57PM +0100, Steffen Prohaska wrote: >> >> I don't think a solution will be found by declaring one platform >> native (UNIX) and all other platform non-native. The question to >> answer is how to support cross-platform projects. A valid >> solution should never corrupt data unless the user explicitly >> told git to do so. I don't believe it is a valid solution to set >> core.autocrlf=true on Windows and tell the users: "Well, in its >> default settings, git sometimes corrupts your data on Windows. >> Maybe you want to switch to Linux because this is the native >> platform where data corruption will never happen." > > Maybe I am wrong but it seems to me that to guarantee that > CRLF conversion is reversible (which means that you can > always get exactly what you put into the repository), it is > enough to check that the conversation is performed only if > every LF is preceded by CR.
I've heard that before but I seem to recall convert.c already doing something similar if I am not mistaken.
static int crlf_to_git(const char *path, const char *src, size_t len,
struct strbuf *buf, int action)
{
struct text_stat stats;
char *dst;if ((action == CRLF_BINARY) || !auto_crlf || !len) return 0;
gather_stats(src, len, &stats); /* No CR? Nothing to convert, regardless. */ if (!stats.cr) return 0;
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)) return 0; }
It counts CR and CRLF and converts only when there are the same number of them. You probably only need to make it also count LF?