Patchwork [V3] revert: allow configuring the .orig file location

login
register
mail settings
Submitter Christian Delahousse
Date Oct. 27, 2015, 4:41 a.m.
Message ID <bf4086fe61d06e3d766a.1445920898@dev4253.prn1.facebook.com>
Download mbox | patch
Permalink /patch/11248/
State Superseded
Commit 080276d377d9131c1fd4f538f7def95d669eba9f
Headers show

Comments

Christian Delahousse - Oct. 27, 2015, 4:41 a.m.
# HG changeset patch
# User Zainab Zahid <zzahid@fb.com>
# Date 1445920380 25200
#      Mon Oct 26 21:33:00 2015 -0700
# Branch stable
# Node ID bf4086fe61d06e3d766a9b00e9e489b4f2b185e9
# Parent  a9ed5a8fc5e0554d5cb81b7206d2203cc49a2d23
revert: allow configuring the .orig file location

Adding support for a 'origbackuppath' 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 origbackuppath 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.
Sean Farley - Oct. 28, 2015, 5:35 p.m.
Christian Delahousse <cdelahousse@fb.com> writes:

> # HG changeset patch
> # User Zainab Zahid <zzahid@fb.com>
> # Date 1445920380 25200
> #      Mon Oct 26 21:33:00 2015 -0700
> # Branch stable
> # Node ID bf4086fe61d06e3d766a9b00e9e489b4f2b185e9
> # Parent  a9ed5a8fc5e0554d5cb81b7206d2203cc49a2d23
> revert: allow configuring the .orig file location
>
> Adding support for a 'origbackuppath' 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 origbackuppath 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.

Looks like no one has responded yet. I like the direction of your
patches (but haven't taken an in-depth look yet) but we are in the
middle of a code freeze, so I think mpm will want you to refrain from
feature patches and focus on bug fixes / regressions / etc.

Since we just had the sprint last week, I can see how things are a bit
confusing with timelines. Anyway,

http://i.ytimg.com/vi/GD6qtc2_AQA/sddefault.jpg
Augie Fackler - Oct. 29, 2015, 6:28 p.m.
On Wed, Oct 28, 2015 at 10:35:42AM -0700, Sean Farley wrote:
>
> Christian Delahousse <cdelahousse@fb.com> writes:
>
> > # HG changeset patch
> > # User Zainab Zahid <zzahid@fb.com>
> > # Date 1445920380 25200
> > #      Mon Oct 26 21:33:00 2015 -0700
> > # Branch stable
> > # Node ID bf4086fe61d06e3d766a9b00e9e489b4f2b185e9
> > # Parent  a9ed5a8fc5e0554d5cb81b7206d2203cc49a2d23
> > revert: allow configuring the .orig file location
> >
> > Adding support for a 'origbackuppath' 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 origbackuppath 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.
>
> Looks like no one has responded yet. I like the direction of your
> patches (but haven't taken an in-depth look yet) but we are in the
> middle of a code freeze, so I think mpm will want you to refrain from
> feature patches and focus on bug fixes / regressions / etc.

I also like it, but it may end up being necessary to do a resend after
November 1st (after we've released 3.6.)

>
> Since we just had the sprint last week, I can see how things are a bit
> confusing with timelines. Anyway,
>
> http://i.ytimg.com/vi/GD6qtc2_AQA/sddefault.jpg
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel
Matt Mackall - Nov. 1, 2015, 7:39 p.m.
On Mon, 2015-10-26 at 21:41 -0700, Christian Delahousse wrote:
> # HG changeset patch
> # User Zainab Zahid <zzahid@fb.com>
> # Date 1445920380 25200
> #      Mon Oct 26 21:33:00 2015 -0700
> # Branch stable
> # Node ID bf4086fe61d06e3d766a9b00e9e489b4f2b185e9
> # Parent  a9ed5a8fc5e0554d5cb81b7206d2203cc49a2d23
> revert: allow configuring the .orig file location

I think I mentioned before that ".orig" files are in no way specific to
revert, so this patch is rather incomplete:

$ hgrep "[.]orig['\"]"
hgext/largefiles/lfcommands.py:                if (os.path.exists(absstandin + '.orig') and
hgext/largefiles/lfcommands.py:                    shutil.copyfile(abslfile, abslfile + '.orig')
hgext/largefiles/lfcommands.py:                    util.unlinkpath(absstandin + '.orig')
hgext/mq.py:                             (f, f + '.orig'))
hgext/mq.py:                    util.copyfile(absf, absf + '.orig')
hgext/mq.py:                    util.rename(absf, absf + '.orig')
hgext/shelve.py:                util.rename(file, file + ".orig")
mercurial/cmdutil.py:                            bakname = "%s.orig" % rel
mercurial/commands.py:                util.rename(a + ".resolve", a + ".orig")
mercurial/filemerge.py:    back = a + ".orig"
mercurial/patch.py:    # If afile is "a/b/foo" and bfile is "a/b/foo.orig" we assume the
mercurial/subrepo.py:                bakname = "%s.orig" % name

This will need a non-_ version of the helper function, probably with a
shorter name, and probably in scmutil.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -3082,7 +3082,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'):
@@ -3114,6 +3114,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
diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
--- a/mercurial/help/config.txt
+++ b/mercurial/help/config.txt
@@ -1488,6 +1488,10 @@ 
     markers is different from the encoding of the merged files,
     serious problems may occur.
 
+``origbackuppath``
+    The path to a directory used to store generated .orig files. If the path is
+    not a directory, one will be created.
+
 ``patch``
     An optional external tool that ``hg import`` and some extensions
     will use for applying patches. By default Mercurial uses an
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]
+  > 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)
 --------------------------------