Patchwork D1413: patch: accept prefix argument to changedfiles() helper

login
register
mail settings
Submitter phabricator
Date Nov. 15, 2017, 2:02 p.m.
Message ID <5d6c3f5eb82e0182cb6e1a1f896c4dc7@localhost.localdomain>
Download mbox | patch
Permalink /patch/25583/
State Not Applicable
Headers show

Comments

phabricator - Nov. 15, 2017, 2:02 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG1706eae096e2: patch: accept prefix argument to changedfiles() helper (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1413?vs=3493&id=3526

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

AFFECTED FILES
  mercurial/patch.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers, lothiraldan, yuja
Cc: mercurial-devel

Patch

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -1990,14 +1990,16 @@ 
     return _applydiff(ui, fp, patchfile, backend, store, strip=strip,
                       prefix=prefix, eolmode=eolmode)
 
+def _canonprefix(repo, prefix):
+    if prefix:
+        prefix = pathutil.canonpath(repo.root, repo.getcwd(), prefix)
+        if prefix != '':
+            prefix += '/'
+    return prefix
+
 def _applydiff(ui, fp, patcher, backend, store, strip=1, prefix='',
                eolmode='strict'):
-
-    if prefix:
-        prefix = pathutil.canonpath(backend.repo.root, backend.repo.getcwd(),
-                                    prefix)
-        if prefix != '':
-            prefix += '/'
+    prefix = _canonprefix(backend.repo, prefix)
     def pstrip(p):
         return pathtransform(p, strip - 1, prefix)[1]
 
@@ -2183,20 +2185,22 @@ 
     return internalpatch(ui, repo, patchname, strip, prefix, files, eolmode,
                          similarity)
 
-def changedfiles(ui, repo, patchpath, strip=1):
+def changedfiles(ui, repo, patchpath, strip=1, prefix=''):
     backend = fsbackend(ui, repo.root)
+    prefix = _canonprefix(repo, prefix)
     with open(patchpath, 'rb') as fp:
         changed = set()
         for state, values in iterhunks(fp):
             if state == 'file':
                 afile, bfile, first_hunk, gp = values
                 if gp:
-                    gp.path = pathtransform(gp.path, strip - 1, '')[1]
+                    gp.path = pathtransform(gp.path, strip - 1, prefix)[1]
                     if gp.oldpath:
-                        gp.oldpath = pathtransform(gp.oldpath, strip - 1, '')[1]
+                        gp.oldpath = pathtransform(gp.oldpath, strip - 1,
+                                                   prefix)[1]
                 else:
                     gp = makepatchmeta(backend, afile, bfile, first_hunk, strip,
-                                       '')
+                                       prefix)
                 changed.add(gp.path)
                 if gp.op == 'RENAME':
                     changed.add(gp.oldpath)