Patchwork [2,of,2] debugupdatecache: also warm rev branch cache

login
register
mail settings
Submitter Boris Feld
Date March 14, 2018, 3:37 p.m.
Message ID <c76963db79b393830c8f.1521041845@FB>
Download mbox | patch
Permalink /patch/29498/
State Accepted
Headers show

Comments

Boris Feld - March 14, 2018, 3:37 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1519230070 -3600
#      Wed Feb 21 17:21:10 2018 +0100
# Node ID c76963db79b393830c8f460baec7efcb39049d86
# Parent  894cf14ad5d770100eecf112cff94c7a7b19679b
# EXP-Topic debug-improvement
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r c76963db79b3
debugupdatecache: also warm rev branch cache

We add basic code to have `debugupdatecache` ensure that the rev branch cache
is fully warmed. This only affects the `debugupdatecache` command, not normal
transaction operation.
Yuya Nishihara - March 15, 2018, 1:55 p.m.
On Wed, 14 Mar 2018 16:37:25 +0100, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1519230070 -3600
> #      Wed Feb 21 17:21:10 2018 +0100
> # Node ID c76963db79b393830c8f460baec7efcb39049d86
> # Parent  894cf14ad5d770100eecf112cff94c7a7b19679b
> # EXP-Topic debug-improvement
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r c76963db79b3
> debugupdatecache: also warm rev branch cache

Queued, thanks.

>      @unfilteredmethod
> -    def updatecaches(self, tr=None):
> +    def updatecaches(self, tr=None, full=False):
>          """warm appropriate caches
>  
>          If this function is called after a transaction closed. The transaction
>          will be available in the 'tr' argument. This can be used to selectively
>          update caches relevant to the changes in that transaction.
> +
> +        If 'full' is set, make sure all caches the function knows about have
> +        up-to-date data. Even the ones usually loaded more lazily.
>          """
>          if tr is not None and tr.hookargs.get('source') == 'strip':
>              # During strip, many caches are invalid but
> @@ -1536,6 +1539,12 @@ class localrepository(object):
>              self.ui.debug('updating the branch cache\n')
>              branchmap.updatecache(self.filtered('served'))
>  
> +        if full:
> +            rbc = self.revbranchcache()
> +            for r in self.changelog:
> +                rbc.branchinfo(r)
> +            rbc.write()

I slightly prefer making it a revbranchcache function.

Patch

diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -2482,7 +2482,7 @@  def debuguiprompt(ui, prompt=''):
 def debugupdatecaches(ui, repo, *pats, **opts):
     """warm all known caches in the repository"""
     with repo.wlock(), repo.lock():
-        repo.updatecaches()
+        repo.updatecaches(full=True)
 
 @command('debugupgraderepo', [
     ('o', 'optimize', [], _('extra optimization to perform'), _('NAME')),
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1519,12 +1519,15 @@  class localrepository(object):
         return updater
 
     @unfilteredmethod
-    def updatecaches(self, tr=None):
+    def updatecaches(self, tr=None, full=False):
         """warm appropriate caches
 
         If this function is called after a transaction closed. The transaction
         will be available in the 'tr' argument. This can be used to selectively
         update caches relevant to the changes in that transaction.
+
+        If 'full' is set, make sure all caches the function knows about have
+        up-to-date data. Even the ones usually loaded more lazily.
         """
         if tr is not None and tr.hookargs.get('source') == 'strip':
             # During strip, many caches are invalid but
@@ -1536,6 +1539,12 @@  class localrepository(object):
             self.ui.debug('updating the branch cache\n')
             branchmap.updatecache(self.filtered('served'))
 
+        if full:
+            rbc = self.revbranchcache()
+            for r in self.changelog:
+                rbc.branchinfo(r)
+            rbc.write()
+
     def invalidatecaches(self):
 
         if '_tagscache' in vars(self):