Comments
Patch
@@ -3037,7 +3037,7 @@
xlist.append(abs)
if dobackup and (backup <= dobackup
or wctx[abs].cmp(ctx[abs])):
- bakname = "%s.orig" % rel
+ bakname = _getorigbackuppath(ui, repo, rel)
ui.note(_('saving current version of %s as %s\n') %
(rel, bakname))
if not opts.get('dry_run'):
@@ -3069,6 +3069,26 @@
finally:
wlock.release()
+def _getorigbackuppath(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)
+ origpath = repo.wjoin(origbackuppath, filepathfromroot);
+
+ origbackupdir = repo.vfs.dirname(origpath)
+ if not repo.vfs.exists(origbackupdir):
+ ui.note(_('creating directory: %s\n') % origbackupdir)
+ util.makedirs(origbackupdir)
+
+ return origpath + ".orig"
+
def _revertprefetch(repo, ctx, *files):
"""Let extension changing the storage layer prefetch content"""
pass
@@ -86,6 +86,23 @@
saving current version of e as e.orig
reverting e
+Test creation of backup (.orig) file in configured file location
+----------------------------------------------------------------
+
+ $ cat $HGRCPATH > hgrc_bak
+ $ cat >> $HGRCPATH << EOF
+ > [ui]
+ > origbackuppath= .hg/origbackups
+ > EOF
+ $ echo z > e
+ $ hg revert --all -v
+ creating directory: $TESTTMP/repo/.hg/origbackups
+ saving current version of e as $TESTTMP/repo/.hg/origbackups/e.orig
+ reverting e
+ $ cp $TESTTMP/repo/.hg/origbackups/e.orig .
+ $ cp hgrc_bak $HGRCPATH
+ $ rm hgrc_bak
+
revert on clean file (no change)
--------------------------------