Patchwork [V3] histedit: select the lowest rev when looking for a root in a revset

login
register
mail settings
Submitter David Soria Parra
Date March 19, 2014, 11:40 p.m.
Message ID <73106cb60a70b7a5f6f4.1395272421@dev544.prn1.facebook.com>
Download mbox | patch
Permalink /patch/4001/
State Accepted
Headers show

Comments

David Soria Parra - March 19, 2014, 11:40 p.m.
# HG changeset patch
# User David Soria Parra <davidsp@fb.com>
# Date 1394751906 25200
#      Thu Mar 13 16:05:06 2014 -0700
# Node ID 73106cb60a70b7a5f6f4ae537d6076ee1ff50709
# Parent  c152e538b85b099ce20b51104b8b7dd3666aad7c
histedit: select the lowest rev when looking for a root in a revset

When we specify a revision or a revset we just get the last element from the
list. For revsets this can lead to unintended effects where you specify a
revset like only() but instead histedit selects the highest revision in the
set as root. Therefore we should always use the lowest revision number as
root.
Augie Fackler - March 20, 2014, 2:05 p.m.
On Wed, Mar 19, 2014 at 04:40:21PM -0700, David Soria Parra wrote:
> # HG changeset patch
> # User David Soria Parra <davidsp@fb.com>
> # Date 1394751906 25200
> #      Thu Mar 13 16:05:06 2014 -0700
> # Node ID 73106cb60a70b7a5f6f4ae537d6076ee1ff50709
> # Parent  c152e538b85b099ce20b51104b8b7dd3666aad7c
> histedit: select the lowest rev when looking for a root in a revset

queued (with (bc) added), many thanks. I keep meaning to do this, but always forget when the moment is passed.

>
> When we specify a revision or a revset we just get the last element from the
> list. For revsets this can lead to unintended effects where you specify a
> revset like only() but instead histedit selects the highest revision in the
> set as root. Therefore we should always use the lowest revision number as
> root.
>
> diff --git a/hgext/histedit.py b/hgext/histedit.py
> --- a/hgext/histedit.py
> +++ b/hgext/histedit.py
> @@ -565,8 +565,11 @@
>                  remote = None
>              root = findoutgoing(ui, repo, remote, force, opts)
>          else:
> -            root = revs[0]
> -            root = scmutil.revsingle(repo, root).node()
> +            rootrevs = list(repo.set('roots(%lr)', revs))
> +            if len(rootrevs) != 1:
> +                raise util.Abort(_('The specified revisions must have ' +
> +                    'exactly one common root'))
> +            root = rootrevs[0].node()
>
>          keep = opts.get('keep', False)
>          revs = between(repo, root, topmost, keep)
> 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
> @@ -72,6 +72,26 @@
>    [255]
>    $ hg up --quiet
>
> +
> +Test that we pick the minimum of a revrange
> +---------------------------------------
> +
> +  $ HGEDITOR=cat hg histedit '2::' --commands - << EOF
> +  > pick eb57da33312f 2 three
> +  > pick c8e68270e35a 3 four
> +  > pick 08d98a8350f3 4 five
> +  > EOF
> +  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
> +  $ hg up --quiet
> +
> +  $ HGEDITOR=cat hg histedit 'tip:2' --commands - << EOF
> +  > pick eb57da33312f 2 three
> +  > pick c8e68270e35a 3 four
> +  > pick 08d98a8350f3 4 five
> +  > EOF
> +  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
> +  $ hg up --quiet
> +
>  Run on a revision not descendants of the initial parent
>  --------------------------------------------------------------------
>
> @@ -198,3 +218,12 @@
>    1 files updated, 0 files merged, 0 files removed, 0 files unresolved
>    0 files updated, 0 files merged, 0 files removed, 0 files unresolved
>    saved backup bundle to $TESTTMP/foo/.hg/strip-backup/*-backup.hg (glob)
> +
> +  $ hg update -q 2
> +  $ echo x > x
> +  $ hg add x
> +  $ hg commit -m'x' x
> +  created new head
> +  $ hg histedit -r 'heads(all())'
> +  abort: The specified revisions must have exactly one common root
> +  [255]
Sean Farley - March 20, 2014, 9:44 p.m.
Augie Fackler <raf@durin42.com> writes:

> On Wed, Mar 19, 2014 at 04:40:21PM -0700, David Soria Parra wrote:
>> # HG changeset patch
>> # User David Soria Parra <davidsp@fb.com>
>> # Date 1394751906 25200
>> #      Thu Mar 13 16:05:06 2014 -0700
>> # Node ID 73106cb60a70b7a5f6f4ae537d6076ee1ff50709
>> # Parent  c152e538b85b099ce20b51104b8b7dd3666aad7c
>> histedit: select the lowest rev when looking for a root in a revset
>
> queued (with (bc) added), many thanks. I keep meaning to do this, but always forget when the moment is passed.

Has this landed yet? I keep looking in crew to no avail.

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -565,8 +565,11 @@ 
                 remote = None
             root = findoutgoing(ui, repo, remote, force, opts)
         else:
-            root = revs[0]
-            root = scmutil.revsingle(repo, root).node()
+            rootrevs = list(repo.set('roots(%lr)', revs))
+            if len(rootrevs) != 1:
+                raise util.Abort(_('The specified revisions must have ' +
+                    'exactly one common root'))
+            root = rootrevs[0].node()
 
         keep = opts.get('keep', False)
         revs = between(repo, root, topmost, keep)
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
@@ -72,6 +72,26 @@ 
   [255]
   $ hg up --quiet
 
+
+Test that we pick the minimum of a revrange
+---------------------------------------
+
+  $ HGEDITOR=cat hg histedit '2::' --commands - << EOF
+  > pick eb57da33312f 2 three
+  > pick c8e68270e35a 3 four
+  > pick 08d98a8350f3 4 five
+  > EOF
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg up --quiet
+
+  $ HGEDITOR=cat hg histedit 'tip:2' --commands - << EOF
+  > pick eb57da33312f 2 three
+  > pick c8e68270e35a 3 four
+  > pick 08d98a8350f3 4 five
+  > EOF
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg up --quiet
+
 Run on a revision not descendants of the initial parent
 --------------------------------------------------------------------
 
@@ -198,3 +218,12 @@ 
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   saved backup bundle to $TESTTMP/foo/.hg/strip-backup/*-backup.hg (glob)
+
+  $ hg update -q 2
+  $ echo x > x
+  $ hg add x
+  $ hg commit -m'x' x
+  created new head
+  $ hg histedit -r 'heads(all())'
+  abort: The specified revisions must have exactly one common root
+  [255]