[PATCH 5 of 6] branchcache: let localrepo own the revbranchcache instance, save on close
Mads Kiilerich
mads at kiilerich.com
Sun Dec 14 12:34:24 CST 2014
# HG changeset patch
# User Mads Kiilerich <madski at unity3d.com>
# Date 1418581984 -3600
# Sun Dec 14 19:33:04 2014 +0100
# Node ID 186394f5dbf37adf268fa034fc897201fd2dbe0d
# Parent a84099ef1a332eb93bc9287d74c64af7e510f90e
branchcache: let localrepo own the revbranchcache instance, save on close
This seems to be the best of way of making a shared branchcache available
everywhere, also to read-only operations like revsets.
diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -234,15 +234,14 @@
cl = repo.changelog
# collect new branch entries
newbranches = {}
- cache = revbranchcache(repo)
- getbranchinfoutf8 = cache.branchinfoutf8
+ getbranchinfoutf8 = repo.revbranchcache.branchinfoutf8
for r in revgen:
branchutf8, closesbranch = getbranchinfoutf8(r)
branch = encoding.tolocal(branchutf8)
newbranches.setdefault(branch, []).append(r)
if closesbranch:
self._closednodes.add(cl.node(r))
- cache.save()
+ repo.revbranchcache.save()
# fetch current topological heads to speed up filtering
topoheads = set(cl.headrevs())
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -298,7 +298,8 @@
self.filteredrevcache = {}
def close(self):
- pass
+ if hasunfilteredcache(self, 'revbranchcache'):
+ self.revbranchcache.save()
def _restrictcapabilities(self, caps):
# bundle2 is not ready for prime time, drop it unless explicitly
@@ -728,6 +729,11 @@
repo = (remote and remote.local()) and remote or self
return repo[key].branch()
+ @unfilteredpropertycache
+ def revbranchcache(self):
+ """persistent cache of revision branch names"""
+ return branchmap.revbranchcache(self)
+
def known(self, nodes):
nm = self.changelog.nodemap
pc = self._phasecache
diff --git a/mercurial/statichttprepo.py b/mercurial/statichttprepo.py
--- a/mercurial/statichttprepo.py
+++ b/mercurial/statichttprepo.py
@@ -90,6 +90,12 @@
def canpush(self):
return False
+class statichttprevbranchcache(object):
+ def __init__(self, repo):
+ self.branchinfoutf8 = repo.changelog.branchinfoutf8
+ def save(self):
+ pass
+
class statichttprepository(localrepo.localrepository):
supported = localrepo.localrepository._basesupported
@@ -141,6 +147,7 @@
self._branchcaches = {}
self.encodepats = None
self.decodepats = None
+ self.revbranchcache = statichttprevbranchcache(self)
def _restrictcapabilities(self, caps):
caps = super(statichttprepository, self)._restrictcapabilities(caps)
More information about the Mercurial-devel
mailing list