Mercurial > hg
changeset 18112:569091b938a9
branchmap: simplify _branchtags using a new _cacheabletip method
The current _branchtags method is a remnant of an older, much larger function.
Its only remaining role is to help MQ to alter the version of branchcache we
store on disk. As MQ mutates the repository it ensures persistent cache does not
contain anything it is likely to alter.
This changeset makes explicit the stable vs volatile part of repository and
reduces the MQ specific code to the computation of this limit. The main
_branchtags code now handles this possible limit in all cases.
This will help to extract the branchmap logic from the repository.
The new code of _branchtags is a bit duplicated, but as I expect major
refactoring of this section I'm not keen to setup factorisation function here.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Thu, 20 Dec 2012 11:52:50 +0100 |
parents | d7c28954d901 |
children | da1714bd0250 |
files | hgext/mq.py mercurial/localrepo.py |
diffstat | 2 files changed, 32 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/mq.py Thu Dec 20 21:26:30 2012 +0100 +++ b/hgext/mq.py Thu Dec 20 11:52:50 2012 +0100 @@ -3477,7 +3477,7 @@ return result - def _branchtags(self, partial, lrev): + def _cacheabletip(self): q = self.mq cl = self.changelog qbase = None @@ -3492,25 +3492,10 @@ except error.LookupError: self.ui.warn(_('mq status file refers to unknown node %s\n') % short(qbasenode)) - if qbase is None: - return super(mqrepo, self)._branchtags(partial, lrev) - - start = lrev + 1 - if start < qbase: - # update the cache (excluding the patches) and save it - ctxgen = (self[r] for r in xrange(lrev + 1, qbase)) - self._updatebranchcache(partial, ctxgen) - self._writebranchcache(partial, cl.node(qbase - 1), qbase - 1) - start = qbase - # if start = qbase, the cache is as updated as it should be. - # if start > qbase, the cache includes (part of) the patches. - # we might as well use it, but we won't save it. - - # update the cache up to the tip - ctxgen = (self[r] for r in xrange(start, len(cl))) - self._updatebranchcache(partial, ctxgen) - - return partial + ret = super(mqrepo, self)._cacheabletip() + if qbase is not None: + ret = min(qbase - 1, ret) + return ret if repo.local(): repo.__class__ = mqrepo
--- a/mercurial/localrepo.py Thu Dec 20 21:26:30 2012 +0100 +++ b/mercurial/localrepo.py Thu Dec 20 11:52:50 2012 +0100 @@ -649,14 +649,37 @@ marks.append(bookmark) return sorted(marks) + def _cacheabletip(self): + """tip-most revision stable enought to used in persistent cache + + This function is overwritten by MQ to ensure we do not write cache for + a part of the history that will likely change. + + Efficient handling of filtered revision in branchcache should offer a + better alternative. But we are using this approach until it is ready. + """ + cl = self.changelog + return cl.rev(cl.tip()) + def _branchtags(self, partial, lrev): # TODO: rename this function? + cl = self.changelog + 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)) + self._updatebranchcache(partial, ctxgen) + self._writebranchcache(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 self.changelog.revs(lrev + 1, tiprev)) + if lrev < tiprev: + ctxgen = (self[r] for r in cl.revs(lrev + 1, tiprev)) self._updatebranchcache(partial, ctxgen) - self._writebranchcache(partial, self.changelog.tip(), tiprev) - return partial @unfilteredmethod # Until we get a smarter cache management