comparison mercurial/branchmap.py @ 41566:eb7ce452e0fb

branchmap: updating triggers a write Rather than separate updating and writing, create a subclass that doesn't write on update. This minimises chances we forget to write out updates somewhere. This also makes refactoring and improving the branchmap functionality easier. Differential Revision: https://phab.mercurial-scm.org/D5636
author Martijn Pieters <mj@octobus.net>
date Mon, 21 Jan 2019 16:37:23 +0000
parents bf7fb97aecf1
children c795c462b1d6
comparison
equal deleted inserted replaced
41565:bf7fb97aecf1 41566:eb7ce452e0fb
61 extrarevs = subset.changelog.filteredrevs - cl.filteredrevs 61 extrarevs = subset.changelog.filteredrevs - cl.filteredrevs
62 revs.extend(r for r in extrarevs if r <= bcache.tiprev) 62 revs.extend(r for r in extrarevs if r <= bcache.tiprev)
63 revs.extend(cl.revs(start=bcache.tiprev + 1)) 63 revs.extend(cl.revs(start=bcache.tiprev + 1))
64 if revs: 64 if revs:
65 bcache.update(repo, revs) 65 bcache.update(repo, revs)
66 bcache.write(repo)
67 66
68 assert bcache.validfor(repo), filtername 67 assert bcache.validfor(repo), filtername
69 repo._branchcaches[repo.filtername] = bcache 68 repo._branchcaches[repo.filtername] = bcache
70 69
71 def replacecache(repo, bm): 70 def replacecache(repo, bm):
240 for bn, heads in self.iteritems(): 239 for bn, heads in self.iteritems():
241 yield (bn, heads) + self._branchtip(heads) 240 yield (bn, heads) + self._branchtip(heads)
242 241
243 def copy(self): 242 def copy(self):
244 """return an deep copy of the branchcache object""" 243 """return an deep copy of the branchcache object"""
245 return branchcache(self, self.tipnode, self.tiprev, self.filteredhash, 244 return type(self)(
246 self._closednodes) 245 self, self.tipnode, self.tiprev, self.filteredhash,
246 self._closednodes)
247 247
248 def write(self, repo): 248 def write(self, repo):
249 try: 249 try:
250 f = repo.cachevfs(self._filename(repo), "w", atomictemp=True) 250 f = repo.cachevfs(self._filename(repo), "w", atomictemp=True)
251 cachekey = [hex(self.tipnode), '%d' % self.tiprev] 251 cachekey = [hex(self.tipnode), '%d' % self.tiprev]
329 self.filteredhash = scmutil.filteredhash(repo, self.tiprev) 329 self.filteredhash = scmutil.filteredhash(repo, self.tiprev)
330 330
331 duration = util.timer() - starttime 331 duration = util.timer() - starttime
332 repo.ui.log('branchcache', 'updated %s branch cache in %.4f seconds\n', 332 repo.ui.log('branchcache', 'updated %s branch cache in %.4f seconds\n',
333 repo.filtername, duration) 333 repo.filtername, duration)
334
335 self.write(repo)
336
337
338 class remotebranchcache(branchcache):
339 """Branchmap info for a remote connection, should not write locally"""
340 def write(self, repo):
341 pass
342
334 343
335 # Revision branch info cache 344 # Revision branch info cache
336 345
337 _rbcversion = '-v1' 346 _rbcversion = '-v1'
338 _rbcnames = 'rbc-names' + _rbcversion 347 _rbcnames = 'rbc-names' + _rbcversion