# HG changeset patch # User Pierre-Yves David # Date 2019-03-14 10:43:01 # Node ID fbee66c90cef4eb4c8f594646ff444add240c1e7 # Parent 08fad2ca4eb60dcb897535db9bf8b6e8f7df2557 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. diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py --- a/mercurial/debugcommands.py +++ b/mercurial/debugcommands.py @@ -1465,45 +1465,50 @@ def debuglocks(ui, repo, **opts): ], '') 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): diff --git a/tests/test-manifest.t b/tests/test-manifest.t --- a/tests/test-manifest.t +++ b/tests/test-manifest.t @@ -107,3 +107,15 @@ Showing the content of the caches after $ 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