Mercurial > evolve
changeset 3340:fd90e73bf79a
caches: factorise the cache warming check
The old conditional was duplicated and hard to read. We factorise everything
into the `utility` module.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 21 Dec 2017 02:01:58 +0100 |
parents | f0933cdf614d |
children | eadbe24a93f8 |
files | hgext3rd/evolve/depthcache.py hgext3rd/evolve/firstmergecache.py hgext3rd/evolve/stablesort.py hgext3rd/evolve/utility.py |
diffstat | 4 files changed, 14 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- 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