D5818: patch: properly escape \ in string literals

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Mon Feb 4 18:36:15 EST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG47c92f8ed128: patch: properly escape \ in string literals (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5818?vs=13745&id=13778

REVISION DETAIL
  https://phab.mercurial-scm.org/D5818

AFFECTED FILES
  mercurial/patch.py

CHANGE DETAILS

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -753,7 +753,7 @@
             for l in x.hunk:
                 lines.append(l)
                 if l[-1:] != '\n':
-                    lines.append("\n\ No newline at end of file\n")
+                    lines.append("\n\\ No newline at end of file\n")
         self.backend.writerej(self.fname, len(self.rej), self.hunks, lines)
 
     def apply(self, h):
@@ -1305,7 +1305,7 @@
             self.hunk.append(u)
 
         l = lr.readline()
-        if l.startswith('\ '):
+        if l.startswith(br'\ '):
             s = self.a[-1][:-1]
             self.a[-1] = s
             self.hunk[-1] = s
@@ -1323,7 +1323,7 @@
         hunki = 1
         for x in pycompat.xrange(self.lenb):
             l = lr.readline()
-            if l.startswith('\ '):
+            if l.startswith(br'\ '):
                 # XXX: the only way to hit this is with an invalid line range.
                 # The no-eol marker is not counted in the line range, but I
                 # guess there are diff(1) out there which behave differently.
@@ -1380,7 +1380,7 @@
 
     def _fixnewline(self, lr):
         l = lr.readline()
-        if l.startswith('\ '):
+        if l.startswith(br'\ '):
             diffhelper.fixnewline(self.hunk, self.a, self.b)
         else:
             lr.push(l)



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list