changeset 47296:d1589957fdcb

updatecaches: introduce a set of constants to control which are updated Passing around a set of constant to select what need warming will be cleaner and more flexible. We did not changed the API yet, as this changes is already large enough. In the rest of the rest we will change more code to actually use this constants (or more realistically pre-defined set of constant directly) Differential Revision: https://phab.mercurial-scm.org/D10727
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 17 May 2021 14:41:09 +0200
parents dd339191f2dc
children 1337bfaa88ca
files mercurial/interfaces/repository.py mercurial/localrepo.py
diffstat 2 files changed, 76 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/interfaces/repository.py	Tue May 18 21:50:09 2021 -0700
+++ b/mercurial/interfaces/repository.py	Mon May 17 14:41:09 2021 +0200
@@ -1,4 +1,5 @@
 # repository.py - Interfaces and base classes for repositories and peers.
+# coding: utf-8
 #
 # Copyright 2017 Gregory Szorc <gregory.szorc@gmail.com>
 #
@@ -44,6 +45,49 @@
 CG_DELTAMODE_P1 = b'p1'
 
 
+## Cache related constants:
+#
+# Used to control which cache should be warmed in a repo.updatecaches(…) call.
+
+# Warm branchmaps of all known repoview's filter-level
+CACHE_BRANCHMAP_ALL = b"branchmap-all"
+# Warm branchmaps of repoview's filter-level used by server
+CACHE_BRANCHMAP_SERVED = b"branchmap-served"
+# Warm internal changelog cache (eg: persistent nodemap)
+CACHE_CHANGELOG_CACHE = b"changelog-cache"
+# Warm full manifest cache
+CACHE_FULL_MANIFEST = b"full-manifest"
+# Warm file-node-tags cache
+CACHE_FILE_NODE_TAGS = b"file-node-tags"
+# Warm internal manifestlog cache (eg: persistent nodemap)
+CACHE_MANIFESTLOG_CACHE = b"manifestlog-cache"
+# Warn rev branch cache
+CACHE_REV_BRANCH = b"rev-branch-cache"
+# Warm tags' cache for default repoview'
+CACHE_TAGS_DEFAULT = b"tags-default"
+# Warm tags' cache for  repoview's filter-level used by server
+CACHE_TAGS_SERVED = b"tags-served"
+
+# the cache to warm by default after a simple transaction
+# (this is a mutable set to let extension update it)
+CACHES_DEFAULT = {
+    CACHE_BRANCHMAP_SERVED,
+}
+
+# the caches to warm when warming all of them
+# (this is a mutable set to let extension update it)
+CACHES_ALL = {
+    CACHE_BRANCHMAP_SERVED,
+    CACHE_BRANCHMAP_ALL,
+    CACHE_CHANGELOG_CACHE,
+    CACHE_FILE_NODE_TAGS,
+    CACHE_FULL_MANIFEST,
+    CACHE_MANIFESTLOG_CACHE,
+    CACHE_TAGS_DEFAULT,
+    CACHE_TAGS_SERVED,
+}
+
+
 class ipeerconnection(interfaceutil.Interface):
     """Represents a "connection" to a repository.
 
--- a/mercurial/localrepo.py	Tue May 18 21:50:09 2021 -0700
+++ b/mercurial/localrepo.py	Mon May 17 14:41:09 2021 +0200
@@ -2752,40 +2752,56 @@
             # later call to `destroyed` will refresh them.
             return
 
-        if tr is None or tr.changes[b'origrepolen'] < len(self):
-            # accessing the 'served' branchmap should refresh all the others,
-            self.ui.debug(b'updating the branch cache\n')
-            self.filtered(b'served').branchmap()
-            self.filtered(b'served.hidden').branchmap()
+        unfi = self.unfiltered()
 
         if full:
-            unfi = self.unfiltered()
-
+            caches = repository.CACHES_ALL
+            if full == b"post-clone":
+                caches = caches.copy()
+                caches.discard(repository.CACHE_FILE_NODE_TAGS)
+        else:
+            caches = repository.CACHES_DEFAULT
+
+        if repository.CACHE_BRANCHMAP_SERVED in caches:
+            if tr is None or tr.changes[b'origrepolen'] < len(self):
+                # accessing the 'served' branchmap should refresh all the others,
+                self.ui.debug(b'updating the branch cache\n')
+                self.filtered(b'served').branchmap()
+                self.filtered(b'served.hidden').branchmap()
+
+        if repository.CACHE_CHANGELOG_CACHE in caches:
             self.changelog.update_caches(transaction=tr)
+
+        if repository.CACHE_MANIFESTLOG_CACHE in caches:
             self.manifestlog.update_caches(transaction=tr)
 
+        if repository.CACHE_REV_BRANCH in caches:
             rbc = unfi.revbranchcache()
             for r in unfi.changelog:
                 rbc.branchinfo(r)
             rbc.write()
 
+        if repository.CACHE_FULL_MANIFEST in caches:
             # ensure the working copy parents are in the manifestfulltextcache
             for ctx in self[b'.'].parents():
                 ctx.manifest()  # accessing the manifest is enough
 
-            if not full == b"post-clone":
-                # accessing fnode cache warms the cache
-                tagsmod.fnoderevs(self.ui, unfi, unfi.changelog.revs())
+        if repository.CACHE_FILE_NODE_TAGS in caches:
+            # accessing fnode cache warms the cache
+            tagsmod.fnoderevs(self.ui, unfi, unfi.changelog.revs())
+
+        if repository.CACHE_TAGS_DEFAULT in caches:
             # accessing tags warm the cache
             self.tags()
+        if repository.CACHE_TAGS_SERVED in caches:
             self.filtered(b'served').tags()
 
-            # The `full` arg is documented as updating even the lazily-loaded
-            # caches immediately, so we're forcing a write to cause these caches
-            # to be warmed up even if they haven't explicitly been requested
-            # yet (if they've never been used by hg, they won't ever have been
-            # written, even if they're a subset of another kind of cache that
-            # *has* been used).
+        if repository.CACHE_BRANCHMAP_ALL in caches:
+            # The CACHE_BRANCHMAP_ALL updates lazily-loaded caches immediately,
+            # so we're forcing a write to cause these caches to be warmed up
+            # even if they haven't explicitly been requested yet (if they've
+            # never been used by hg, they won't ever have been written, even if
+            # they're a subset of another kind of cache that *has* been used).
             for filt in repoview.filtertable.keys():
                 filtered = self.filtered(filt)
                 filtered.branchmap().write(filtered)