Skip to content
Snippets Groups Projects
Commit fbee66c9 authored by Pierre-Yves David's avatar Pierre-Yves David :octopus:
Browse files

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.
parent 08fad2ca
No related branches found
No related tags found
No related merge requests found
......@@ -1465,6 +1465,7 @@
], '')
def debugmanifestfulltextcache(ui, repo, add=None, **opts):
"""show, clear or amend the contents of the manifest fulltext cache"""
with repo.lock():
def getcache():
r = repo.manifestlog.getstorage(b'')
try:
......@@ -1469,4 +1470,4 @@
r = repo.manifestlog.getstorage(b'')
try:
cache = r._fulltextcache
return r._fulltextcache
except AttributeError:
......@@ -1472,9 +1473,10 @@
except AttributeError:
ui.warn(_(
"Current revlog implementation doesn't appear to have a "
'manifest fulltext cache\n'))
return
if opts.get(r'clear'):
msg = _("Current revlog implementation doesn't appear to have a "
"manifest fulltext cache\n")
raise error.Abort(msg)
if opts.get(r'clear'):
with repo.lock():
cache = getcache()
cache.clear()
......@@ -1479,4 +1481,5 @@
cache.clear()
if add:
if add:
with repo.lock():
try:
......@@ -1482,6 +1485,7 @@
try:
manifest = repo.manifestlog[r.lookup(add)]
m = repo.manifestlog
manifest = m[m.getstorage(b'').lookup(add)]
except error.LookupError as e:
raise error.Abort(e, hint="Check your manifest node id")
manifest.read() # stores revisision in cache too
......@@ -1484,26 +1488,27 @@
except error.LookupError as e:
raise error.Abort(e, hint="Check your manifest node id")
manifest.read() # stores revisision in cache too
if not len(cache):
ui.write(_('cache empty\n'))
else:
ui.write(
_('cache contains %d manifest entries, in order of most to '
'least recent:\n') % (len(cache),))
totalsize = 0
for nodeid in cache:
# Use cache.get to not update the LRU order
data = cache.get(nodeid)
size = len(data)
totalsize += size + 24 # 20 bytes nodeid, 4 bytes size
ui.write(_('id: %s, size %s\n') % (
hex(nodeid), util.bytecount(size)))
ondisk = cache._opener.stat('manifestfulltextcache').st_size
ui.write(
_('total cache data size %s, on-disk %s\n') % (
util.bytecount(totalsize), util.bytecount(ondisk))
)
cache = getcache()
if not len(cache):
ui.write(_('cache empty\n'))
else:
ui.write(
_('cache contains %d manifest entries, in order of most to '
'least recent:\n') % (len(cache),))
totalsize = 0
for nodeid in cache:
# Use cache.get to not update the LRU order
data = cache.get(nodeid)
size = len(data)
totalsize += size + 24 # 20 bytes nodeid, 4 bytes size
ui.write(_('id: %s, size %s\n') % (
hex(nodeid), util.bytecount(size)))
ondisk = cache._opener.stat('manifestfulltextcache').st_size
ui.write(
_('total cache data size %s, on-disk %s\n') % (
util.bytecount(totalsize), util.bytecount(ondisk))
)
@command('debugmergestate', [], '')
def debugmergestate(ui, repo, *args):
......
......@@ -107,3 +107,15 @@
$ hg debugmanifestfulltextcache
cache empty
Adding a new persistent entry in the cache
$ hg debugmanifestfulltextcache --add 1e01206b1d2f72bd55f2a33fa8ccad74144825b7
cache contains 1 manifest entries, in order of most to least recent:
id: 1e01206b1d2f72bd55f2a33fa8ccad74144825b7, size 133 bytes
total cache data size 157 bytes, on-disk 157 bytes
$ hg debugmanifestfulltextcache
cache contains 1 manifest entries, in order of most to least recent:
id: 1e01206b1d2f72bd55f2a33fa8ccad74144825b7, size 133 bytes
total cache data size 157 bytes, on-disk 157 bytes
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment