[PATCH 3 of 8 "] manifestcache: only lock the repository if the debug command touch the cache

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Mar 15 07:43:25 EDT 2019


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at octobus.net>
# Date 1552560181 0
#      Thu Mar 14 10:43:01 2019 +0000
# Node ID 6c6d0a2d336f2da651863b981bfc071adaa19c46
# Parent  c6026351ed8758dc931f5caf04dfe2b77d31cd7a
# EXP-Topic manifestcache
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 6c6d0a2d336f
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


More information about the Mercurial-devel mailing list