changeset 40752:65591a513b9c

revert: extract origvfs logic in a sub-function The subrepo's "revert" logic could benefit from it.
author Boris Feld <boris.feld@octobus.net>
date Thu, 22 Nov 2018 19:26:05 +0100
parents 41b6245c3fc4
children 9199548525fc
files mercurial/scmutil.py
diffstat 1 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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))