Patchwork [7,of,7] histedit: automatically select root with --commands

login
register
mail settings
Submitter timeless@mozdev.org
Date Dec. 23, 2015, 9:06 a.m.
Message ID <1e0690dcbb9704f28329.1450861606@waste.org>
Download mbox | patch
Permalink /patch/12285/
State Superseded
Headers show

Comments

timeless@mozdev.org - Dec. 23, 2015, 9:06 a.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1450856256 0
#      Wed Dec 23 07:37:36 2015 +0000
# Node ID 1e0690dcbb9704f283293a10ce16e2dc91388959
# Parent  6832335c22e1c4861fc8911e21bf56a8915e9395
histedit: automatically select root with --commands

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -807,7 +807,7 @@ 
      ('f', 'force', False,
       _('force outgoing even for unrelated repositories')),
      ('r', 'rev', [], _('first revision to be edited'), _('REV'))],
-     _("[OPTIONS] ([ANCESTOR] | --outgoing [URL])"))
+     _("[OPTIONS] ([ANCESTOR] | --outgoing [URL] | --commands FILE)"))
 def histedit(ui, repo, *freeargs, **opts):
     """interactively edit changeset history
 
@@ -834,6 +834,9 @@ 
     - Use --outgoing -- it will be the first linear changeset not
       included in destination. (See :hg:"help default-push")
 
+    - Use --commands -- it will be the first linear changeset from the
+      specified changesets.
+
     - Otherwise, the value from the "histedit.defaultrev" config option
       is used as a revset to select the base revision when ANCESTOR is not
       specified. The first revision returned by the revset is used. By
@@ -933,6 +936,7 @@ 
     force = opts.get('force')
     rules = opts.get('commands', '')
     revs = opts.get('rev', [])
+    hasrevs = any(revs)
     goal = 'new' # This invocation goal, in new, continue, abort
     if force and not outg:
         raise error.Abort(_('--force only allowed with --outgoing'))
@@ -1078,6 +1082,19 @@ 
             rules = f.read()
             f.close()
         actions = parserules(rules, state)
+        if not any((outg, hasrevs)) and opts.get('commands', ''):
+            try:
+                avail = scmutil.revrange(repo,
+                            [node.hex(a.node) for a in actions])
+                rr = list(repo.set('roots(%ld)', avail))
+                if len(rr) == 1:
+                    root = rr[0].node()
+                    revs = between(repo, root, topmost, state.keep)
+                    ctxs = [repo[r] for r in revs]
+            except error.RepoLookupError:
+                pass
+            except error.Abort:
+                pass
         verifyactions(actions, state, ctxs)
 
         parentctxnode = repo[root].parents()[0].node()
diff --git a/tests/test-histedit-arguments.t b/tests/test-histedit-arguments.t
--- a/tests/test-histedit-arguments.t
+++ b/tests/test-histedit-arguments.t
@@ -100,6 +100,24 @@ 
   > EOF
   $ hg up --quiet
 
+Test implicit minimum version via --commands
+---------------------------------------
+
+  $ HGEDITOR=cat hg histedit --commands - << EOF
+  > pick c8e68270e35a 3 four
+  > pick 08d98a8350f3 4 five
+  > EOF
+  $ hg up --quiet
+
+  $ HGEDITOR=cat hg histedit --commands - << EOF
+  > pick eb57da33312f 2 three
+  > pick 08d98a8350f3 4 five
+  > EOF
+  abort: missing rules for changeset 579e40513370
+  (use "drop 579e40513370" to discard, see also: "hg help -e histedit.config")
+  [255]
+  $ hg up --quiet
+
 Test config specified default
 -----------------------------
 
diff --git a/tests/test-histedit-commute.t b/tests/test-histedit-commute.t
--- a/tests/test-histedit-commute.t
+++ b/tests/test-histedit-commute.t
@@ -268,7 +268,8 @@ 
   > pick de71b079d9ce e
   > pick 38b92f448761 c
   > EOF
-  abort: may not use "pick" with changesets other than the ones listed
+  abort: pick "646537316230" changeset was not a candidate
+  (only use listed changesets)
   $ hg log --graph
   @  changeset:   7:803ef1c6fcfd
   |  tag:         tip