Mercurial > hg
diff mercurial/branchmap.py @ 24374:77fd1fb538cd
revbranchcache: store repo on the object
Previously we would instantiate the revbranchcache with a repo object, use it
briefly, then require it be passed in every time we wanted to fetch any
information. This seems unnecessary since it's obviously specific to that repo
(since it was constructed with it).
This patch stores the repo on the revbranchcache object, and removes the repo
parameter from the various functions on that class. This has the other nice
benefit of removing the double-revbranchcache-read that existed before (it was
read once for the branch revset, and once for the repo.revbranchcache).
author | Durham Goode <durham@fb.com> |
---|---|
date | Tue, 10 Feb 2015 19:57:51 -0800 |
parents | 59cc09240afb |
children | fe255b2525d5 |
line wrap: on
line diff
--- a/mercurial/branchmap.py Tue Feb 10 19:53:48 2015 -0800 +++ b/mercurial/branchmap.py Tue Feb 10 19:57:51 2015 -0800 @@ -98,7 +98,7 @@ partial.write(repo) if repo._revbranchcache is not None: - repo._revbranchcache.write(repo) + repo._revbranchcache.write() assert partial.validfor(repo), filtername repo._branchcaches[repo.filtername] = partial @@ -239,11 +239,9 @@ cl = repo.changelog # collect new branch entries newbranches = {} - urepo = repo.unfiltered() - ucl = urepo.changelog getbranchinfo = repo.revbranchcache().branchinfo for r in revgen: - branch, closesbranch = getbranchinfo(ucl, r) + branch, closesbranch = getbranchinfo(r) newbranches.setdefault(branch, []).append(r) if closesbranch: self._closednodes.add(cl.node(r)) @@ -331,6 +329,7 @@ def __init__(self, repo, readonly=True): assert repo.filtername is None + self._repo = repo self._names = [] # branch names in local encoding with static index self._rbcrevs = array('c') # structs of type _rbcrecfmt self._rbcsnameslen = 0 @@ -360,9 +359,10 @@ self._rbcnamescount = len(self._names) # number of good names on disk self._namesreverse = dict((b, r) for r, b in enumerate(self._names)) - def branchinfo(self, changelog, rev): + def branchinfo(self, rev): """Return branch name and close flag for rev, using and updating persistent cache.""" + changelog = self._repo.changelog rbcrevidx = rev * _rbcrecsize # if requested rev is missing, add and populate all missing revs @@ -371,7 +371,7 @@ self._rbcrevs.extend('\0' * (len(changelog) * _rbcrecsize - len(self._rbcrevs))) for r in xrange(first, len(changelog)): - self._branchinfo(changelog, r) + self._branchinfo(r) # fast path: extract data from cache, use it if node is matching reponode = changelog.node(rev)[:_rbcnodelen] @@ -384,10 +384,11 @@ return self._names[branchidx], close # fall back to slow path and make sure it will be written to disk self._rbcrevslen = min(self._rbcrevslen, rev) - return self._branchinfo(changelog, rev) + return self._branchinfo(rev) - def _branchinfo(self, changelog, rev): + def _branchinfo(self, rev): """Retrieve branch info from changelog and update _rbcrevs""" + changelog = self._repo.changelog b, close = changelog.branchinfo(rev) if b in self._namesreverse: branchidx = self._namesreverse[b] @@ -404,8 +405,9 @@ self._rbcrevs[rbcrevidx:rbcrevidx + _rbcrecsize] = rec return b, close - def write(self, repo): + def write(self): """Save branch cache if it is dirty.""" + repo = self._repo if self._rbcnamescount < len(self._names): try: if self._rbcnamescount != 0: