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

login
register
mail settings
Submitter timeless@mozdev.org
Date Jan. 10, 2016, 7:01 p.m.
Message ID <3f7fc942c59484f747ba.1452452483@waste.org>
Download mbox | patch
Permalink /patch/12639/
State Accepted
Headers show

Comments

timeless@mozdev.org - Jan. 10, 2016, 7:01 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1450856256 0
#      Wed Dec 23 07:37:36 2015 +0000
# Node ID 3f7fc942c59484f747bae8ab13714eeab210896a
# Parent  1532327bebd926fa7ade9c84da7392ca08777ec7
histedit: automatically select root with --commands
Augie Fackler - Jan. 12, 2016, 3:06 a.m.
On Sun, Jan 10, 2016 at 01:01:23PM -0600, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1450856256 0
> #      Wed Dec 23 07:37:36 2015 +0000
> # Node ID 3f7fc942c59484f747bae8ab13714eeab210896a
> # Parent  1532327bebd926fa7ade9c84da7392ca08777ec7
> histedit: automatically select root with --commands

I've queued the first three, but I'm really not happy with this
idea. It feels extremely magical, and if ever combined with
delete-implies-drop behavior it's a footgun waiting to happen.

>
> diff --git a/hgext/histedit.py b/hgext/histedit.py
> --- a/hgext/histedit.py
> +++ b/hgext/histedit.py
> @@ -867,7 +867,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
>
> @@ -894,6 +894,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
> @@ -988,6 +991,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'))
> @@ -1131,6 +1135,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
>          warnverifyactions(ui, repo, 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
> @@ -101,6 +101,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
> +  hg: parse error: 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
>  -----------------------------
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -867,7 +867,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
 
@@ -894,6 +894,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
@@ -988,6 +991,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'))
@@ -1131,6 +1135,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
         warnverifyactions(ui, repo, 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
@@ -101,6 +101,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
+  hg: parse error: 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
 -----------------------------