Mercurial > hg
changeset 45154:10f48720ef95
diff: move no-eol text constant to a common location
Differential Revision: https://phab.mercurial-scm.org/D8763
author | Rodrigo Damazio Bovendorp <rdamazio@google.com> |
---|---|
date | Fri, 17 Jul 2020 03:53:19 -0700 |
parents | 8b6a446508c2 |
children | a381618210d0 |
files | mercurial/crecord.py mercurial/diffhelper.py mercurial/mdiff.py mercurial/patch.py |
diffstat | 4 files changed, 13 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/crecord.py Fri Jul 17 02:31:42 2020 -0700 +++ b/mercurial/crecord.py Fri Jul 17 03:53:19 2020 -0700 @@ -20,6 +20,7 @@ open, ) from . import ( + diffhelper, encoding, error, patch as patchmod, @@ -416,7 +417,7 @@ contextlen = ( len(self.before) + len(self.after) + removedconvertedtocontext ) - if self.after and self.after[-1] == b'\\ No newline at end of file\n': + if self.after and self.after[-1] == diffhelper.MISSING_NEWLINE_MARKER: contextlen -= 1 fromlen = contextlen + self.removed tolen = contextlen + self.added @@ -503,7 +504,7 @@ noeol = False for line in self.changedlines: text = line.linetext - if line.linetext == b'\\ No newline at end of file\n': + if line.linetext == diffhelper.MISSING_NEWLINE_MARKER: noeol = True break if line.applied:
--- a/mercurial/diffhelper.py Fri Jul 17 02:31:42 2020 -0700 +++ b/mercurial/diffhelper.py Fri Jul 17 03:53:19 2020 -0700 @@ -14,6 +14,8 @@ pycompat, ) +MISSING_NEWLINE_MARKER = b'\\ No newline at end of file\n' + def addlines(fp, hunk, lena, lenb, a, b): """Read lines from fp into the hunk @@ -32,7 +34,7 @@ s = fp.readline() if not s: raise error.ParseError(_(b'incomplete hunk')) - if s == b"\\ No newline at end of file\n": + if s == MISSING_NEWLINE_MARKER: fixnewline(hunk, a, b) continue if s == b'\n' or s == b'\r\n':
--- a/mercurial/mdiff.py Fri Jul 17 02:31:42 2020 -0700 +++ b/mercurial/mdiff.py Fri Jul 17 03:53:19 2020 -0700 @@ -17,6 +17,7 @@ setattr, ) from . import ( + diffhelper, encoding, error, policy, @@ -25,8 +26,6 @@ ) from .utils import dateutil -_missing_newline_marker = b"\\ No newline at end of file\n" - bdiff = policy.importmod('bdiff') mpatch = policy.importmod('mpatch') @@ -309,7 +308,7 @@ hunklines = [b"@@ -0,0 +1,%d @@\n" % size] + [b"+" + e for e in b] if without_newline: hunklines[-1] += b'\n' - hunklines.append(_missing_newline_marker) + hunklines.append(diffhelper.MISSING_NEWLINE_MARKER) hunks = ((hunkrange, hunklines),) elif not b: without_newline = not a.endswith(b'\n') @@ -325,7 +324,7 @@ hunklines = [b"@@ -1,%d +0,0 @@\n" % size] + [b"-" + e for e in a] if without_newline: hunklines[-1] += b'\n' - hunklines.append(_missing_newline_marker) + hunklines.append(diffhelper.MISSING_NEWLINE_MARKER) hunks = ((hunkrange, hunklines),) else: hunks = _unidiff(a, b, opts=opts) @@ -418,13 +417,13 @@ if hunklines[i].startswith(b' '): skip = True hunklines[i] += b'\n' - hunklines.insert(i + 1, _missing_newline_marker) + hunklines.insert(i + 1, diffhelper.MISSING_NEWLINE_MARKER) break if not skip and not t2.endswith(b'\n') and bstart + blen == len(l2) + 1: for i in pycompat.xrange(len(hunklines) - 1, -1, -1): if hunklines[i].startswith(b'+'): hunklines[i] += b'\n' - hunklines.insert(i + 1, _missing_newline_marker) + hunklines.insert(i + 1, diffhelper.MISSING_NEWLINE_MARKER) break yield hunkrange, hunklines
--- a/mercurial/patch.py Fri Jul 17 02:31:42 2020 -0700 +++ b/mercurial/patch.py Fri Jul 17 03:53:19 2020 -0700 @@ -785,7 +785,7 @@ for l in x.hunk: lines.append(l) if l[-1:] != b'\n': - lines.append(b"\n\\ No newline at end of file\n") + lines.append(b'\n' + diffhelper.MISSING_NEWLINE_MARKER) self.backend.writerej(self.fname, len(self.rej), self.hunks, lines) def apply(self, h): @@ -1069,7 +1069,7 @@ def write(self, fp): delta = len(self.before) + len(self.after) - if self.after and self.after[-1] == b'\\ No newline at end of file\n': + if self.after and self.after[-1] == diffhelper.MISSING_NEWLINE_MARKER: delta -= 1 fromlen = delta + self.removed tolen = delta + self.added