comparison mercurial/revset.py @ 16417:b4b0c6931e11

revset: avoid demandimport bug Apparently the "import x as xy" doesn't manage to update xy in the current scope's dictionary after load, which causes nodemod.nullrev to do a huge amount of demandload magic in the inner loop.
author Matt Mackall <mpm@selenic.com>
date Fri, 13 Apr 2012 15:32:49 -0500
parents a232a1b5ae9b
children 432f198600c6
comparison
equal deleted inserted replaced
16415:a232a1b5ae9b 16417:b4b0c6931e11
5 # This software may be used and distributed according to the terms of the 5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version. 6 # GNU General Public License version 2 or any later version.
7 7
8 import re 8 import re
9 import parser, util, error, discovery, hbisect, phases 9 import parser, util, error, discovery, hbisect, phases
10 import node as nodemod 10 import node
11 import bookmarks as bookmarksmod 11 import bookmarks as bookmarksmod
12 import match as matchmod 12 import match as matchmod
13 from i18n import _ 13 from i18n import _
14 import encoding 14 import encoding
15 15
16 def _revancestors(repo, revs, followfirst): 16 def _revancestors(repo, revs, followfirst):
17 """Like revlog.ancestors(), but supports followfirst.""" 17 """Like revlog.ancestors(), but supports followfirst."""
18 cut = followfirst and 1 or None 18 cut = followfirst and 1 or None
19 cl = repo.changelog 19 cl = repo.changelog
20 visit = list(revs) 20 visit = list(revs)
21 seen = set([nodemod.nullrev]) 21 seen = set([node.nullrev])
22 while visit: 22 while visit:
23 for parent in cl.parentrevs(visit.pop(0))[:cut]: 23 for parent in cl.parentrevs(visit.pop(0))[:cut]:
24 if parent not in seen: 24 if parent not in seen:
25 visit.append(parent) 25 visit.append(parent)
26 seen.add(parent) 26 seen.add(parent)
29 def _revdescendants(repo, revs, followfirst): 29 def _revdescendants(repo, revs, followfirst):
30 """Like revlog.descendants() but supports followfirst.""" 30 """Like revlog.descendants() but supports followfirst."""
31 cut = followfirst and 1 or None 31 cut = followfirst and 1 or None
32 cl = repo.changelog 32 cl = repo.changelog
33 first = min(revs) 33 first = min(revs)
34 if first == nodemod.nullrev: 34 nullrev = node.nullrev
35 if first == nullrev:
35 # Are there nodes with a null first parent and a non-null 36 # Are there nodes with a null first parent and a non-null
36 # second one? Maybe. Do we care? Probably not. 37 # second one? Maybe. Do we care? Probably not.
37 for i in cl: 38 for i in cl:
38 yield i 39 yield i
39 return 40 return
40 41
41 seen = set(revs) 42 seen = set(revs)
42 for i in xrange(first + 1, len(cl)): 43 for i in xrange(first + 1, len(cl)):
43 for x in cl.parentrevs(i)[:cut]: 44 for x in cl.parentrevs(i)[:cut]:
44 if x != nodemod.nullrev and x in seen: 45 if x != nullrev and x in seen:
45 seen.add(i) 46 seen.add(i)
46 yield i 47 yield i
47 break 48 break
48 49
49 elements = { 50 elements = {
722 """ 723 """
723 # i18n: "modifies" is a keyword 724 # i18n: "modifies" is a keyword
724 pat = getstring(x, _("modifies requires a pattern")) 725 pat = getstring(x, _("modifies requires a pattern"))
725 return checkstatus(repo, subset, pat, 0) 726 return checkstatus(repo, subset, pat, 0)
726 727
727 def node(repo, subset, x): 728 def node_(repo, subset, x):
728 """``id(string)`` 729 """``id(string)``
729 Revision non-ambiguously specified by the given hex string prefix. 730 Revision non-ambiguously specified by the given hex string prefix.
730 """ 731 """
731 # i18n: "id" is a keyword 732 # i18n: "id" is a keyword
732 l = getargs(x, 1, 1, _("id requires one argument")) 733 l = getargs(x, 1, 1, _("id requires one argument"))
1123 "follow": follow, 1124 "follow": follow,
1124 "_followfirst": _followfirst, 1125 "_followfirst": _followfirst,
1125 "grep": grep, 1126 "grep": grep,
1126 "head": head, 1127 "head": head,
1127 "heads": heads, 1128 "heads": heads,
1128 "id": node, 1129 "id": node_,
1129 "keyword": keyword, 1130 "keyword": keyword,
1130 "last": last, 1131 "last": last,
1131 "limit": limit, 1132 "limit": limit,
1132 "_matchfiles": _matchfiles, 1133 "_matchfiles": _matchfiles,
1133 "max": maxrev, 1134 "max": maxrev,
1397 return quote(arg) 1398 return quote(arg)
1398 elif c == 'r': 1399 elif c == 'r':
1399 parse(arg) # make sure syntax errors are confined 1400 parse(arg) # make sure syntax errors are confined
1400 return '(%s)' % arg 1401 return '(%s)' % arg
1401 elif c == 'n': 1402 elif c == 'n':
1402 return quote(nodemod.hex(arg)) 1403 return quote(node.hex(arg))
1403 elif c == 'b': 1404 elif c == 'b':
1404 return quote(arg.branch()) 1405 return quote(arg.branch())
1405 1406
1406 def listexp(s, t): 1407 def listexp(s, t):
1407 l = len(s) 1408 l = len(s)
1412 elif t == 'd': 1413 elif t == 'd':
1413 return "_list('%s')" % "\0".join(str(int(a)) for a in s) 1414 return "_list('%s')" % "\0".join(str(int(a)) for a in s)
1414 elif t == 's': 1415 elif t == 's':
1415 return "_list('%s')" % "\0".join(s) 1416 return "_list('%s')" % "\0".join(s)
1416 elif t == 'n': 1417 elif t == 'n':
1417 return "_list('%s')" % "\0".join(nodemod.hex(a) for a in s) 1418 return "_list('%s')" % "\0".join(node.hex(a) for a in s)
1418 elif t == 'b': 1419 elif t == 'b':
1419 return "_list('%s')" % "\0".join(a.branch() for a in s) 1420 return "_list('%s')" % "\0".join(a.branch() for a in s)
1420 1421
1421 m = l // 2 1422 m = l // 2
1422 return '(%s or %s)' % (listexp(s[:m], t), listexp(s[m:], t)) 1423 return '(%s or %s)' % (listexp(s[:m], t), listexp(s[m:], t))