Mercurial > hg
changeset 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 |
files | mercurial/branchmap.py mercurial/localrepo.py mercurial/repair.py |
diffstat | 3 files changed, 37 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/branchmap.py Wed Dec 19 14:49:06 2012 +0100 +++ b/mercurial/branchmap.py Thu Dec 20 14:45:17 2012 +0100 @@ -111,3 +111,35 @@ if not nodes: del partial[branch] +def updatecache(repo): + repo = repo.unfiltered() # Until we get a smarter cache management + cl = repo.changelog + tip = cl.tip() + if repo._branchcache is not None and repo._branchcachetip == tip: + return + + oldtip = repo._branchcachetip + if oldtip is None or oldtip not in cl.nodemap: + partial, last, lrev = read(repo) + else: + lrev = cl.rev(oldtip) + partial = repo._branchcache + + catip = repo._cacheabletip() + # if lrev == catip: cache is already up to date + # if lrev > catip: we have uncachable element in `partial` can't write + # on disk + if lrev < catip: + ctxgen = (repo[r] for r in cl.revs(lrev + 1, catip)) + update(repo, partial, ctxgen) + write(repo, partial, cl.node(catip), catip) + lrev = catip + # If cacheable tip were lower than actual tip, we need to update the + # cache up to tip. This update (from cacheable to actual tip) is not + # written to disk since it's not cacheable. + tiprev = len(repo) - 1 + if lrev < tiprev: + ctxgen = (repo[r] for r in cl.revs(lrev + 1, tiprev)) + update(repo, partial, ctxgen) + repo._branchcache = partial + repo._branchcachetip = tip
--- a/mercurial/localrepo.py Wed Dec 19 14:49:06 2012 +0100 +++ b/mercurial/localrepo.py Thu Dec 20 14:45:17 2012 +0100 @@ -662,39 +662,6 @@ cl = self.changelog return cl.rev(cl.tip()) - @unfilteredmethod # Until we get a smarter cache management - def updatebranchcache(self): - cl = self.changelog - tip = cl.tip() - if self._branchcache is not None and self._branchcachetip == tip: - return - - oldtip = self._branchcachetip - if oldtip is None or oldtip not in cl.nodemap: - partial, last, lrev = branchmap.read(self) - else: - lrev = cl.rev(oldtip) - partial = self._branchcache - - catip = self._cacheabletip() - # if lrev == catip: cache is already up to date - # if lrev > catip: we have uncachable element in `partial` can't write - # on disk - if lrev < catip: - ctxgen = (self[r] for r in cl.revs(lrev + 1, catip)) - branchmap.update(self, partial, ctxgen) - branchmap.write(self, partial, cl.node(catip), catip) - lrev = catip - # If cacheable tip were lower than actual tip, we need to update the - # cache up to tip. This update (from cacheable to actual tip) is not - # written to disk since it's not cacheable. - tiprev = len(self) - 1 - if lrev < tiprev: - ctxgen = (self[r] for r in cl.revs(lrev + 1, tiprev)) - branchmap.update(self, partial, ctxgen) - self._branchcache = partial - self._branchcachetip = tip - def branchmap(self): '''returns a dictionary {branch: [branchheads]}''' if self.changelog.filteredrevs: @@ -703,7 +670,7 @@ branchmap.update(self, bmap, (self[r] for r in self)) return bmap else: - self.updatebranchcache() + branchmap.updatecache(self) return self._branchcache @@ -1446,7 +1413,7 @@ # if minimal phase was 0 we don't need to retract anything phases.retractboundary(self, targetphase, [n]) tr.close() - self.updatebranchcache() + branchmap.updatecache(self) return n finally: if tr: @@ -2431,7 +2398,7 @@ tr.close() if changesets > 0: - self.updatebranchcache() + branchmap.updatecache(self) def runhooks(): # forcefully update the on-disk branch cache self.ui.debug("updating the branch cache\n")
--- a/mercurial/repair.py Wed Dec 19 14:49:06 2012 +0100 +++ b/mercurial/repair.py Thu Dec 20 14:45:17 2012 +0100 @@ -6,7 +6,7 @@ # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. -from mercurial import changegroup +from mercurial import changegroup, branchmap from mercurial.node import short from mercurial.i18n import _ import os @@ -60,7 +60,7 @@ # It simplifies the logic around updating the branchheads cache if we only # have to consider the effect of the stripped revisions and not revisions # missing because the cache is out-of-date. - repo.updatebranchcache() + branchmap.updatecache(repo) cl = repo.changelog # TODO handle undo of merge sets