Mercurial > hg
changeset 18124:79db6d40bced
branchmap: store branchcache in a dedicated object
Value and key of branchcache would benefit from being hold by the same object.
Moreover some logic (update, write, validation) could be move on such object.
The creation of this object is the first step toward this move. The result will
clarify branchcache related code and hide most of the detail in the class
itself. This encapsulation will greatly helps implementation of branchcache for
filtered view of the repo.
author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
---|---|
date | Sat, 22 Dec 2012 01:44:42 +0100 |
parents | 6fb3b8c61775 |
children | ad194a8ab5c1 |
files | mercurial/branchmap.py mercurial/discovery.py mercurial/localrepo.py |
diffstat | 3 files changed, 12 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/branchmap.py Sat Dec 22 01:34:23 2012 +0100 +++ b/mercurial/branchmap.py Sat Dec 22 01:44:42 2012 +0100 @@ -9,13 +9,13 @@ import encoding def read(repo): - partial = {} + partial = branchcache() try: f = repo.opener("cache/branchheads") lines = f.read().split('\n') f.close() except (IOError, OSError): - return {}, nullid, nullrev + return branchcache(), nullid, nullrev try: last, lrev = lines.pop(0).split(" ", 1) @@ -37,7 +37,7 @@ except Exception, inst: if repo.ui.debugflag: repo.ui.warn(str(inst), '\n') - partial, last, lrev = {}, nullid, nullrev + partial, last, lrev = branchcache(), nullid, nullrev return partial, last, lrev def write(repo, branches, tip, tiprev): @@ -143,3 +143,7 @@ update(repo, partial, ctxgen) repo._branchcache = partial repo._branchcachetip = tip + +class branchcache(dict): + """A dict like object that hold branches heads cache""" +
--- a/mercurial/discovery.py Sat Dec 22 01:34:23 2012 +0100 +++ b/mercurial/discovery.py Sat Dec 22 01:44:42 2012 +0100 @@ -193,8 +193,9 @@ # D. Update newmap with outgoing changes. # This will possibly add new heads and remove existing ones. - newmap = dict((branch, heads[1]) for branch, heads in headssum.iteritems() - if heads[0] is not None) + newmap = branchmap.branchcache((branch, heads[1]) + for branch, heads in headssum.iteritems() + if heads[0] is not None) branchmap.update(repo, newmap, missingctx) for branch, newheads in newmap.iteritems(): headssum[branch][1][:] = newheads
--- a/mercurial/localrepo.py Sat Dec 22 01:34:23 2012 +0100 +++ b/mercurial/localrepo.py Sat Dec 22 01:44:42 2012 +0100 @@ -666,7 +666,7 @@ '''returns a dictionary {branch: [branchheads]}''' if self.changelog.filteredrevs: # some changeset are excluded we can't use the cache - bmap = {} + bmap = branchmap.branchcache() branchmap.update(self, bmap, (self[r] for r in self)) return bmap else: @@ -2495,7 +2495,7 @@ if rbheads: rtiprev = max((int(self.changelog.rev(node)) for node in rbheads)) - self._branchcache = rbranchmap + self._branchcache = branchmap.branchcache(rbranchmap) rtipnode = self._branchcachetip = self[rtiprev].node() branchmap.write(self, self._branchcache, rtipnode, rtiprev) self.invalidate()