Patchwork revset: added _hexlist method to replace _list for %ln

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 27, 2014, 1:19 a.m.
Message ID <34bf12ea670796e0da95.1393463962@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3781/
State Accepted
Commit 0d4be103c7347623aa000d677d0d2ddc2967a807
Headers show

Comments

Lucas Moscovicz - Feb. 27, 2014, 1:19 a.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@fb.com>
# Date 1393463755 28800
#      Wed Feb 26 17:15:55 2014 -0800
# Node ID 34bf12ea670796e0da95f44bf4ef95c1e0da8fd2
# Parent  d9cf5e6843d7b15fe82ab0cd64a614489ff590da
revset: added _hexlist method to replace _list for %ln

Now %ln expression goes through _hexlist and doesn't do any unnecesary
processing anymore.
Matt Mackall - Feb. 27, 2014, 6:17 p.m.
On Wed, 2014-02-26 at 17:19 -0800, Lucas Moscovicz wrote:
> # HG changeset patch
> # User Lucas Moscovicz <lmoscovicz@fb.com>
> # Date 1393463755 28800
> #      Wed Feb 26 17:15:55 2014 -0800
> # Node ID 34bf12ea670796e0da95f44bf4ef95c1e0da8fd2
> # Parent  d9cf5e6843d7b15fe82ab0cd64a614489ff590da
> revset: added _hexlist method to replace _list for %ln
> 
> Now %ln expression goes through _hexlist and doesn't do any unnecesary
> processing anymore.

Queued for default, but you forgot to include your benchmarks.

You can still promote two scope lookups out of the inner loop.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1589,6 +1589,16 @@ 
     s = subset.set()
     return baseset([r for r in ls if r in s])
 
+# for internal use
+def _hexlist(repo, subset, x):
+    s = getstring(x, "internal error")
+    if not s:
+        return baseset([])
+    cl = repo.changelog
+    ls = [cl.rev(node.bin(r)) for r in s.split('\0')]
+    s = subset.set()
+    return baseset([r for r in ls if r in s])
+
 symbols = {
     "adds": adds,
     "all": getall,
@@ -1657,6 +1667,7 @@ 
     "unstable": unstable,
     "_list": _list,
     "_intlist": _intlist,
+    "_hexlist": _hexlist,
 }
 
 # symbols which can't be used for a DoS attack for any given input
@@ -1728,6 +1739,7 @@ 
     "unstable",
     "_list",
     "_intlist",
+    "_hexlist",
 ])
 
 methods = {
@@ -2038,7 +2050,7 @@ 
         elif t == 's':
             return "_list('%s')" % "\0".join(s)
         elif t == 'n':
-            return "_list('%s')" % "\0".join(node.hex(a) for a in s)
+            return "_hexlist('%s')" % "\0".join(node.hex(a) for a in s)
         elif t == 'b':
             return "_list('%s')" % "\0".join(a.branch() for a in s)