# HG changeset patch # User Boris Feld # Date 2018-11-22 18:26:05 # Node ID 65591a513b9c10b6145ce2418068682ad51bb5ef # Parent 41b6245c3fc4d9a3f4b548e9114c7b6acc7ccb89 revert: extract origvfs logic in a sub-function The subrepo's "revert" logic could benefit from it. 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 = 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))