Patchwork revrange: don't parse revset aliases as hash prefixes (issue4553)

login
register
mail settings
Submitter Jordi Gutiérrez Hermoso
Date Feb. 25, 2015, 11:16 p.m.
Message ID <f003009faca138e394ef.1424906198@Iris>
Download mbox | patch
Permalink /patch/7831/
State Superseded
Headers show

Comments

Jordi Gutiérrez Hermoso - Feb. 25, 2015, 11:16 p.m.
# HG changeset patch
# User Jordi Gutiérrez Hermoso <jordigh@octave.org>
# Date 1424905921 18000
#      Wed Feb 25 18:12:01 2015 -0500
# Node ID f003009faca138e394efcfd675f601a4db58b1ef
# Parent  f15891e7f658fbc0351589887760548cab2c41f8
revrange: don't parse revset aliases as hash prefixes (issue4553)

If a user has a revsetalias defined, it is their explicit wish for
this alias to be parsed as a revset and nothing else. Although the
case of the alias being short enough and only contain the letters a-f
is probably kind of rare, it may still happen.
Jordi Gutiérrez Hermoso - Feb. 25, 2015, 11:20 p.m.
On Wed, 2015-02-25 at 18:16 -0500, Jordi Gutiérrez Hermoso wrote:
> # Parent  f15891e7f658fbc0351589887760548cab2c41f8
> revrange: don't parse revset aliases as hash prefixes (issue4553)
[snip]
> diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
> --- a/mercurial/scmutil.py
> +++ b/mercurial/scmutil.py
> @@ -631,9 +631,19 @@ def revrange(repo, revs):
>      for spec in revs:
>          if l and not seen:
>              seen = set(l)
> +
> +        revsetaliases = [alias for (alias, _) in
> +                         repo.ui.configitems("revsetalias")]
> +

Oops, I meant to define this outside the loop. V2 in a few minutes...

Patch

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -631,9 +631,19 @@  def revrange(repo, revs):
     for spec in revs:
         if l and not seen:
             seen = set(l)
+
+        revsetaliases = [alias for (alias, _) in
+                         repo.ui.configitems("revsetalias")]
+
         # attempt to parse old-style ranges first to deal with
         # things like old-tag which contain query metacharacters
         try:
+            # ... except for revset aliases without arguments. These
+            # should be parsed as soon as possible, because they might
+            # clash with a hash prefix.
+            if spec in revsetaliases:
+                raise error.RepoLookupError
+
             if isinstance(spec, int):
                 seen.add(spec)
                 l = l + revset.baseset([spec])
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -1128,6 +1128,22 @@  far away.
   3
   2
 
+issue4553: check that revset aliases override existing hash prefix
+
+  $ hg log -qr e --config revsetalias.e="all()"
+  0:2785f51eece5
+  1:d75937da8da0
+  2:5ed5505e9f1c
+  3:8528aa5637f2
+  4:2326846efdab
+  5:904fa392b941
+  6:e0cc66ef77e8
+  7:013af1973af4
+  8:d5d0dcbdc4d9
+  9:24286f4ae135
+  $ hg log -qr e
+  6:e0cc66ef77e8
+
 issue2549 - correct optimizations
 
   $ log 'limit(1 or 2 or 3, 2) and not 2'