diff mercurial/crecord.py @ 45153:8b6a446508c2

revert: fix interactive reverting of end-of-file newline changes The chunk reversal used by `revert -i` in Curses mode was not taking this case into account. Differential Revision: https://phab.mercurial-scm.org/D8762
author Rodrigo Damazio Bovendorp <rdamazio@google.com>
date Fri, 17 Jul 2020 02:31:42 -0700
parents 4a503c1b664a
children 10f48720ef95
line wrap: on
line diff
--- a/mercurial/crecord.py	Thu Jul 16 14:16:53 2020 -0400
+++ b/mercurial/crecord.py	Fri Jul 17 02:31:42 2020 -0700
@@ -500,8 +500,12 @@
         """
         dels = []
         adds = []
+        noeol = False
         for line in self.changedlines:
             text = line.linetext
+            if line.linetext == b'\\ No newline at end of file\n':
+                noeol = True
+                break
             if line.applied:
                 if text.startswith(b'+'):
                     dels.append(text[1:])
@@ -511,6 +515,9 @@
                 dels.append(text[1:])
                 adds.append(text[1:])
         hunk = [b'-%s' % l for l in dels] + [b'+%s' % l for l in adds]
+        if noeol and hunk:
+            # Remove the newline from the end of the hunk.
+            hunk[-1] = hunk[-1][:-1]
         h = self._hunk
         return patchmod.recordhunk(
             h.header, h.toline, h.fromline, h.proc, h.before, hunk, h.after