# HG changeset patch # User Durham Goode # Date 1423626828 28800 # Node ID 59cc09240afb31f62022a5081ab7f2b35d2a2643 # Parent 577f65cf1a57a43e58380eb060f356858efe99bf revbranchcache: move out of branchmap onto localrepo Previously the revbranchcache was a field inside the branchmap. This is bad for a couple reasons: 1) There can be multiple branchmaps per repo (one for each filter level). There can only be one revbranchcache per repo. In fact, a revbranchcache could only exist on a branchmap that was for the unfiltered view, so you could have branchmaps exist for which you couldn't have a revbranchcache. It was funky. 2) The write lifecycle for the revbranchcache is going to be different from the branchmap (branchmap is greedily written early on, revbranchcache should be lazily computed and written). This patch moves the revbranchcache to live as a field on the localrepo (alongside self._branchmap). This will allow us to handle it's lifecycle differently, which will let us move it to be lazily computed in future patches. diff -r 577f65cf1a57 -r 59cc09240afb mercurial/branchmap.py --- a/mercurial/branchmap.py Tue Mar 17 14:29:56 2015 -0700 +++ b/mercurial/branchmap.py Tue Feb 10 19:53:48 2015 -0800 @@ -96,6 +96,10 @@ if revs: partial.update(repo, revs) partial.write(repo) + + if repo._revbranchcache is not None: + repo._revbranchcache.write(repo) + assert partial.validfor(repo), filtername repo._branchcaches[repo.filtername] = partial @@ -134,7 +138,6 @@ self._closednodes = set() else: self._closednodes = closednodes - self._revbranchcache = None def _hashfiltered(self, repo): """build hash of revision filtered in the current cache @@ -226,9 +229,6 @@ repo.ui.debug("couldn't write branch cache: %s\n" % inst) # Abort may be raise by read only opener pass - if self._revbranchcache: - self._revbranchcache.write(repo.unfiltered()) - self._revbranchcache = None def update(self, repo, revgen): """Given a branchhead cache, self, that may have extra nodes or be @@ -240,9 +240,8 @@ # collect new branch entries newbranches = {} urepo = repo.unfiltered() - self._revbranchcache = revbranchcache(urepo) - getbranchinfo = self._revbranchcache.branchinfo ucl = urepo.changelog + getbranchinfo = repo.revbranchcache().branchinfo for r in revgen: branch, closesbranch = getbranchinfo(ucl, r) newbranches.setdefault(branch, []).append(r) diff -r 577f65cf1a57 -r 59cc09240afb mercurial/localrepo.py --- a/mercurial/localrepo.py Tue Mar 17 14:29:56 2015 -0700 +++ b/mercurial/localrepo.py Tue Feb 10 19:53:48 2015 -0800 @@ -279,6 +279,7 @@ self._branchcaches = {} + self._revbranchcache = None self.filterpats = {} self._datafilters = {} self._transref = self._lockref = self._wlockref = None @@ -726,6 +727,12 @@ branchmap.updatecache(self) return self._branchcaches[self.filtername] + @unfilteredmethod + def revbranchcache(self): + if not self._revbranchcache: + self._revbranchcache = branchmap.revbranchcache(self.unfiltered()) + return self._revbranchcache + def branchtip(self, branch, ignoremissing=False): '''return the tip node for a given branch diff -r 577f65cf1a57 -r 59cc09240afb mercurial/statichttprepo.py --- a/mercurial/statichttprepo.py Tue Mar 17 14:29:56 2015 -0700 +++ b/mercurial/statichttprepo.py Tue Feb 10 19:53:48 2015 -0800 @@ -141,6 +141,7 @@ self._tags = None self.nodetagscache = None self._branchcaches = {} + self._revbranchcache = None self.encodepats = None self.decodepats = None