Patchwork [EVOLVE] fold: rehaul handling of multiple and single revisions (BC)

login
register
mail settings
Submitter Jordi Gutiérrez Hermoso
Date June 26, 2014, 4:56 p.m.
Message ID <106715812d083bfbf53c.1403801801@Iris>
Download mbox | patch
Permalink /patch/5070/
State Not Applicable
Headers show

Comments

Jordi Gutiérrez Hermoso - June 26, 2014, 4:56 p.m.
# HG changeset patch
# User Jordi Gutiérrez Hermoso <jordigh@octave.org>
# Date 1397267702 14400
#      Fri Apr 11 21:55:02 2014 -0400
# Node ID 106715812d083bfbf53cd2ca834e7cf1d39cfc6a
# Parent  404a000bb38b0139ad93feb4327a5f2d1ea8c0f8
fold: rehaul handling of multiple and single revisions (BC)

The fold command parsed the revision arguments in a very peculiar and
idiosyncratic fashion: either a single revision could be specified or
multiple revisions could be specified with --rev (but not both). This
is inconsistent with the way all other hg commands parse revision
arguments. We have several examples of command where several revisions
are passed, and the --rev option is optional for specifying those
revisions (update, strip, export).

This patch alters the way in which fold parses its revision arguments.
No distinction is made between revisions passed with or without the
--rev argument. Whether a single or multiple revision is specified, it
will all be folded together into one, by connecting them to the parent
of the working directory. If the --exact argument is passed, then the
parent of the working directory is ignored and the specified revisions
must be a single contiguous line.

The docstring and error messages are modified accordingly, as well as
the tests.

Patch

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -2074,41 +2074,58 @@  def touch(ui, repo, *revs, **opts):
         lockmod.release(lock, wlock)
 
 @command('^fold|squash',
-    [('r', 'rev', [], _("explicitly specify the full set of revision to fold")),
+    [('r', 'rev', [], _("revision to fold")),
+     ('', 'exact', None, _("ignore parent of working directory"))
     ] + commitopts + commitopts2,
-    # allow to choose the seed ?
-    _('rev'))
+    _('hg fold [OPTION]... [-r] REV'))
 def fold(ui, repo, *revs, **opts):
-    """Fold multiple revisions into a single one
+    """fold multiple revisions into a single one
 
-    The revisions from your current working directory to the given one are folded
-    into a single successor revision.
+    Folds all revisions between the specified revision and the parent
+    of working directory into a single revision. The folded revisions
+    will be marked as obsolete and replaced by the resulting revision.
 
-    you can alternatively use --rev to explicitly specify revisions to be folded,
-    ignoring the current working directory parent.
+    If multiple revisions are specified, they will all be folded
+    together with the parent of the working directory, along with any
+    intermediate revisions.
+
+    If specifying multiple revisions, use --exact for folding those
+    revisions while ignoring the parent of the working directory. In
+    this case, the given revisions must form a linear unbroken chain.
     """
     revs = list(revs)
-    if revs:
-        if opts.get('rev', ()):
-            raise util.Abort("cannot specify both --rev and a target revision")
-        targets = scmutil.revrange(repo, revs)
-        revs = repo.revs('(%ld::.) or (.::%ld)', targets, targets)
-    elif 'rev' in opts:
-        revs = scmutil.revrange(repo, opts['rev'])
-    else:
-        revs = ()
+    revs.extend(opts['rev'])
     if not revs:
-        ui.write_err('no revision to fold\n')
+        ui.write_err(_('no revisions specified\n'))
         return 1
+
+    revs = scmutil.revrange(repo, revs)
+
+    if not opts['exact']:
+        # 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]
+        if discardedrevs:
+            raise util.Abort(_("cannot fold non-linear revisions"),
+                               hint=_("given revisions are unrelated to parent "
+                                      "of working directory"))
+        revs = extrevs
+
+    if len(revs) == 1:
+        ui.write_err(_('single revision specified, nothing to fold\n'))
+        return 2
+
     roots = repo.revs('roots(%ld)', revs)
     if len(roots) > 1:
-        raise util.Abort("set has multiple roots")
+        raise util.Abort(_("cannot fold non-linear revisions"),
+                           hint=_("multiple roots detected"))
     root = repo[roots[0]]
     if root.phase() <= phases.public:
-        raise util.Abort("can't fold public revisions")
+        raise util.Abort(_("cannot fold public revisions"))
     heads = repo.revs('heads(%ld)', revs)
     if len(heads) > 1:
-        raise util.Abort("set has multiple heads")
+        raise util.Abort(_("cannot fold non-linear revisions"),
+                           hint=_("multiple heads detected"))
     head = repo[heads[0]]
     wlock = lock = None
     try:
@@ -2129,9 +2146,9 @@  def fold(ui, repo, *revs, **opts):
                 commitopts['message'] =  "\n".join(msgs)
                 commitopts['edit'] = True
 
-            newid, _ = rewrite(repo, root, allctx, head,
-                             [root.p1().node(), root.p2().node()],
-                             commitopts=commitopts)
+            newid, unusedvariable = rewrite(repo, root, allctx, head,
+                                            [root.p1().node(), root.p2().node()],
+                                            commitopts=commitopts)
             phases.retractboundary(repo, targetphase, [newid])
             createmarkers(repo, [(ctx, (repo[newid],))
                                  for ctx in allctx])
diff --git a/tests/test-evolve.t b/tests/test-evolve.t
--- a/tests/test-evolve.t
+++ b/tests/test-evolve.t
@@ -614,26 +614,30 @@  Test fold
 
   $ rm *.orig
   $ hg fold
-  no revision to fold
+  no revisions specified
   [1]
-  $ hg fold 6 --rev 10
-  abort: cannot specify both --rev and a target revision
+  $ hg fold 0::10 --rev 1 --exact
+  abort: cannot fold non-linear revisions
+  (multiple heads detected)
   [255]
+  $ hg fold -r 4 -r 6 --exact
+  abort: cannot fold non-linear revisions
+  (multiple roots detected)
+  [255]
+  $ hg fold 10 1
+  abort: cannot fold non-linear revisions
+  (given revisions are unrelated to parent of working directory)
+  [255]
+  $ hg fold -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
-  2 changesets folded
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  $ glog
-  @  11:dd4682c1a481@default(draft) add 1
-  |
-  o  5:0b9e50c35132@default(draft) add 3
-  |
-  o  4:ce341209337f@default(draft) add 4
-  |
-  | o  1:73d38bb17fd7@default(draft) add 1
-  |/
-  o  0:8685c6d34325@default(draft) add 0
+  abort: unknown revision '6'!
+  [255]
+  $ hg log -r 11 --template '{desc}\n'
+  add 3
   
-  $ hg log -r 11 --template '{desc}\n'
+  
   add 1
   
   
@@ -645,8 +649,8 @@  Test fold with wc parent is not the head
 
   $ hg up 4
   0 files updated, 0 files merged, 2 files removed, 0 files unresolved
-  $ hg fold --rev 4::11 --user victor
-  3 changesets folded
+  $ hg fold --rev 4::11 --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
@@ -677,8 +681,7 @@  Test olog
 
   $ hg olog
   4	: add 4 - test
-  5	: add 3 - test
-  11	: add 1 - test
+  11	: add 3 - test
 
 Test obsstore stat