# HG changeset patch # User Yuya Nishihara # Date 1523032645 -32400 # Node ID 230eb959415002b1daed0025d6d38229b01043d8 # Parent a1bcc7ff0eac83d6c429295a01ce285c5492e65d diffhelpers: be more tolerant for stripped empty lines of CRLF ending Exchange. It appears to trim lines containing only whitespace as well as converting LF to CRLF. diff -r a1bcc7ff0eac -r 230eb9594150 mercurial/diffhelpers.py --- a/mercurial/diffhelpers.py Mon Apr 09 21:08:52 2018 +0900 +++ b/mercurial/diffhelpers.py Sat Apr 07 01:37:25 2018 +0900 @@ -33,10 +33,10 @@ if s == "\\ No newline at end of file\n": fixnewline(hunk, a, b) continue - if s == "\n": + if s == '\n' or s == '\r\n': # Some patches may be missing the control char # on empty lines. Supply a leading space. - s = " \n" + s = ' ' + s hunk.append(s) if s.startswith('+'): b.append(s[1:]) diff -r a1bcc7ff0eac -r 230eb9594150 tests/test-import-eol.t --- a/tests/test-import-eol.t Mon Apr 09 21:08:52 2018 +0900 +++ b/tests/test-import-eol.t Sat Apr 07 01:37:25 2018 +0900 @@ -1,5 +1,6 @@ $ cat > makepatch.py < f = open('eol.diff', 'wb') + > import sys + > f = open(sys.argv[2], 'wb') > w = f.write > w(b'test message\n') > w(b'diff --git a/a b/a\n') @@ -10,7 +11,10 @@ > w(b'-bbb\r\n') > w(b'+yyyy\r\n') > w(b' cc\r\n') - > w(b' \n') + > w({'empty:lf': b' \n', + > 'empty:crlf': b' \r\n', + > 'empty:stripped-lf': b'\n', + > 'empty:stripped-crlf': b'\r\n'}[sys.argv[1]]) > w(b' d\n') > w(b'-e\n') > w(b'\ No newline at end of file\n') @@ -29,8 +33,10 @@ $ hg ci -Am adda adding .hgignore adding a - $ $PYTHON ../makepatch.py - + $ $PYTHON ../makepatch.py empty:lf eol.diff + $ $PYTHON ../makepatch.py empty:crlf eol-empty-crlf.diff + $ $PYTHON ../makepatch.py empty:stripped-lf eol-empty-stripped-lf.diff + $ $PYTHON ../makepatch.py empty:stripped-crlf eol-empty-stripped-crlf.diff invalid eol @@ -45,6 +51,8 @@ $ hg --traceback --config patch.eol='LF' import eol.diff applying eol.diff + $ hg id + 9e4ef7b3d4af tip $ cat a a yyyy @@ -54,6 +62,25 @@ e (no-eol) $ hg st + (test empty-line variants: all of them should generate the same revision) + + $ hg up -qC 0 + $ hg --config patch.eol='LF' import eol-empty-crlf.diff + applying eol-empty-crlf.diff + $ hg id + 9e4ef7b3d4af tip + + $ hg up -qC 0 + $ hg --config patch.eol='LF' import eol-empty-stripped-lf.diff + applying eol-empty-stripped-lf.diff + $ hg id + 9e4ef7b3d4af tip + + $ hg up -qC 0 + $ hg --config patch.eol='LF' import eol-empty-stripped-crlf.diff + applying eol-empty-stripped-crlf.diff + $ hg id + 9e4ef7b3d4af tip force CRLF