# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1424905921 18000 # Node ID c4e3e7b031b741d74e1b9316a6ec6512d2c25037 # Parent bd9f64ec891d926abf7bdfc1b4430106f1f11090 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. diff -r bd9f64ec891d -r c4e3e7b031b7 mercurial/scmutil.py --- a/mercurial/scmutil.py Tue Feb 24 08:49:22 2015 +0100 +++ b/mercurial/scmutil.py Wed Feb 25 18:12:01 2015 -0500 @@ -628,12 +628,22 @@ return repo[val].rev() seen, l = set(), revset.baseset([]) + + revsetaliases = [alias for (alias, _) in + repo.ui.configitems("revsetalias")] + for spec in revs: if l and not seen: seen = set(l) # 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]) @@ -641,6 +651,9 @@ if _revrangesep in spec: start, end = spec.split(_revrangesep, 1) + if start in revsetaliases or end in revsetaliases: + raise error.RepoLookupError + start = revfix(repo, start, 0) end = revfix(repo, end, len(repo) - 1) if end == nullrev and start < 0: diff -r bd9f64ec891d -r c4e3e7b031b7 tests/test-revset.t --- a/tests/test-revset.t Tue Feb 24 08:49:22 2015 +0100 +++ b/tests/test-revset.t Wed Feb 25 18:12:01 2015 -0500 @@ -1127,6 +1127,62 @@ 3 2 +issue4553: check that revset aliases override existing hash prefix + + $ hg log -qr e + 6:e0cc66ef77e8 + + $ 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: --config revsetalias.e="0" + 0:2785f51eece5 + 1:d75937da8da0 + 2:5ed5505e9f1c + 3:8528aa5637f2 + 4:2326846efdab + 5:904fa392b941 + 6:e0cc66ef77e8 + 7:013af1973af4 + 8:d5d0dcbdc4d9 + 9:24286f4ae135 + + $ hg log -qr :e --config revsetalias.e="9" + 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 + 7:013af1973af4 + 8:d5d0dcbdc4d9 + 9:24286f4ae135 + + $ hg log -qr :e + 0:2785f51eece5 + 1:d75937da8da0 + 2:5ed5505e9f1c + 3:8528aa5637f2 + 4:2326846efdab + 5:904fa392b941 + 6:e0cc66ef77e8 + issue2549 - correct optimizations $ log 'limit(1 or 2 or 3, 2) and not 2'