##// END OF EJS Templates
branchmap: extract updatebranchcache from repo
Pierre-Yves David -
r18121:f8a13f06 default
parent child Browse files
Show More
@@ -111,3 +111,35 b' def update(repo, partial, ctxgen):'
111 if not nodes:
111 if not nodes:
112 del partial[branch]
112 del partial[branch]
113
113
114 def updatecache(repo):
115 repo = repo.unfiltered() # Until we get a smarter cache management
116 cl = repo.changelog
117 tip = cl.tip()
118 if repo._branchcache is not None and repo._branchcachetip == tip:
119 return
120
121 oldtip = repo._branchcachetip
122 if oldtip is None or oldtip not in cl.nodemap:
123 partial, last, lrev = read(repo)
124 else:
125 lrev = cl.rev(oldtip)
126 partial = repo._branchcache
127
128 catip = repo._cacheabletip()
129 # if lrev == catip: cache is already up to date
130 # if lrev > catip: we have uncachable element in `partial` can't write
131 # on disk
132 if lrev < catip:
133 ctxgen = (repo[r] for r in cl.revs(lrev + 1, catip))
134 update(repo, partial, ctxgen)
135 write(repo, partial, cl.node(catip), catip)
136 lrev = catip
137 # If cacheable tip were lower than actual tip, we need to update the
138 # cache up to tip. This update (from cacheable to actual tip) is not
139 # written to disk since it's not cacheable.
140 tiprev = len(repo) - 1
141 if lrev < tiprev:
142 ctxgen = (repo[r] for r in cl.revs(lrev + 1, tiprev))
143 update(repo, partial, ctxgen)
144 repo._branchcache = partial
145 repo._branchcachetip = tip
@@ -662,39 +662,6 b' class localrepository(object):'
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:
@@ -703,7 +670,7 b' class localrepository(object):'
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
@@ -1446,7 +1413,7 b' class localrepository(object):'
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:
@@ -2431,7 +2398,7 b' class localrepository(object):'
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")
@@ -6,7 +6,7 b''
6 # This software may be used and distributed according to the terms of the
6 # This software may be used and distributed according to the terms of the
7 # GNU General Public License version 2 or any later version.
7 # GNU General Public License version 2 or any later version.
8
8
9 from mercurial import changegroup
9 from mercurial import changegroup, branchmap
10 from mercurial.node import short
10 from mercurial.node import short
11 from mercurial.i18n import _
11 from mercurial.i18n import _
12 import os
12 import os
@@ -60,7 +60,7 b' def strip(ui, repo, nodelist, backup="al'
60 # It simplifies the logic around updating the branchheads cache if we only
60 # It simplifies the logic around updating the branchheads cache if we only
61 # have to consider the effect of the stripped revisions and not revisions
61 # have to consider the effect of the stripped revisions and not revisions
62 # missing because the cache is out-of-date.
62 # missing because the cache is out-of-date.
63 repo.updatebranchcache()
63 branchmap.updatecache(repo)
64
64
65 cl = repo.changelog
65 cl = repo.changelog
66 # TODO handle undo of merge sets
66 # TODO handle undo of merge sets
General Comments 0
You need to be logged in to leave comments. Login now