# HG changeset patch # User Pierre-Yves David # Date 1513818118 -3600 # Node ID fd90e73bf79ac4796ee0a03e9fdb8d7d15062ded # Parent f0933cdf614d06166c5ebba727c7e6a096a1e9eb caches: factorise the cache warming check The old conditional was duplicated and hard to read. We factorise everything into the `utility` module. diff -r f0933cdf614d -r fd90e73bf79a hgext3rd/evolve/depthcache.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 diff -r f0933cdf614d -r fd90e73bf79a hgext3rd/evolve/firstmergecache.py --- 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 diff -r f0933cdf614d -r fd90e73bf79a hgext3rd/evolve/stablesort.py --- 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 diff -r f0933cdf614d -r fd90e73bf79a hgext3rd/evolve/utility.py --- 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