caches: factorise the cache warming check
authorPierre-Yves David <pierre-yves.david@octobus.net>
Thu, 21 Dec 2017 02:01:58 +0100
changeset 3340 fd90e73bf79a
parent 3339 f0933cdf614d
child 3341 eadbe24a93f8
caches: factorise the cache warming check The old conditional was duplicated and hard to read. We factorise everything into the `utility` module.
hgext3rd/evolve/depthcache.py
hgext3rd/evolve/firstmergecache.py
hgext3rd/evolve/stablesort.py
hgext3rd/evolve/utility.py
--- a/hgext3rd/evolve/depthcache.py	Thu Dec 21 00:06:07 2017 +0100
+++ b/hgext3rd/evolve/depthcache.py	Thu Dec 21 02:01:58 2017 +0100
@@ -78,11 +78,7 @@
         if util.safehasattr(repo, 'updatecaches'):
             @localrepo.unfilteredmethod
             def updatecaches(self, tr=None):
-                if (repo.ui.configbool('experimental', 'obshashrange',
-                                       False)
-                        and repo.ui.configbool('experimental',
-                                               'obshashrange.warm-cache',
-                                               True)):
+                if utility.shouldwarmcache(repo):
                     self.depthcache.update(repo)
                     self.depthcache.save(repo)
                 super(depthcacherepo, self).updatecaches(tr)
@@ -98,11 +94,7 @@
                         return
                     repo = repo.unfiltered()
 
-                if (repo.ui.configbool('experimental', 'obshashrange',
-                                       False)
-                        and repo.ui.configbool('experimental',
-                                               'obshashrange.warm-cache',
-                                               True)):
+                if utility.shouldwarmcache(repo):
                     tr.addpostclose('warmcache-00depthcache', _warmcache)
                 return tr
 
--- a/hgext3rd/evolve/firstmergecache.py	Thu Dec 21 00:06:07 2017 +0100
+++ b/hgext3rd/evolve/firstmergecache.py	Thu Dec 21 02:01:58 2017 +0100
@@ -40,11 +40,7 @@
         if util.safehasattr(repo, 'updatecaches'):
             @localrepo.unfilteredmethod
             def updatecaches(self, tr=None):
-                if (repo.ui.configbool('experimental', 'obshashrange',
-                                       False)
-                        and repo.ui.configbool('experimental',
-                                               'obshashrange.warm-cache',
-                                               True)):
+                if utility.shouldwarmcache(repo):
                     self.firstmergecache.update(repo)
                     self.firstmergecache.save(repo)
                 super(firstmergecacherepo, self).updatecaches(tr)
@@ -62,11 +58,7 @@
                     self.firstmergecache.update(repo)
                     self.firstmergecache.save(repo)
 
-                if (repo.ui.configbool('experimental', 'obshashrange',
-                                       False)
-                        and repo.ui.configbool('experimental',
-                                               'obshashrange.warm-cache',
-                                               True)):
+                if utility.shouldwarmcache(repo):
                     tr.addpostclose('warmcache-01-firstparentcache', _warmcache)
                 return tr
 
--- a/hgext3rd/evolve/stablesort.py	Thu Dec 21 00:06:07 2017 +0100
+++ b/hgext3rd/evolve/stablesort.py	Thu Dec 21 02:01:58 2017 +0100
@@ -671,11 +671,7 @@
         if util.safehasattr(repo, 'updatecaches'):
             @localrepo.unfilteredmethod
             def updatecaches(self, tr=None):
-                if (repo.ui.configbool('experimental', 'obshashrange',
-                                       False)
-                        and repo.ui.configbool('experimental',
-                                               'obshashrange.warm-cache',
-                                               True)):
+                if utility.shouldwarmcache(repo):
                     self.stablesort.update(repo)
                     self.stablesort.save(repo)
                 super(stablesortrepo, self).updatecaches(tr)
@@ -691,11 +687,7 @@
                         return
                     repo = repo.unfiltered()
 
-                if (repo.ui.configbool('experimental', 'obshashrange',
-                                       False)
-                        and repo.ui.configbool('experimental',
-                                               'obshashrange.warm-cache',
-                                               True)):
+                if utility.shouldwarmcache(repo):
                     tr.addpostclose('warmcache-02stablesort', _warmcache)
                 return tr
 
--- a/hgext3rd/evolve/utility.py	Thu Dec 21 00:06:07 2017 +0100
+++ b/hgext3rd/evolve/utility.py	Thu Dec 21 02:01:58 2017 +0100
@@ -36,3 +36,11 @@
         return (p2,)
     else:
         return parents
+
+def shouldwarmcache(repo):
+    configbool = repo.ui.configbool
+    if not configbool('experimental', 'obshashrange', False):
+        return False
+    if not configbool('experimental', 'obshashrange.warm-cache', True):
+        return False
+    return True