fileset, revset: do not use global parser object for thread safety stable
authorYuya Nishihara <yuya@tcha.org>
Sat, 21 Dec 2013 12:44:19 +0900
branchstable
changeset 20208 61a47fd64f30
parent 20168 d4be314b2071
child 20209 174d9b8baf5d
child 20211 ca387377df7a
fileset, revset: do not use global parser object for thread safety parse() cannot be called at the same time because a parser object keeps its states. This is no problem for command-line hg client, but it would cause strange errors in multi-threaded hgweb. Creating parser object is not too expensive. original: % python -m timeit -s 'from mercurial import revset' 'revset.parse("0::tip")' 100000 loops, best of 3: 11.3 usec per loop thread-safe: % python -m timeit -s 'from mercurial import revset' 'revset.parse("0::tip")' 100000 loops, best of 3: 13.1 usec per loop
mercurial/fileset.py
mercurial/revset.py
--- a/mercurial/fileset.py	Wed Dec 04 13:42:28 2013 -0600
+++ b/mercurial/fileset.py	Sat Dec 21 12:44:19 2013 +0900
@@ -78,7 +78,9 @@
         pos += 1
     yield ('end', None, pos)
 
-parse = parser.parser(tokenize, elements).parse
+def parse(expr):
+    p = parser.parser(tokenize, elements)
+    return p.parse(expr)
 
 def getstring(x, err):
     if x and (x[0] == 'string' or x[0] == 'symbol'):
--- a/mercurial/revset.py	Wed Dec 04 13:42:28 2013 -0600
+++ b/mercurial/revset.py	Sat Dec 21 12:44:19 2013 +0900
@@ -1880,7 +1880,9 @@
         aliases[alias.name] = alias
     return _expandaliases(aliases, tree, [], {})
 
-parse = parser.parser(tokenize, elements).parse
+def parse(spec):
+    p = parser.parser(tokenize, elements)
+    return p.parse(spec)
 
 def match(ui, spec):
     if not spec: