diff mercurial/patch.py @ 46246:416ecdaa12df

patch: handle filenames with trailing spaces I have no idea if this is *actually* supported by the patch file format, but at least when reading from a patch file created by running `hg shelve`, it is written out such that there's a trailing space after the second (`b`) filename. When we read the patch file, we remove the space before parsing the filenames, so it doesn't end up matching the other sources of what files are in the shelve. We observed this internally due to a wrapper around unshelve that called into patch.changedfiles, but `hg patch` is able to reproduce the issue as well, so I've included both tests. Differential Revision: https://phab.mercurial-scm.org/D9729
author Kyle Lippincott <spectral@google.com>
date Mon, 11 Jan 2021 17:46:55 -0800
parents 2cf61e66c6d0
children 33350debb480
line wrap: on
line diff
--- a/mercurial/patch.py	Tue Dec 29 23:15:26 2020 +0100
+++ b/mercurial/patch.py	Mon Jan 11 17:46:55 2021 -0800
@@ -393,7 +393,7 @@
     gp = None
     gitpatches = []
     for line in lr:
-        line = line.rstrip(b' \r\n')
+        line = line.rstrip(b'\r\n')
         if line.startswith(b'diff --git a/'):
             m = gitre.match(line)
             if m:
@@ -2073,7 +2073,7 @@
                 yield b'file', (afile, bfile, h, gp and gp.copy() or None)
             yield b'hunk', h
         elif x.startswith(b'diff --git a/'):
-            m = gitre.match(x.rstrip(b' \r\n'))
+            m = gitre.match(x.rstrip(b'\r\n'))
             if not m:
                 continue
             if gitpatches is None: