mercurial/patch.py
changeset 38630 e1987261dd05
parent 38588 1c93e0237a24
child 38773 59af0c7d103f
--- a/mercurial/patch.py	Sat Jul 07 23:38:06 2018 -0400
+++ b/mercurial/patch.py	Tue Jul 10 13:18:34 2018 +0200
@@ -2405,7 +2405,7 @@
     """yield tokens for a list of lines in a single hunk"""
     for line in hunklines:
         # chomp
-        chompline = line.rstrip('\n')
+        chompline = line.rstrip('\r\n')
         # highlight tabs and trailing whitespace
         stripline = chompline.rstrip()
         if line.startswith('-'):
@@ -2473,6 +2473,9 @@
             isendofline = token.endswith('\n')
             if isendofline:
                 chomp = token[:-1] # chomp
+                if chomp.endswith('\r'):
+                    chomp = chomp[:-1]
+                endofline = token[len(chomp):]
                 token = chomp.rstrip() # detect spaces at the end
                 endspaces = chomp[len(token):]
             # scan tabs
@@ -2488,7 +2491,7 @@
             if isendofline:
                 if endspaces:
                     yield (endspaces, 'diff.trailingwhitespace')
-                yield ('\n', '')
+                yield (endofline, '')
                 nextisnewline = True
 
 def difflabel(func, *args, **kw):