comparison mercurial/branchmap.py @ 24373:59cc09240afb

revbranchcache: move out of branchmap onto localrepo Previously the revbranchcache was a field inside the branchmap. This is bad for a couple reasons: 1) There can be multiple branchmaps per repo (one for each filter level). There can only be one revbranchcache per repo. In fact, a revbranchcache could only exist on a branchmap that was for the unfiltered view, so you could have branchmaps exist for which you couldn't have a revbranchcache. It was funky. 2) The write lifecycle for the revbranchcache is going to be different from the branchmap (branchmap is greedily written early on, revbranchcache should be lazily computed and written). This patch moves the revbranchcache to live as a field on the localrepo (alongside self._branchmap). This will allow us to handle it's lifecycle differently, which will let us move it to be lazily computed in future patches.
author Durham Goode <durham@fb.com>
date Tue, 10 Feb 2015 19:53:48 -0800
parents bb11081562d7
children 77fd1fb538cd
comparison
equal deleted inserted replaced
24372:577f65cf1a57 24373:59cc09240afb
94 revs.extend(r for r in extrarevs if r <= partial.tiprev) 94 revs.extend(r for r in extrarevs if r <= partial.tiprev)
95 revs.extend(cl.revs(start=partial.tiprev + 1)) 95 revs.extend(cl.revs(start=partial.tiprev + 1))
96 if revs: 96 if revs:
97 partial.update(repo, revs) 97 partial.update(repo, revs)
98 partial.write(repo) 98 partial.write(repo)
99
100 if repo._revbranchcache is not None:
101 repo._revbranchcache.write(repo)
102
99 assert partial.validfor(repo), filtername 103 assert partial.validfor(repo), filtername
100 repo._branchcaches[repo.filtername] = partial 104 repo._branchcaches[repo.filtername] = partial
101 105
102 class branchcache(dict): 106 class branchcache(dict):
103 """A dict like object that hold branches heads cache. 107 """A dict like object that hold branches heads cache.
132 # heads. 136 # heads.
133 if closednodes is None: 137 if closednodes is None:
134 self._closednodes = set() 138 self._closednodes = set()
135 else: 139 else:
136 self._closednodes = closednodes 140 self._closednodes = closednodes
137 self._revbranchcache = None
138 141
139 def _hashfiltered(self, repo): 142 def _hashfiltered(self, repo):
140 """build hash of revision filtered in the current cache 143 """build hash of revision filtered in the current cache
141 144
142 Tracking tipnode and tiprev is not enough to ensure validity of the 145 Tracking tipnode and tiprev is not enough to ensure validity of the
224 repo.filtername, len(self), nodecount) 227 repo.filtername, len(self), nodecount)
225 except (IOError, OSError, util.Abort), inst: 228 except (IOError, OSError, util.Abort), inst:
226 repo.ui.debug("couldn't write branch cache: %s\n" % inst) 229 repo.ui.debug("couldn't write branch cache: %s\n" % inst)
227 # Abort may be raise by read only opener 230 # Abort may be raise by read only opener
228 pass 231 pass
229 if self._revbranchcache:
230 self._revbranchcache.write(repo.unfiltered())
231 self._revbranchcache = None
232 232
233 def update(self, repo, revgen): 233 def update(self, repo, revgen):
234 """Given a branchhead cache, self, that may have extra nodes or be 234 """Given a branchhead cache, self, that may have extra nodes or be
235 missing heads, and a generator of nodes that are strictly a superset of 235 missing heads, and a generator of nodes that are strictly a superset of
236 heads missing, this function updates self to be correct. 236 heads missing, this function updates self to be correct.
238 starttime = time.time() 238 starttime = time.time()
239 cl = repo.changelog 239 cl = repo.changelog
240 # collect new branch entries 240 # collect new branch entries
241 newbranches = {} 241 newbranches = {}
242 urepo = repo.unfiltered() 242 urepo = repo.unfiltered()
243 self._revbranchcache = revbranchcache(urepo)
244 getbranchinfo = self._revbranchcache.branchinfo
245 ucl = urepo.changelog 243 ucl = urepo.changelog
244 getbranchinfo = repo.revbranchcache().branchinfo
246 for r in revgen: 245 for r in revgen:
247 branch, closesbranch = getbranchinfo(ucl, r) 246 branch, closesbranch = getbranchinfo(ucl, r)
248 newbranches.setdefault(branch, []).append(r) 247 newbranches.setdefault(branch, []).append(r)
249 if closesbranch: 248 if closesbranch:
250 self._closednodes.add(cl.node(r)) 249 self._closednodes.add(cl.node(r))