Patchwork [V2] fold: add --upto argument to handle ambiguous case

login
register
mail settings
Submitter Laurent Charignon
Date June 3, 2015, 12:23 a.m.
Message ID <0ac75aa4eb2f31e8a534.1433291032@lcharignon-mbp.dhcp.thefacebook.com>
Download mbox | patch
Permalink /patch/9451/
State Changes Requested
Headers show

Comments

Laurent Charignon - June 3, 2015, 12:23 a.m.
# HG changeset patch
# User Laurent Charignon <lcharignon@fb.com>
# Date 1432845532 25200
#      Thu May 28 13:38:52 2015 -0700
# Node ID 0ac75aa4eb2f31e8a5347f7e5787a50adba38175
# Parent  69e5de3e6129185469c2cbf98383ac6d58260d0c
fold: add --upto argument to handle ambiguous case

Before this patch, consider the following example:
- Assuming repository with 5 revisions, linear from 1 to 5 and the parent of
the workdir is 5
- hg fold -r 2+3 doesn't just fold revision 2 and 3 together but 2,3,4,5
- Au contraire, hg fold --exact -r 2+3 folds 2 and 3 together
- This can be counterintuitive as fold by default folds more than what is
specified, it folds upto the parent of the working copy

The decision of making this the default behavior has been well thought before
(see b98dd5d3065c).

To solve the problem above, this patch introduces a new option when the
selection seem ambiguous: when the user specified two or more revisions not
including the working copy's parent without using --exact flag. In that case
we urge the urger to add --upto or --exact to choose what to do.

When the user is giving only one revision or when the working copy's parent is
in the list of revision specified, we assume that the intent of the user is clear
and that he does not mean --exact.

Example of change after the patch assuming that we have a linear history from
rev 1 to 10 and the working copy parent is 10:

hg fold 7 # will fold 7,8,9,10 together

hg fold 8 + 7 # before was folding 7,8,9,10, now prints an error

hg fold 7::9 # now prints an error and does not fold 7,8,9,10 anymore

hg fold 8 + 7 --exact # folds 7 and 8 together

hg fold 8 + 7 --chain # folds 7,8,9,10 together

hg fold 7:: # fold 7,8,9,10 it is not ambiguous as 10 is in 7::
Pierre-Yves David - June 9, 2015, 12:39 a.m.
On 06/02/2015 05:23 PM, Laurent Charignon wrote:
> # HG changeset patch
> # User Laurent Charignon <lcharignon@fb.com>
> # Date 1432845532 25200
> #      Thu May 28 13:38:52 2015 -0700
> # Node ID 0ac75aa4eb2f31e8a5347f7e5787a50adba38175
> # Parent  69e5de3e6129185469c2cbf98383ac6d58260d0c
> fold: add --upto argument to handle ambiguous case

I think we need some summary of the discussion in the EvolveUI page 
before being able to move forward here.

Patch

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -2263,7 +2263,9 @@ 
 
 @command('^fold|squash',
     [('r', 'rev', [], _("revision to fold")),
-     ('', 'exact', None, _("only fold specified revisions"))
+     ('', 'exact', None, _("only fold specified revisions")),
+     ('', 'upto', None, _("fold from specified revisions upto the parent of"\
+                            " the working copy")),
     ] + commitopts + commitopts2,
     _('hg fold [OPTION]... [-r] REV'))
 def fold(ui, repo, *revs, **opts):
@@ -2308,6 +2310,8 @@ 
     revs = scmutil.revrange(repo, revs)
 
     if not opts['exact']:
+        if len(revs) > 1 and not opts['upto'] and not repo['.'].rev() in revs:
+            raise util.Abort(_('ambiguous case, please use --exact or --upto'))
         # 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]
diff --git a/tests/test-evolve.t b/tests/test-evolve.t
--- a/tests/test-evolve.t
+++ b/tests/test-evolve.t
@@ -634,7 +634,11 @@ 
   $ hg fold -r 4 -r 6 --exact
   abort: cannot fold non-linear revisions (multiple roots given)
   [255]
-  $ hg fold 10 1
+Two revisions in the middle of the stack, ambiguous behavior
+  $ hg fold -r '4+5'
+  abort: ambiguous case, please use --exact or --upto
+  [255]
+  $ hg fold 10 1 --upto
   abort: cannot fold non-linear revisions
   (given revisions are unrelated to parent of working directory)
   [255]
@@ -642,14 +646,19 @@ 
   $ hg fold -r 0
   abort: cannot fold public revisions
   [255]
+
+Two revisions including the parent of the working copy
+  $ hg fold -r '6 + 10'
+  2 changesets folded
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg fold -r 5
-  3 changesets folded
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  2 changesets folded
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg fold 6 # want to run hg fold 6
   abort: hidden revision '6'!
   (use --hidden to access hidden revisions)
   [255]
-  $ hg log -r 11 --template '{desc}\n'
+  $ hg log -r 12 --template '{desc}\n'
   add 3
   
   
@@ -664,21 +673,21 @@ 
 
   $ hg up 4
   0 files updated, 0 files merged, 2 files removed, 0 files unresolved
-  $ hg fold --rev 4::11 --user victor --exact
+  $ hg fold --rev 4::12 --user victor --exact
   2 changesets folded
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ glog
-  @  12:d26d339c513f@default(draft) add 4
+  @  13:d26d339c513f@default(draft) add 4
   |
   | o  1:73d38bb17fd7@default(draft) add 1
   |/
   o  0:8685c6d34325@default(public) add 0
   
   $ hg log --template '{rev}: {author}\n'
-  12: victor
+  13: victor
   1: test
   0: test
-  $ hg log -r 12 --template '{desc}\n'
+  $ hg log -r 13 --template '{desc}\n'
   add 4
   
   
@@ -696,32 +705,32 @@ 
 
   $ hg olog
   4	: add 4 - test
-  11	: add 3 - test
+  12	: add 3 - test
 
 Test obsstore stat
 
   $ hg debugobsstorestat
-  markers total:                     10
-      for known precursors:          10
+  markers total:                     11
+      for known precursors:          11
       with parents data:              0
   markers with no successors:         0
-                1 successors:        10
+                1 successors:        11
                 2 successors:         0
       more than 2 successors:         0
       available  keys:
-                 user:               10
+                 user:               11
   disconnected clusters:              1
           any known node:             1
-          smallest length:           10
-          longer length:             10
-          median length:             10
-          mean length:               10
+          smallest length:           11
+          longer length:             11
+          median length:             11
+          mean length:               11
       using parents data:             1
           any known node:             1
-          smallest length:           10
-          longer length:             10
-          median length:             10
-          mean length:               10
+          smallest length:           11
+          longer length:             11
+          median length:             11
+          mean length:               11
 
 
 Test evolving renames
@@ -741,8 +750,8 @@ 
   1 changesets pruned
   1 new unstable changesets
   $ hg stab --any
-  move:[15] c
-  atop:[13] a
+  move:[16] c
+  atop:[14] a
   working directory is now at 3742bde73477
   $ hg st -C --change=tip
   A c
diff --git a/tests/test-tutorial.t b/tests/test-tutorial.t
--- a/tests/test-tutorial.t
+++ b/tests/test-tutorial.t
@@ -494,6 +494,8 @@ 
   
    -r --rev VALUE [+] revision to fold
       --exact         only fold specified revisions
+      --upto          fold from specified revisions upto the parent of the
+                      working copy
    -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