# HG changeset patch # User Durham Goode # Date 1423627071 28800 # Node ID 77fd1fb538cd4b4ab3d4c0c9c2b667ad85f3df3c # Parent 59cc09240afb31f62022a5081ab7f2b35d2a2643 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). diff -r 59cc09240afb -r 77fd1fb538cd mercurial/branchmap.py --- 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: diff -r 59cc09240afb -r 77fd1fb538cd mercurial/revset.py --- a/mercurial/revset.py Tue Feb 10 19:53:48 2015 -0800 +++ b/mercurial/revset.py Tue Feb 10 19:57:51 2015 -0800 @@ -528,10 +528,7 @@ a regular expression. To match a branch that actually starts with `re:`, use the prefix `literal:`. """ - import branchmap - urepo = repo.unfiltered() - ucl = urepo.changelog - getbi = branchmap.revbranchcache(urepo, readonly=True).branchinfo + getbi = repo.revbranchcache().branchinfo try: b = getstring(x, '') @@ -544,16 +541,16 @@ # note: falls through to the revspec case if no branch with # this name exists if pattern in repo.branchmap(): - return subset.filter(lambda r: matcher(getbi(ucl, r)[0])) + return subset.filter(lambda r: matcher(getbi(r)[0])) else: - return subset.filter(lambda r: matcher(getbi(ucl, r)[0])) + return subset.filter(lambda r: matcher(getbi(r)[0])) s = getset(repo, fullreposet(repo), x) b = set() for r in s: - b.add(getbi(ucl, r)[0]) + b.add(getbi(r)[0]) c = s.__contains__ - return subset.filter(lambda r: c(r) or getbi(ucl, r)[0] in b) + return subset.filter(lambda r: c(r) or getbi(r)[0] in b) def bumped(repo, subset, x): """``bumped()``