comparison mercurial/debugcommands.py @ 41942:fbee66c90cef

manifestcache: only lock the repository if the debug command touch the cache Not doing so had two consequences: 1) the command cannot be run on read only repositories, 2) when using --add on an empty cache, the command crash prematurely trying to read the cache file on disk.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 14 Mar 2019 10:43:01 +0000
parents 08fad2ca4eb6
children 1e75311d78f7
comparison
equal deleted inserted replaced
41941:08fad2ca4eb6 41942:fbee66c90cef
1463 ('a', 'add', '', _('add the given manifest node to the cache'), 1463 ('a', 'add', '', _('add the given manifest node to the cache'),
1464 _('NODE')) 1464 _('NODE'))
1465 ], '') 1465 ], '')
1466 def debugmanifestfulltextcache(ui, repo, add=None, **opts): 1466 def debugmanifestfulltextcache(ui, repo, add=None, **opts):
1467 """show, clear or amend the contents of the manifest fulltext cache""" 1467 """show, clear or amend the contents of the manifest fulltext cache"""
1468 with repo.lock(): 1468
1469 def getcache():
1469 r = repo.manifestlog.getstorage(b'') 1470 r = repo.manifestlog.getstorage(b'')
1470 try: 1471 try:
1471 cache = r._fulltextcache 1472 return r._fulltextcache
1472 except AttributeError: 1473 except AttributeError:
1473 ui.warn(_( 1474 msg = _("Current revlog implementation doesn't appear to have a "
1474 "Current revlog implementation doesn't appear to have a " 1475 "manifest fulltext cache\n")
1475 'manifest fulltext cache\n')) 1476 raise error.Abort(msg)
1476 return 1477
1477 1478 if opts.get(r'clear'):
1478 if opts.get(r'clear'): 1479 with repo.lock():
1480 cache = getcache()
1479 cache.clear() 1481 cache.clear()
1480 1482
1481 if add: 1483 if add:
1484 with repo.lock():
1482 try: 1485 try:
1483 manifest = repo.manifestlog[r.lookup(add)] 1486 m = repo.manifestlog
1487 manifest = m[m.getstorage(b'').lookup(add)]
1484 except error.LookupError as e: 1488 except error.LookupError as e:
1485 raise error.Abort(e, hint="Check your manifest node id") 1489 raise error.Abort(e, hint="Check your manifest node id")
1486 manifest.read() # stores revisision in cache too 1490 manifest.read() # stores revisision in cache too
1487 1491
1488 if not len(cache): 1492 cache = getcache()
1489 ui.write(_('cache empty\n')) 1493 if not len(cache):
1490 else: 1494 ui.write(_('cache empty\n'))
1491 ui.write( 1495 else:
1492 _('cache contains %d manifest entries, in order of most to ' 1496 ui.write(
1493 'least recent:\n') % (len(cache),)) 1497 _('cache contains %d manifest entries, in order of most to '
1494 totalsize = 0 1498 'least recent:\n') % (len(cache),))
1495 for nodeid in cache: 1499 totalsize = 0
1496 # Use cache.get to not update the LRU order 1500 for nodeid in cache:
1497 data = cache.get(nodeid) 1501 # Use cache.get to not update the LRU order
1498 size = len(data) 1502 data = cache.get(nodeid)
1499 totalsize += size + 24 # 20 bytes nodeid, 4 bytes size 1503 size = len(data)
1500 ui.write(_('id: %s, size %s\n') % ( 1504 totalsize += size + 24 # 20 bytes nodeid, 4 bytes size
1501 hex(nodeid), util.bytecount(size))) 1505 ui.write(_('id: %s, size %s\n') % (
1502 ondisk = cache._opener.stat('manifestfulltextcache').st_size 1506 hex(nodeid), util.bytecount(size)))
1503 ui.write( 1507 ondisk = cache._opener.stat('manifestfulltextcache').st_size
1504 _('total cache data size %s, on-disk %s\n') % ( 1508 ui.write(
1505 util.bytecount(totalsize), util.bytecount(ondisk)) 1509 _('total cache data size %s, on-disk %s\n') % (
1506 ) 1510 util.bytecount(totalsize), util.bytecount(ondisk))
1511 )
1507 1512
1508 @command('debugmergestate', [], '') 1513 @command('debugmergestate', [], '')
1509 def debugmergestate(ui, repo, *args): 1514 def debugmergestate(ui, repo, *args):
1510 """print merge state 1515 """print merge state
1511 1516