Mercurial > evolve
comparison hgext3rd/topic/stack.py @ 3123:237b39bf7e6b stable
topic: instroduce a fast path when computing stack
We do some stack related computation during transaction now. The current
inefficiency of the revset is hurting us too much. We pre-compute a subset using
native set operation to speed things up.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 23 Oct 2017 15:11:48 +0200 |
parents | 3eca2cbdc498 |
children | 28fb347a5bf8 |
comparison
equal
deleted
inserted
replaced
3115:663dbef40f97 | 3123:237b39bf7e6b |
---|---|
7 destutil, | 7 destutil, |
8 context, | 8 context, |
9 error, | 9 error, |
10 node, | 10 node, |
11 phases, | 11 phases, |
12 obsolete, | |
12 util, | 13 util, |
13 ) | 14 ) |
14 from .evolvebits import builddependencies, _singlesuccessor | 15 from .evolvebits import builddependencies, _singlesuccessor |
15 | 16 |
16 short = node.short | 17 short = node.short |
20 if not util.safehasattr(context.basectx, 'orphan'): | 21 if not util.safehasattr(context.basectx, 'orphan'): |
21 context.basectx.orphan = context.basectx.unstable | 22 context.basectx.orphan = context.basectx.unstable |
22 | 23 |
23 if not util.safehasattr(context.basectx, 'isunstable'): | 24 if not util.safehasattr(context.basectx, 'isunstable'): |
24 context.basectx.isunstable = context.basectx.troubled | 25 context.basectx.isunstable = context.basectx.troubled |
26 | |
27 def _stackcandidates(repo): | |
28 """build the smaller set of revs that might be part of a stack. | |
29 | |
30 The intend is to build something more efficient than what revsets do in | |
31 this area. | |
32 """ | |
33 phasecache = repo._phasecache | |
34 if not phasecache._phasesets: | |
35 return repo.revs('(not public()) - obsolete()') | |
36 if any(s is None for s in phasecache._phasesets): | |
37 return repo.revs('(not public()) - obsolete()') | |
38 | |
39 result = set() | |
40 for s in phasecache._phasesets[phases.draft:]: | |
41 result |= s | |
42 | |
43 result -= obsolete.getrevs(repo, 'obsolete') | |
44 return result | |
25 | 45 |
26 class stack(object): | 46 class stack(object): |
27 """object represent a stack and common logic associated to it.""" | 47 """object represent a stack and common logic associated to it.""" |
28 | 48 |
29 def __init__(self, repo, branch=None, topic=None): | 49 def __init__(self, repo, branch=None, topic=None): |
30 self._repo = repo | 50 self._repo = repo |
31 self.branch = branch | 51 self.branch = branch |
32 self.topic = topic | 52 self.topic = topic |
33 self.behinderror = None | 53 self.behinderror = None |
54 | |
55 subset = _stackcandidates(repo) | |
56 | |
34 if topic is not None and branch is not None: | 57 if topic is not None and branch is not None: |
35 raise error.ProgrammingError('both branch and topic specified (not defined yet)') | 58 raise error.ProgrammingError('both branch and topic specified (not defined yet)') |
36 elif topic is not None: | 59 elif topic is not None: |
37 trevs = repo.revs("not obsolete() and topic(%s)", topic) | 60 trevs = repo.revs("%ld and topic(%s)", subset, topic) |
38 elif branch is not None: | 61 elif branch is not None: |
39 trevs = repo.revs("not public() and branch(%s) - obsolete() - topic()", branch) | 62 trevs = repo.revs("%ld and branch(%s) - topic()", subset, branch) |
40 else: | 63 else: |
41 raise error.ProgrammingError('neither branch and topic specified (not defined yet)') | 64 raise error.ProgrammingError('neither branch and topic specified (not defined yet)') |
42 self._revs = trevs | 65 self._revs = trevs |
43 | 66 |
44 def __iter__(self): | 67 def __iter__(self): |