comparison mercurial/localrepo.py @ 17012:ea97744c4801

localrepo: convert _updatebranchcache from nodespace to revspace _updatebranchcache used to use revlog.reachable. After the switch to revlog.ancestors, we can now clean it up a bit and switch the algorithm from nodes to revs.
author Joshua Redstone <joshua.redstone@fb.com>
date Fri, 01 Jun 2012 08:56:17 -0700
parents 0c18aed2fcca
children c8eda7bbdcab
comparison
equal deleted inserted replaced
17011:25f7d40fe735 17012:ea97744c4801
572 572
573 def _updatebranchcache(self, partial, ctxgen): 573 def _updatebranchcache(self, partial, ctxgen):
574 # collect new branch entries 574 # collect new branch entries
575 newbranches = {} 575 newbranches = {}
576 for c in ctxgen: 576 for c in ctxgen:
577 newbranches.setdefault(c.branch(), []).append(c.node()) 577 newbranches.setdefault(c.branch(), []).append(c.rev())
578 # if older branchheads are reachable from new ones, they aren't 578 # if older branchheads are reachable from new ones, they aren't
579 # really branchheads. Note checking parents is insufficient: 579 # really branchheads. Note checking parents is insufficient:
580 # 1 (branch a) -> 2 (branch b) -> 3 (branch a) 580 # 1 (branch a) -> 2 (branch b) -> 3 (branch a)
581 for branch, newnodes in newbranches.iteritems(): 581 for branch, newrevs in newbranches.iteritems():
582 bheads = partial.setdefault(branch, []) 582 bheadrevs = [self.changelog.rev(node) for node in
583 bheads.extend(newnodes) 583 partial.setdefault(branch, [])]
584 if len(bheads) <= 1: 584 bheadrevs.extend(newrevs)
585 continue 585 bheadrevs.sort()
586 bheads = sorted(bheads, key=lambda x: self[x].rev()) 586 # starting from tip means fewer passes over ancestors
587 # starting from tip means fewer passes over reachable 587 newrevs.sort()
588 while newnodes: 588 while newrevs:
589 latest = newnodes.pop() 589 latest = newrevs.pop()
590 if latest not in bheads: 590 if latest not in bheadrevs:
591 continue 591 continue
592 minbhnode = self[bheads[0]].node() 592 ancestors = set(self.changelog.ancestors([latest],
593 cl = self.changelog 593 bheadrevs[0]))
594 ancestors = cl.ancestors([cl.rev(latest)], 594 if ancestors:
595 cl.rev(minbhnode)) 595 bheadrevs = [b for b in bheadrevs if b not in ancestors]
596 reachable = [cl.node(rev) for rev in ancestors] 596 partial[branch] = [self.changelog.node(rev) for rev in bheadrevs]
597 if reachable:
598 bheads = [b for b in bheads if b not in reachable]
599 partial[branch] = bheads
600 597
601 def lookup(self, key): 598 def lookup(self, key):
602 return self[key].node() 599 return self[key].node()
603 600
604 def lookupbranch(self, key, remote=None): 601 def lookupbranch(self, key, remote=None):