Patchwork [4,of,4] revrange: drop old-style parser in favor of revset (API)

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 4, 2015, 3:10 p.m.
Message ID <046756d89df2cee3930d.1438701030@mimosa>
Download mbox | patch
Permalink /patch/10103/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 4, 2015, 3:10 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1422106094 -32400
#      Sat Jan 24 22:28:14 2015 +0900
# Node ID 046756d89df2cee3930d733469cc7fb4d7c546aa
# Parent  2fe6baa83605980bf2a57b1b0b7a5177b884c0f5
revrange: drop old-style parser in favor of revset (API)

Now revset can parse nullary ":" operator and existing "foo+bar" tags, we
don't need the old-style parser.

This means scmutil.revsingle(), revpair() and revrange() no longer accept
a binary nodeid. An integer revision is still allowed as it isn't ambiguous.
Pierre-Yves David - Aug. 5, 2015, 12:16 a.m.
On 08/04/2015 08:10 AM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1422106094 -32400
> #      Sat Jan 24 22:28:14 2015 +0900
> # Node ID 046756d89df2cee3930d733469cc7fb4d7c546aa
> # Parent  2fe6baa83605980bf2a57b1b0b7a5177b884c0f5
> revrange: drop old-style parser in favor of revset (API)

Some serious dragons slaying here.

+1 for forbiding binary node in revxxx familly of function.

Pushed to the clowncopter.

Patch

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -6,7 +6,7 @@ 
 # GNU General Public License version 2 or any later version.
 
 from i18n import _
-from mercurial.node import nullrev, wdirrev
+from mercurial.node import wdirrev
 import util, error, osutil, revset, similar, encoding, phases
 import pathutil
 import match as matchmod
@@ -720,54 +720,10 @@  def revpair(repo, revs):
 
 def revrange(repo, revs):
     """Yield revision as strings from a list of revision specifications."""
-
-    def revfix(repo, val, defval):
-        if not val and val != 0 and defval is not None:
-            return defval
-        return repo[val].rev()
-
     subsets = []
-
-    revsetaliases = [alias for (alias, _) in
-                     repo.ui.configitems("revsetalias")]
-
     for spec in revs:
-        # 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):
-                subsets.append(revset.baseset([spec]))
-                continue
-
-            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:
-                    start = nullrev
-                if start < end:
-                    l = revset.spanset(repo, start, end + 1)
-                else:
-                    l = revset.spanset(repo, start, end - 1)
-                subsets.append(l)
-                continue
-            elif spec and spec in repo: # single unquoted rev
-                rev = revfix(repo, spec, None)
-                subsets.append(revset.baseset([rev]))
-                continue
-        except error.RepoLookupError:
-            pass
-
-        # fall through to new-style queries if old-style fails
+        if isinstance(spec, int):
+            spec = revset.formatspec('rev(%d)', spec)
         m = revset.match(repo.ui, spec, repo)
         subsets.append(m(repo))