Patchwork [2,of,6] revert: extract origvfs logic in a sub-function

login
register
mail settings
Submitter Boris Feld
Date Nov. 26, 2018, 6:22 p.m.
Message ID <a83de6825f6aac64efc0.1543256564@localhost.localdomain>
Download mbox | patch
Permalink /patch/36775/
State Accepted
Headers show

Comments

Boris Feld - Nov. 26, 2018, 6:22 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1542911165 -3600
#      Thu Nov 22 19:26:05 2018 +0100
# Node ID a83de6825f6aac64efc059e6224225b073d441f4
# Parent  5bcdd426a817c333ca30dac9a02ec100f962155e
# EXP-Topic vfs.audit-rename
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r a83de6825f6a
revert: extract origvfs logic in a sub-function

The subrepo's "revert" logic could benefit from it.

Patch

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -814,21 +814,29 @@  def parsefollowlinespattern(repo, rev, p
             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))