comparison mercurial/branchmap.py @ 33535:755e6532e81d

cachevfs: migration the revbranchcache to 'cachevfs' This will help sharing the cache between shares.
author Boris Feld <boris.feld@octobus.net>
date Sat, 15 Jul 2017 22:42:50 +0200
parents 2715a4fc0684
children 1814ca418b30
comparison
equal deleted inserted replaced
33534:2715a4fc0684 33535:755e6532e81d
315 repo.filtername, duration) 315 repo.filtername, duration)
316 316
317 # Revision branch info cache 317 # Revision branch info cache
318 318
319 _rbcversion = '-v1' 319 _rbcversion = '-v1'
320 _rbcnames = 'cache/rbc-names' + _rbcversion 320 _rbcnames = 'rbc-names' + _rbcversion
321 _rbcrevs = 'cache/rbc-revs' + _rbcversion 321 _rbcrevs = 'rbc-revs' + _rbcversion
322 # [4 byte hash prefix][4 byte branch name number with sign bit indicating open] 322 # [4 byte hash prefix][4 byte branch name number with sign bit indicating open]
323 _rbcrecfmt = '>4sI' 323 _rbcrecfmt = '>4sI'
324 _rbcrecsize = calcsize(_rbcrecfmt) 324 _rbcrecsize = calcsize(_rbcrecfmt)
325 _rbcnodelen = 4 325 _rbcnodelen = 4
326 _rbcbranchidxmask = 0x7fffffff 326 _rbcbranchidxmask = 0x7fffffff
354 self._repo = repo 354 self._repo = repo
355 self._names = [] # branch names in local encoding with static index 355 self._names = [] # branch names in local encoding with static index
356 self._rbcrevs = bytearray() 356 self._rbcrevs = bytearray()
357 self._rbcsnameslen = 0 # length of names read at _rbcsnameslen 357 self._rbcsnameslen = 0 # length of names read at _rbcsnameslen
358 try: 358 try:
359 bndata = repo.vfs.read(_rbcnames) 359 bndata = repo.cachevfs.read(_rbcnames)
360 self._rbcsnameslen = len(bndata) # for verification before writing 360 self._rbcsnameslen = len(bndata) # for verification before writing
361 if bndata: 361 if bndata:
362 self._names = [encoding.tolocal(bn) 362 self._names = [encoding.tolocal(bn)
363 for bn in bndata.split('\0')] 363 for bn in bndata.split('\0')]
364 except (IOError, OSError): 364 except (IOError, OSError):
366 # don't try to use cache - fall back to the slow path 366 # don't try to use cache - fall back to the slow path
367 self.branchinfo = self._branchinfo 367 self.branchinfo = self._branchinfo
368 368
369 if self._names: 369 if self._names:
370 try: 370 try:
371 data = repo.vfs.read(_rbcrevs) 371 data = repo.cachevfs.read(_rbcrevs)
372 self._rbcrevs[:] = data 372 self._rbcrevs[:] = data
373 except (IOError, OSError) as inst: 373 except (IOError, OSError) as inst:
374 repo.ui.debug("couldn't read revision branch cache: %s\n" % 374 repo.ui.debug("couldn't read revision branch cache: %s\n" %
375 inst) 375 inst)
376 # remember number of good records on disk 376 # remember number of good records on disk
471 try: 471 try:
472 if self._rbcnamescount < len(self._names): 472 if self._rbcnamescount < len(self._names):
473 step = ' names' 473 step = ' names'
474 wlock = repo.wlock(wait=False) 474 wlock = repo.wlock(wait=False)
475 if self._rbcnamescount != 0: 475 if self._rbcnamescount != 0:
476 f = repo.vfs.open(_rbcnames, 'ab') 476 f = repo.cachevfs.open(_rbcnames, 'ab')
477 if f.tell() == self._rbcsnameslen: 477 if f.tell() == self._rbcsnameslen:
478 f.write('\0') 478 f.write('\0')
479 else: 479 else:
480 f.close() 480 f.close()
481 repo.ui.debug("%s changed - rewriting it\n" % _rbcnames) 481 repo.ui.debug("%s changed - rewriting it\n" % _rbcnames)
482 self._rbcnamescount = 0 482 self._rbcnamescount = 0
483 self._rbcrevslen = 0 483 self._rbcrevslen = 0
484 if self._rbcnamescount == 0: 484 if self._rbcnamescount == 0:
485 # before rewriting names, make sure references are removed 485 # before rewriting names, make sure references are removed
486 repo.vfs.unlinkpath(_rbcrevs, ignoremissing=True) 486 repo.cachevfs.unlinkpath(_rbcrevs, ignoremissing=True)
487 f = repo.vfs.open(_rbcnames, 'wb') 487 f = repo.cachevfs.open(_rbcnames, 'wb')
488 f.write('\0'.join(encoding.fromlocal(b) 488 f.write('\0'.join(encoding.fromlocal(b)
489 for b in self._names[self._rbcnamescount:])) 489 for b in self._names[self._rbcnamescount:]))
490 self._rbcsnameslen = f.tell() 490 self._rbcsnameslen = f.tell()
491 f.close() 491 f.close()
492 self._rbcnamescount = len(self._names) 492 self._rbcnamescount = len(self._names)
496 step = '' 496 step = ''
497 if wlock is None: 497 if wlock is None:
498 wlock = repo.wlock(wait=False) 498 wlock = repo.wlock(wait=False)
499 revs = min(len(repo.changelog), 499 revs = min(len(repo.changelog),
500 len(self._rbcrevs) // _rbcrecsize) 500 len(self._rbcrevs) // _rbcrecsize)
501 f = repo.vfs.open(_rbcrevs, 'ab') 501 f = repo.cachevfs.open(_rbcrevs, 'ab')
502 if f.tell() != start: 502 if f.tell() != start:
503 repo.ui.debug("truncating %s to %d\n" % (_rbcrevs, start)) 503 repo.ui.debug("truncating cache/%s to %d\n"
504 % (_rbcrevs, start))
504 f.seek(start) 505 f.seek(start)
505 if f.tell() != start: 506 if f.tell() != start:
506 start = 0 507 start = 0
507 f.seek(start) 508 f.seek(start)
508 f.truncate() 509 f.truncate()