revert: extract origvfs logic in a sub-function
authorBoris Feld <boris.feld@octobus.net>
Thu, 22 Nov 2018 19:26:05 +0100
changeset 40752 65591a513b9c
parent 40751 41b6245c3fc4
child 40753 9199548525fc
revert: extract origvfs logic in a sub-function The subrepo's "revert" logic could benefit from it.
mercurial/scmutil.py
--- a/mercurial/scmutil.py	Thu Nov 22 18:44:07 2018 +0100
+++ b/mercurial/scmutil.py	Thu Nov 22 19:26:05 2018 +0100
@@ -814,21 +814,29 @@
             raise error.ParseError(msg)
         return files[0]
 
+def getorigvfs(ui, repo):
+    """return a vfs suitable to save 'orig' file
+
+    return None if no special directory is configured"""
+    origbackuppath = ui.config('ui', 'origbackuppath')
+    if not origbackuppath:
+        return None
+    return vfs.vfs(repo.wvfs.join(origbackuppath))
+
 def origpath(ui, repo, filepath):
     '''customize where .orig files are created
 
     Fetch user defined path from config file: [ui] origbackuppath = <path>
     Fall back to default (filepath with .orig suffix) if not specified
     '''
-    origbackuppath = ui.config('ui', 'origbackuppath')
-    if not origbackuppath:
+    origvfs = getorigvfs(ui, repo)
+    if origvfs is None:
         return filepath + ".orig"
 
     # Convert filepath from an absolute path into a path inside the repo.
     filepathfromroot = util.normpath(os.path.relpath(filepath,
                                                      start=repo.root))
 
-    origvfs = vfs.vfs(repo.wjoin(origbackuppath))
     origbackupdir = origvfs.dirname(filepathfromroot)
     if not origvfs.isdir(origbackupdir) or origvfs.islink(origbackupdir):
         ui.note(_('creating directory: %s\n') % origvfs.join(origbackupdir))