comparison mercurial/branchmap.py @ 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 f8a13f061a8a
children ad194a8ab5c1
comparison
equal deleted inserted replaced
18123:6fb3b8c61775 18124:79db6d40bced
7 7
8 from node import bin, hex, nullid, nullrev 8 from node import bin, hex, nullid, nullrev
9 import encoding 9 import encoding
10 10
11 def read(repo): 11 def read(repo):
12 partial = {} 12 partial = branchcache()
13 try: 13 try:
14 f = repo.opener("cache/branchheads") 14 f = repo.opener("cache/branchheads")
15 lines = f.read().split('\n') 15 lines = f.read().split('\n')
16 f.close() 16 f.close()
17 except (IOError, OSError): 17 except (IOError, OSError):
18 return {}, nullid, nullrev 18 return branchcache(), nullid, nullrev
19 19
20 try: 20 try:
21 last, lrev = lines.pop(0).split(" ", 1) 21 last, lrev = lines.pop(0).split(" ", 1)
22 last, lrev = bin(last), int(lrev) 22 last, lrev = bin(last), int(lrev)
23 if lrev >= len(repo) or repo[lrev].node() != last: 23 if lrev >= len(repo) or repo[lrev].node() != last:
35 except KeyboardInterrupt: 35 except KeyboardInterrupt:
36 raise 36 raise
37 except Exception, inst: 37 except Exception, inst:
38 if repo.ui.debugflag: 38 if repo.ui.debugflag:
39 repo.ui.warn(str(inst), '\n') 39 repo.ui.warn(str(inst), '\n')
40 partial, last, lrev = {}, nullid, nullrev 40 partial, last, lrev = branchcache(), nullid, nullrev
41 return partial, last, lrev 41 return partial, last, lrev
42 42
43 def write(repo, branches, tip, tiprev): 43 def write(repo, branches, tip, tiprev):
44 try: 44 try:
45 f = repo.opener("cache/branchheads", "w", atomictemp=True) 45 f = repo.opener("cache/branchheads", "w", atomictemp=True)
141 if lrev < tiprev: 141 if lrev < tiprev:
142 ctxgen = (repo[r] for r in cl.revs(lrev + 1, tiprev)) 142 ctxgen = (repo[r] for r in cl.revs(lrev + 1, tiprev))
143 update(repo, partial, ctxgen) 143 update(repo, partial, ctxgen)
144 repo._branchcache = partial 144 repo._branchcache = partial
145 repo._branchcachetip = tip 145 repo._branchcachetip = tip
146
147 class branchcache(dict):
148 """A dict like object that hold branches heads cache"""
149