diffhelpers: handle CRLF in hunk last line without EOL
authorPatrick Mezard <pmezard@gmail.com>
Wed, 23 Dec 2009 19:31:48 +0100
changeset 10129 900ccbd79ef7
parent 10128 ea7c392f2b08
child 10130 7936cd261dc9
diffhelpers: handle CRLF in hunk last line without EOL Note that diff generation code always ends last lines without newline with a LF, so this is a tolerance.
mercurial/diffhelpers.c
tests/test-mq-eol
--- a/mercurial/diffhelpers.c	Wed Dec 23 19:31:48 2009 +0100
+++ b/mercurial/diffhelpers.c	Wed Dec 23 19:31:48 2009 +0100
@@ -22,6 +22,9 @@
 	PyObject *s = PyList_GET_ITEM(hunk, hunksz-1);
 	char *l = PyString_AS_STRING(s);
 	int sz = PyString_GET_SIZE(s);
+	if (sz > 1 && l[sz-2] == '\r')
+	        /* tolerate CRLF in last line */
+	        sz -= 1;
 	int alen = PyList_Size(a);
 	int blen = PyList_Size(b);
 	char c = l[0];
--- a/tests/test-mq-eol	Wed Dec 23 19:31:48 2009 +0100
+++ b/tests/test-mq-eol	Wed Dec 23 19:31:48 2009 +0100
@@ -20,7 +20,7 @@
 w(' d\n')
 w('-e\n')
 w('\ No newline at end of file\n')
-w('+z\n')
+w('+z\r\n')
 w('\ No newline at end of file\r\n')
 EOF