# HG changeset patch
# User Durham Goode <dur...@fb.com>
# Date 1474400113 25200
#      Tue Sep 20 12:35:13 2016 -0700
# Node ID 22915866409350cbb5302289c05bb65bc1bfd308
# Parent  52a206d772021194ab4356aeba2c73650851a624
manifest: change manifestlog mancache to be directory based

In the last patch we added a get() function that allows fetching directory level
treemanifestctxs. It didn't handle caching at directory level though, so we 
need to
change our mancache to support multiple directories.

diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -1021,9 +1021,16 @@ class manifestlog(object):
             usetreemanifest = opts.get('treemanifest', usetreemanifest)
         self._treeinmem = usetreemanifest
 
+        # A dictionary containing the cache for each directory
+        self._dirmancache = {}
+
         # We'll separate this into it's own cache once oldmanifest is no longer
         # used
-        self._mancache = repo.manifest._mancache
+        self._dirmancache[''] = repo.manifest._mancache
+
+        # A future patch makes this use the same config value as the existing
+        # mancache
+        self.cachesize = 4
 
     @property
     def _revlog(self):
@@ -1047,8 +1054,8 @@ class manifestlog(object):
                         _("cannot ask for manifest directory '%s' in a flat "
                           "manifest") % dir)
         else:
-            if node in self._mancache:
-                cachemf = self._mancache[node]
+            if node in self._dirmancache.get(dir, ()):
+                cachemf = self._dirmancache[dir][node]
                 # The old manifest may put non-ctx manifests in the cache, so
                 # skip those since they don't implement the full api.
                 if (isinstance(cachemf, manifestctx) or
@@ -1059,8 +1066,13 @@ class manifestlog(object):
                 m = treemanifestctx(self._revlog, '', node)
             else:
                 m = manifestctx(self._revlog, node)
-            if node != revlog.nullid:
-                self._mancache[node] = m
+
+        if node != revlog.nullid:
+            mancache = self._dirmancache.get(dir)
+            if not mancache:
+                mancache = util.lrucachedict(self.cachesize)
+                self._dirmancache[dir] = mancache
+            mancache[node] = m
         return m
 
     def add(self, m, transaction, link, p1, p2, added, removed):
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to