Mercurial > public > mercurial-scm > hg
comparison mercurial/scmutil.py @ 41595:8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Unlike most functions in our codebase, origpath() takes a path that is
relative to cwd. This commit introduces a replacement for
origpath(). The new function takes a path that is relative to the repo
root. There is a lot of duplication between the two, but I intend to
remove origpath() within the next few commits, so it won't be a
maintenance burden.
origpath() is also a little weird in that it returns either a a
cwd-relative path or an absolute path. It needs to be able to return a
path outside the repo, so it makes sense that it can return an
absolute path. However, it would be simpler to always return an
absolute path. The new function does that.
Differential Revision: https://phab.mercurial-scm.org/D5851
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Mon, 04 Feb 2019 20:46:33 -0800 |
parents | aec185af621e |
children | e944cf4ce1a8 |
comparison
equal
deleted
inserted
replaced
41594:7e09ffb3170d | 41595:8785188d1915 |
---|---|
836 origbackuppath = ui.config('ui', 'origbackuppath') | 836 origbackuppath = ui.config('ui', 'origbackuppath') |
837 if not origbackuppath: | 837 if not origbackuppath: |
838 return None | 838 return None |
839 return vfs.vfs(repo.wvfs.join(origbackuppath)) | 839 return vfs.vfs(repo.wvfs.join(origbackuppath)) |
840 | 840 |
841 def backuppath(ui, repo, filepath): | |
842 '''customize where working copy backup files (.orig files) are created | |
843 | |
844 Fetch user defined path from config file: [ui] origbackuppath = <path> | |
845 Fall back to default (filepath with .orig suffix) if not specified | |
846 | |
847 filepath is repo-relative | |
848 | |
849 Returns an absolute path | |
850 ''' | |
851 origvfs = getorigvfs(ui, repo) | |
852 if origvfs is None: | |
853 return repo.wjoin(filepath + ".orig") | |
854 | |
855 origbackupdir = origvfs.dirname(filepath) | |
856 if not origvfs.isdir(origbackupdir) or origvfs.islink(origbackupdir): | |
857 ui.note(_('creating directory: %s\n') % origvfs.join(origbackupdir)) | |
858 | |
859 # Remove any files that conflict with the backup file's path | |
860 for f in reversed(list(util.finddirs(filepath))): | |
861 if origvfs.isfileorlink(f): | |
862 ui.note(_('removing conflicting file: %s\n') | |
863 % origvfs.join(f)) | |
864 origvfs.unlink(f) | |
865 break | |
866 | |
867 origvfs.makedirs(origbackupdir) | |
868 | |
869 if origvfs.isdir(filepath) and not origvfs.islink(filepath): | |
870 ui.note(_('removing conflicting directory: %s\n') | |
871 % origvfs.join(filepath)) | |
872 origvfs.rmtree(filepath, forcibly=True) | |
873 | |
874 return origvfs.join(filepath) | |
875 | |
841 def origpath(ui, repo, filepath): | 876 def origpath(ui, repo, filepath): |
842 '''customize where .orig files are created | 877 '''customize where .orig files are created |
843 | 878 |
844 Fetch user defined path from config file: [ui] origbackuppath = <path> | 879 Fetch user defined path from config file: [ui] origbackuppath = <path> |
845 Fall back to default (filepath with .orig suffix) if not specified | 880 Fall back to default (filepath with .orig suffix) if not specified |