diff mercurial/cmdutil.py @ 26937:dda0aa3baedd

cmdutil: add origbackuppath helper
author Christian Delahousse <cdelahousse@fb.com>
date Thu, 12 Nov 2015 16:56:06 -0600
parents 1aee2ab0f902
children 080276d377d9
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Tue Nov 10 11:16:25 2015 -0800
+++ b/mercurial/cmdutil.py	Thu Nov 12 16:56:06 2015 -0600
@@ -3114,6 +3114,26 @@
     finally:
         wlock.release()
 
+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) if not specified
+    '''
+    origbackuppath = ui.config('ui', 'origbackuppath', None)
+    if origbackuppath is None:
+        return filepath + ".orig"
+
+    filepathfromroot = os.path.relpath(filepath, start=repo.root)
+    fullorigpath = repo.wjoin(origbackuppath, filepathfromroot)
+
+    origbackupdir = repo.vfs.dirname(fullorigpath)
+    if not repo.vfs.exists(origbackupdir):
+        ui.note(_('creating directory: %s\n') % origbackupdir)
+        util.makedirs(origbackupdir)
+
+    return fullorigpath + ".orig"
+
 def _revertprefetch(repo, ctx, *files):
     """Let extension changing the storage layer prefetch content"""
     pass