Mercurial > public > mercurial-scm > hg
comparison mercurial/scmutil.py @ 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 | 4ec8bee15930 |
children | b7823bd59b07 |
comparison
equal
deleted
inserted
replaced
40751:41b6245c3fc4 | 40752:65591a513b9c |
---|---|
812 files = [f for f in ctx if m(f)] | 812 files = [f for f in ctx if m(f)] |
813 if len(files) != 1: | 813 if len(files) != 1: |
814 raise error.ParseError(msg) | 814 raise error.ParseError(msg) |
815 return files[0] | 815 return files[0] |
816 | 816 |
817 def getorigvfs(ui, repo): | |
818 """return a vfs suitable to save 'orig' file | |
819 | |
820 return None if no special directory is configured""" | |
821 origbackuppath = ui.config('ui', 'origbackuppath') | |
822 if not origbackuppath: | |
823 return None | |
824 return vfs.vfs(repo.wvfs.join(origbackuppath)) | |
825 | |
817 def origpath(ui, repo, filepath): | 826 def origpath(ui, repo, filepath): |
818 '''customize where .orig files are created | 827 '''customize where .orig files are created |
819 | 828 |
820 Fetch user defined path from config file: [ui] origbackuppath = <path> | 829 Fetch user defined path from config file: [ui] origbackuppath = <path> |
821 Fall back to default (filepath with .orig suffix) if not specified | 830 Fall back to default (filepath with .orig suffix) if not specified |
822 ''' | 831 ''' |
823 origbackuppath = ui.config('ui', 'origbackuppath') | 832 origvfs = getorigvfs(ui, repo) |
824 if not origbackuppath: | 833 if origvfs is None: |
825 return filepath + ".orig" | 834 return filepath + ".orig" |
826 | 835 |
827 # Convert filepath from an absolute path into a path inside the repo. | 836 # Convert filepath from an absolute path into a path inside the repo. |
828 filepathfromroot = util.normpath(os.path.relpath(filepath, | 837 filepathfromroot = util.normpath(os.path.relpath(filepath, |
829 start=repo.root)) | 838 start=repo.root)) |
830 | 839 |
831 origvfs = vfs.vfs(repo.wjoin(origbackuppath)) | |
832 origbackupdir = origvfs.dirname(filepathfromroot) | 840 origbackupdir = origvfs.dirname(filepathfromroot) |
833 if not origvfs.isdir(origbackupdir) or origvfs.islink(origbackupdir): | 841 if not origvfs.isdir(origbackupdir) or origvfs.islink(origbackupdir): |
834 ui.note(_('creating directory: %s\n') % origvfs.join(origbackupdir)) | 842 ui.note(_('creating directory: %s\n') % origvfs.join(origbackupdir)) |
835 | 843 |
836 # Remove any files that conflict with the backup file's path | 844 # Remove any files that conflict with the backup file's path |