caches: factorise the cache warming check
The old conditional was duplicated and hard to read. We factorise everything
into the `utility` module.
--- 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