Mercurial > hg
comparison mercurial/branchmap.py @ 18126:090ada0acddb
branchmap: add the tiprev (cache key) on the branchmap object
The actual cache key used on disk is the (tipnode, tiprev) pair. There is no
reason not to use the revision number for the in memory version.
author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
---|---|
date | Sat, 22 Dec 2012 02:06:26 +0100 |
parents | ad194a8ab5c1 |
children | dcd43ac7572d |
comparison
equal
deleted
inserted
replaced
18125:ad194a8ab5c1 | 18126:090ada0acddb |
---|---|
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 branchcache(), nullrev | 18 return branchcache() |
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: |
31 if not node in repo: | 31 if not node in repo: |
32 raise ValueError('invalidating branch cache because node '+ | 32 raise ValueError('invalidating branch cache because node '+ |
33 '%s does not exist' % node) | 33 '%s does not exist' % node) |
34 partial.setdefault(label, []).append(bin(node)) | 34 partial.setdefault(label, []).append(bin(node)) |
35 partial.tipnode = last | 35 partial.tipnode = last |
36 partial.tiprev = lrev | |
36 except KeyboardInterrupt: | 37 except KeyboardInterrupt: |
37 raise | 38 raise |
38 except Exception, inst: | 39 except Exception, inst: |
39 if repo.ui.debugflag: | 40 if repo.ui.debugflag: |
40 repo.ui.warn(str(inst), '\n') | 41 repo.ui.warn(str(inst), '\n') |
41 partial, lrev = branchcache(), nullrev | 42 partial = branchcache() |
42 return partial, lrev | 43 return partial |
43 | 44 |
44 def write(repo, branches, tip, tiprev): | 45 def write(repo, branches, tip, tiprev): |
45 try: | 46 try: |
46 f = repo.opener("cache/branchheads", "w", atomictemp=True) | 47 f = repo.opener("cache/branchheads", "w", atomictemp=True) |
47 f.write("%s %s\n" % (hex(tip), tiprev)) | 48 f.write("%s %s\n" % (hex(tip), tiprev)) |
119 partial = repo._branchcache | 120 partial = repo._branchcache |
120 if partial is not None and partial.tipnode == tip: | 121 if partial is not None and partial.tipnode == tip: |
121 return | 122 return |
122 | 123 |
123 if partial is None or partial.tipnode not in cl.nodemap: | 124 if partial is None or partial.tipnode not in cl.nodemap: |
124 partial, lrev = read(repo) | 125 partial = read(repo) |
125 else: | |
126 lrev = cl.rev(partial.tipnode) | |
127 | 126 |
128 catip = repo._cacheabletip() | 127 catip = repo._cacheabletip() |
129 # if lrev == catip: cache is already up to date | 128 # if partial.tiprev == catip: cache is already up to date |
130 # if lrev > catip: we have uncachable element in `partial` can't write | 129 # if partial.tiprev > catip: we have uncachable element in `partial` can't |
131 # on disk | 130 # write on disk |
132 if lrev < catip: | 131 if partial.tiprev < catip: |
133 ctxgen = (repo[r] for r in cl.revs(lrev + 1, catip)) | 132 ctxgen = (repo[r] for r in cl.revs(partial.tiprev + 1, catip)) |
134 update(repo, partial, ctxgen) | 133 update(repo, partial, ctxgen) |
135 partial.tipnode = cl.node(catip) | 134 partial.tipnode = cl.node(catip) |
136 write(repo, partial, partial.tipnode, catip) | 135 partial.tiprev = catip |
137 lrev = catip | 136 write(repo, partial, partial.tipnode, partial.tiprev) |
138 # If cacheable tip were lower than actual tip, we need to update the | 137 # If cacheable tip were lower than actual tip, we need to update the |
139 # cache up to tip. This update (from cacheable to actual tip) is not | 138 # cache up to tip. This update (from cacheable to actual tip) is not |
140 # written to disk since it's not cacheable. | 139 # written to disk since it's not cacheable. |
141 tiprev = len(repo) - 1 | 140 tiprev = len(repo) - 1 |
142 if lrev < tiprev: | 141 if partial.tiprev < tiprev: |
143 ctxgen = (repo[r] for r in cl.revs(lrev + 1, tiprev)) | 142 ctxgen = (repo[r] for r in cl.revs(partial.tiprev + 1, tiprev)) |
144 update(repo, partial, ctxgen) | 143 update(repo, partial, ctxgen) |
145 partial.tipnode = cl.node(tiprev) | 144 partial.tipnode = cl.node(tiprev) |
145 partial.tiprev = tiprev | |
146 repo._branchcache = partial | 146 repo._branchcache = partial |
147 | 147 |
148 class branchcache(dict): | 148 class branchcache(dict): |
149 """A dict like object that hold branches heads cache""" | 149 """A dict like object that hold branches heads cache""" |
150 | 150 |
151 def __init__(self, entries=(), tipnode=nullid): | 151 def __init__(self, entries=(), tipnode=nullid, tiprev=nullrev): |
152 super(branchcache, self).__init__(entries) | 152 super(branchcache, self).__init__(entries) |
153 self.tipnode = tipnode | 153 self.tipnode = tipnode |
154 self.tiprev = tiprev |