[PATCH evolve-ext] fold: add argument to handle ambiguous case

Laurent Charignon lcharignon at fb.com
Thu May 28 16:01:57 CDT 2015


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1432845532 25200
#      Thu May 28 13:38:52 2015 -0700
# Node ID 0821817a84792210498107777181dcc9f1d68ec7
# Parent  69e5de3e6129185469c2cbf98383ac6d58260d0c
fold: add argument to handle ambiguous case

Before this patch, when a user was using fold for the first times he could
think that --exact is the default behavior and make a mistake.
For example hg fold -r 12+13 won't just fold revision 12 and 13 together but
12, 13 and the linear chain of revision upto the working directory's parent.

This patch introduces a new option when the selection is ambiguous: when the
user specified two or more revisions not including the working copy's parent
without using --exact flag.
When the user is giving only one revision we assume that the intent of the user
is clearly to fold the chain from that revision up to the working directory's
parent. Example of change assuming that we have a linear history from rev 1 to
10 and the working copy parent is 10:

hg fold 9 # will fold 9 and 10 together, unchanged

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

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

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

hg fold 7:: # fold 7,8,9,10 it is not ambiguous as 10 is in the set

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

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")),
+     ('', 'chain', None, _('fold the chain of revisions between the given '
+                           'revisions and the parent of the working copy')),
     ] + commitopts + commitopts2,
     _('hg fold [OPTION]... [-r] REV'))
 def fold(ui, repo, *revs, **opts):
@@ -2308,6 +2310,14 @@
     revs = scmutil.revrange(repo, revs)
 
     if not opts['exact']:
+        if len(revs) > 1 and not opts['chain'] and not repo['.'].rev() in revs:
+            ui.write_err(_('multiple revisions specified not including the'
+            ' parent of the working.\n'
+            'Please use one of:\n'
+            '   --exact to fold exactly these revisions\n'
+            '   --chain to fold the chain from these revisions upto the parent'
+            'of the working copy\n'))
+            return 1
         # 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,14 @@
   $ 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'
+  multiple revisions specified not including the parent of the working.
+  Please use one of:
+     --exact to fold exactly these revisions
+     --chain to fold the chain from these revisions upto the parentof the working copy
+  [1]
+  $ hg fold 10 1 --chain
   abort: cannot fold non-linear revisions
   (given revisions are unrelated to parent of working directory)
   [255]
@@ -642,14 +649,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 +676,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 at default(draft) add 4
+  @  13:d26d339c513f at default(draft) add 4
   |
   | o  1:73d38bb17fd7 at default(draft) add 1
   |/
   o  0:8685c6d34325 at 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 +708,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 +753,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
+      --chain         fold the chain of revisions between the given revisions
+                      and 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


More information about the Mercurial-devel mailing list