Mercurial > public > mercurial-scm > hg
comparison mercurial/localrepo.py @ 18121:f8a13f061a8a
branchmap: extract updatebranchcache from repo
author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
---|---|
date | Thu, 20 Dec 2012 14:45:17 +0100 |
parents | 88990d3e3d75 |
children | 6fb3b8c61775 |
comparison
equal
deleted
inserted
replaced
18120:88990d3e3d75 | 18121:f8a13f061a8a |
---|---|
660 better alternative. But we are using this approach until it is ready. | 660 better alternative. But we are using this approach until it is ready. |
661 """ | 661 """ |
662 cl = self.changelog | 662 cl = self.changelog |
663 return cl.rev(cl.tip()) | 663 return cl.rev(cl.tip()) |
664 | 664 |
665 @unfilteredmethod # Until we get a smarter cache management | |
666 def updatebranchcache(self): | |
667 cl = self.changelog | |
668 tip = cl.tip() | |
669 if self._branchcache is not None and self._branchcachetip == tip: | |
670 return | |
671 | |
672 oldtip = self._branchcachetip | |
673 if oldtip is None or oldtip not in cl.nodemap: | |
674 partial, last, lrev = branchmap.read(self) | |
675 else: | |
676 lrev = cl.rev(oldtip) | |
677 partial = self._branchcache | |
678 | |
679 catip = self._cacheabletip() | |
680 # if lrev == catip: cache is already up to date | |
681 # if lrev > catip: we have uncachable element in `partial` can't write | |
682 # on disk | |
683 if lrev < catip: | |
684 ctxgen = (self[r] for r in cl.revs(lrev + 1, catip)) | |
685 branchmap.update(self, partial, ctxgen) | |
686 branchmap.write(self, partial, cl.node(catip), catip) | |
687 lrev = catip | |
688 # If cacheable tip were lower than actual tip, we need to update the | |
689 # cache up to tip. This update (from cacheable to actual tip) is not | |
690 # written to disk since it's not cacheable. | |
691 tiprev = len(self) - 1 | |
692 if lrev < tiprev: | |
693 ctxgen = (self[r] for r in cl.revs(lrev + 1, tiprev)) | |
694 branchmap.update(self, partial, ctxgen) | |
695 self._branchcache = partial | |
696 self._branchcachetip = tip | |
697 | |
698 def branchmap(self): | 665 def branchmap(self): |
699 '''returns a dictionary {branch: [branchheads]}''' | 666 '''returns a dictionary {branch: [branchheads]}''' |
700 if self.changelog.filteredrevs: | 667 if self.changelog.filteredrevs: |
701 # some changeset are excluded we can't use the cache | 668 # some changeset are excluded we can't use the cache |
702 bmap = {} | 669 bmap = {} |
703 branchmap.update(self, bmap, (self[r] for r in self)) | 670 branchmap.update(self, bmap, (self[r] for r in self)) |
704 return bmap | 671 return bmap |
705 else: | 672 else: |
706 self.updatebranchcache() | 673 branchmap.updatecache(self) |
707 return self._branchcache | 674 return self._branchcache |
708 | 675 |
709 | 676 |
710 def _branchtip(self, heads): | 677 def _branchtip(self, heads): |
711 '''return the tipmost branch head in heads''' | 678 '''return the tipmost branch head in heads''' |
1444 # be compliant anyway | 1411 # be compliant anyway |
1445 # | 1412 # |
1446 # if minimal phase was 0 we don't need to retract anything | 1413 # if minimal phase was 0 we don't need to retract anything |
1447 phases.retractboundary(self, targetphase, [n]) | 1414 phases.retractboundary(self, targetphase, [n]) |
1448 tr.close() | 1415 tr.close() |
1449 self.updatebranchcache() | 1416 branchmap.updatecache(self) |
1450 return n | 1417 return n |
1451 finally: | 1418 finally: |
1452 if tr: | 1419 if tr: |
1453 tr.release() | 1420 tr.release() |
1454 lock.release() | 1421 lock.release() |
2429 cl.finalize(trp) | 2396 cl.finalize(trp) |
2430 | 2397 |
2431 tr.close() | 2398 tr.close() |
2432 | 2399 |
2433 if changesets > 0: | 2400 if changesets > 0: |
2434 self.updatebranchcache() | 2401 branchmap.updatecache(self) |
2435 def runhooks(): | 2402 def runhooks(): |
2436 # forcefully update the on-disk branch cache | 2403 # forcefully update the on-disk branch cache |
2437 self.ui.debug("updating the branch cache\n") | 2404 self.ui.debug("updating the branch cache\n") |
2438 self.hook("changegroup", node=hex(cl.node(clstart)), | 2405 self.hook("changegroup", node=hex(cl.node(clstart)), |
2439 source=srctype, url=url) | 2406 source=srctype, url=url) |