diff mercurial/patch.py @ 24390:72d7d390ef5d

patch._applydiff: resolve prefix with respect to the cwd This has several advantages compared to resolving it relative to the root: - '--prefix .' works as expected. - consistent with upcoming 'hg diff' option to produce relative patches (I made sure to put in the (glob) annotations this time!)
author Siddharth Agarwal <sid0@fb.com>
date Thu, 19 Mar 2015 10:18:05 -0700
parents 885a573fa619
children f07047a506d1
line wrap: on
line diff
--- a/mercurial/patch.py	Fri Mar 20 00:22:37 2015 +0900
+++ b/mercurial/patch.py	Thu Mar 19 10:18:05 2015 -0700
@@ -17,6 +17,7 @@
 from node import hex, short
 import cStringIO
 import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error
+import pathutil
 
 gitre = re.compile('diff --git a/(.*) b/(.*)')
 tabsplitter = re.compile(r'(\t+|[^\t]+)')
@@ -1795,8 +1796,10 @@
                eolmode='strict'):
 
     if prefix:
-        # clean up double slashes, lack of trailing slashes, etc
-        prefix = util.normpath(prefix) + '/'
+        prefix = pathutil.canonpath(backend.repo.root, backend.repo.getcwd(),
+                                    prefix)
+        if prefix != '':
+            prefix += '/'
     def pstrip(p):
         return pathtransform(p, strip - 1, prefix)[1]