Patchwork [evolve-ext] fold: require --from flag for folding revisions to working copy

login
register
mail settings
Submitter via Mercurial-devel
Date Jan. 12, 2017, 9:50 p.m.
Message ID <80a3dc2541cf09499eab.1484257849@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/18198/
State Accepted
Headers show

Comments

via Mercurial-devel - Jan. 12, 2017, 9:50 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1484257669 28800
#      Thu Jan 12 13:47:49 2017 -0800
# Node ID 80a3dc2541cf09499eab9f8e55d980590372f472
# Parent  3e270ed7ede06471c71968f148cbfc8e4ea60a54
fold: require --from flag for folding revisions to working copy

It's very easy to think that "hg fold 4::6" will fold exactly those
revisions. In reality, it will fold those *and* any revisions between
them and the working copy. To prevent users from making that mistake,
require the use of a new --from flag for folding revisions from the
given set to the working copy. With this change, I'm sure some users
will be surprised that the command can not be run without either
--from or --exact, but at least the consequences will be smaller (the
command simply aborts and the user can try again).
Pierre-Yves David - Jan. 13, 2017, 7:43 a.m.
On 01/12/2017 10:50 PM, Martin von Zweigbergk via Mercurial-devel wrote:
> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz@google.com>
> # Date 1484257669 28800
> #      Thu Jan 12 13:47:49 2017 -0800
> # Node ID 80a3dc2541cf09499eab9f8e55d980590372f472
> # Parent  3e270ed7ede06471c71968f148cbfc8e4ea60a54
> fold: require --from flag for folding revisions to working copy

Pushed, thanks. I'm not a huge fan of the what we decided on, but that 
is the best we could find that fitted our constraints.

I've made a minor update to the tests for the "no flag at all" cases.

Thanks.

Patch

diff -r 3e270ed7ede0 -r 80a3dc2541cf hgext/evolve.py
--- a/hgext/evolve.py	Thu Jan 05 01:36:37 2017 -0800
+++ b/hgext/evolve.py	Thu Jan 12 13:47:49 2017 -0800
@@ -3068,16 +3068,17 @@ 
 
 @command('^fold|squash',
     [('r', 'rev', [], _("revision to fold")),
-     ('', 'exact', None, _("only fold specified revisions"))
+     ('', 'exact', None, _("only fold specified revisions")),
+     ('', 'from', None, _("fold revisions linearly to working copy parent"))
     ] + commitopts + commitopts2,
     _('hg fold [OPTION]... [-r] REV'))
 def fold(ui, repo, *revs, **opts):
     """fold multiple revisions into a single one
 
-    By default, folds all the revisions linearly between the given revisions
+    With --from, folds all the revisions linearly between the given revisions
     and the parent of the working directory.
 
-    Use --exact for folding only the specified revisions while ignoring the
+    With --exact, folds only the specified revisions while ignoring the
     parent of the working directory. In this case, the given revisions must
     form a linear unbroken chain.
 
@@ -3087,18 +3088,18 @@ 
 
      - Fold the current revision with its parent::
 
-         hg fold .^
+         hg fold --from .^
 
      - Fold all draft revisions with working directory parent::
 
-         hg fold 'draft()'
+         hg fold --from 'draft()'
 
        See :hg:`help phases` for more about draft revisions and
        :hg:`help revsets` for more about the `draft()` keyword
 
      - Fold revisions between 3 and 6 with the working directory parent::
 
-         hg fold 3::6
+         hg fold --from 3::6
 
      - Fold revisions 3 and 4:
 
@@ -3115,7 +3116,9 @@ 
 
     revs = scmutil.revrange(repo, revs)
 
-    if not opts['exact']:
+    if opts['from'] and opts['exact']:
+        raise error.Abort(_('cannot use both --from and --exact'))
+    elif opts['from']:
         # Try to extend given revision starting from the working directory
         extrevs = repo.revs('(%ld::.) or (.::%ld)', revs, revs)
         discardedrevs = [r for r in revs if r not in extrevs]
@@ -3124,6 +3127,11 @@ 
                                hint=_("given revisions are unrelated to parent "
                                       "of working directory"))
         revs = extrevs
+    elif opts['exact']:
+        # Nothing to do; "revs" is already set correctly
+        pass
+    else:
+        raise error.Abort(_('must specify either --from or --exact'))
 
     if len(revs) == 1:
         ui.write_err(_('single revision specified, nothing to fold\n'))
diff -r 3e270ed7ede0 -r 80a3dc2541cf tests/test-evolve.t
--- a/tests/test-evolve.t	Thu Jan 05 01:36:37 2017 -0800
+++ b/tests/test-evolve.t	Thu Jan 12 13:47:49 2017 -0800
@@ -679,7 +679,13 @@ 
   $ hg fold
   abort: no revisions specified
   [255]
-  $ hg fold .
+  $ hg fold --from
+  abort: no revisions specified
+  [255]
+  $ hg fold --from . --exact
+  abort: cannot use both --from and --exact
+  [255]
+  $ hg fold --from .
   single revision specified, nothing to fold
   [1]
   $ hg fold 0::10 --rev 1 --exact
@@ -688,18 +694,18 @@ 
   $ hg fold -r 4 -r 6 --exact
   abort: cannot fold non-linear revisions (multiple roots given)
   [255]
-  $ hg fold 10 1
+  $ hg fold --from 10 1
   abort: cannot fold non-linear revisions
   (given revisions are unrelated to parent of working directory)
   [255]
   $ hg phase --public 0
-  $ hg fold -r 0
+  $ hg fold --from -r 0
   abort: cannot fold public revisions
   [255]
-  $ hg fold -r 5
+  $ hg fold --from -r 5
   3 changesets folded
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  $ hg fold 6 # want to run hg fold 6
+  $ hg fold --from 6 # want to run hg fold 6
   abort: hidden revision '6'!
   (use --hidden to access hidden revisions)
   [255]
@@ -806,7 +812,7 @@ 
 Test fold with commit messages
 
   $ cd ../work
-  $ hg fold .^ --message "Folding with custom commit message"
+  $ hg fold --from .^ --message "Folding with custom commit message"
   2 changesets folded
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ glog
@@ -825,7 +831,7 @@ 
   >                   commit message
   > EOF
 
-  $ hg fold .^ --logfile commit-message
+  $ hg fold --from .^ --logfile commit-message
   2 changesets folded
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg qlog
diff -r 3e270ed7ede0 -r 80a3dc2541cf tests/test-tutorial.t
--- a/tests/test-tutorial.t	Thu Jan 05 01:36:37 2017 -0800
+++ b/tests/test-tutorial.t	Thu Jan 12 13:47:49 2017 -0800
@@ -480,17 +480,18 @@ 
   
   fold multiple revisions into a single one
   
-      By default, folds all the revisions linearly between the given revisions
+      With --from, folds all the revisions linearly between the given revisions
       and the parent of the working directory.
   
-      Use --exact for folding only the specified revisions while ignoring the
-      parent of the working directory. In this case, the given revisions must
-      form a linear unbroken chain.
+      With --exact, folds only the specified revisions while ignoring the parent
+      of the working directory. In this case, the given revisions must form a
+      linear unbroken chain.
   
   options ([+] can be repeated):
   
    -r --rev VALUE [+] revision to fold
       --exact         only fold specified revisions
+      --from          fold revisions linearly to working copy parent
    -m --message TEXT  use text as commit message
    -l --logfile FILE  read commit message from file
    -d --date DATE     record the specified date as commit date
diff -r 3e270ed7ede0 -r 80a3dc2541cf tests/test-userguide.t
--- a/tests/test-userguide.t	Thu Jan 05 01:36:37 2017 -0800
+++ b/tests/test-userguide.t	Thu Jan 12 13:47:49 2017 -0800
@@ -109,7 +109,7 @@ 
   7:05e61aab8294  step 1
   8:be6d5bc8e4cc  step 2
   9:35f432d9f7c1  step 3
-  $ hg fold -d '0 0' -m 'fix bug 64' -r 7::
+  $ hg fold -d '0 0' -m 'fix bug 64' --from -r 7::
   3 changesets folded
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg --hidden shortlog -G -r 6::