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.
--- a/mercurial/debugcommands.py Thu Mar 14 10:24:51 2019 +0000
+++ b/mercurial/debugcommands.py Thu Mar 14 10:43:01 2019 +0000
@@ -1465,45 +1465,50 @@
], '')
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:
- cache = r._fulltextcache
+ return r._fulltextcache
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()
- if add:
+ if add:
+ with repo.lock():
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
- 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):
--- a/tests/test-manifest.t Thu Mar 14 10:24:51 2019 +0000
+++ b/tests/test-manifest.t Thu Mar 14 10:43:01 2019 +0000
@@ -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