[PATCH] revert: allow configuring the .orig file location
Augie Fackler
raf at durin42.com
Tue Aug 11 15:02:36 CDT 2015
On Mon, Aug 10, 2015 at 09:07:13PM -0700, Zainab Zahid wrote:
> # HG changeset patch
> # User Zainab Zahid <zzahid at fb.com>
> # Date 1438967257 25200
> # Fri Aug 07 10:07:37 2015 -0700
> # Node ID 92707bacbef0292af14701d0e812cbbf7239f754
> # Parent eabba9c75061254ff62827f92df0f32491c74b3d
> revert: allow configuring the .orig file location
Why? Is having .orig in ignores insufficient?
(I'm -0 on this patch because I can't think of a VCS tool that offers
it, and everyone's been fine with that for the past N decades...)
>
> Adding support for a 'revertbackuppath' entry under section [ui] in the configuration file.
> It allows user to specify where .orig files should be stored relative to the repo.
> In case of no revertbackuppath entry, we fallback to the default behaviour of moving old
> versions of a file to a file name <oldpath>.orig. This will prevent cluttering of the
> working copy.
>
> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py
> +++ b/mercurial/cmdutil.py
> @@ -3037,7 +3037,7 @@
> xlist.append(abs)
> if dobackup and (backup <= dobackup
> or wctx[abs].cmp(ctx[abs])):
> - bakname = "%s.orig" % rel
> + bakname = _getrevertbackuppath(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 _getrevertbackuppath(ui, repo, filepath):
> + '''customize where .orig files are created
> +
> + Fetch user defined path from config file: [ui] revertbackuppath = <path>
> + Fall back to default (filepath) if not specified
> + '''
> + revertbackuppath = ui.config('ui', 'revertbackuppath', None)
> + if revertbackuppath is None:
> + return filepath + ".orig"
> +
> + filepathfromroot = os.path.relpath(filepath, start=repo.root)
> + revertpath = repo.wjoin(revertbackuppath, filepathfromroot);
> +
> + revertbackupdir = repo.vfs.dirname(revertpath)
> + if not repo.vfs.exists(revertbackupdir):
> + ui.note(_('creating directory: %s\n') % revertbackupdir)
> + util.makedirs(revertbackupdir)
> +
> + return revertpath + ".orig"
> +
> def _revertprefetch(repo, ctx, *files):
> """Let extension changing the storage layer prefetch content"""
> pass
> diff --git a/tests/test-revert.t b/tests/test-revert.t
> --- a/tests/test-revert.t
> +++ b/tests/test-revert.t
> @@ -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]
> + > revertbackuppath= .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)
> --------------------------------
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list