Mercurial > evolve
changeset 3279:4a9718a83602
genericcaches: handle the lack of util.timer in 4.1
We do the same trick as usual.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 12 Dec 2017 01:10:44 +0100 |
parents | 26b604d7e1a8 |
children | e642bad8174a |
files | hgext3rd/evolve/genericcaches.py |
diffstat | 1 files changed, 15 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext3rd/evolve/genericcaches.py Mon Dec 11 15:49:22 2017 +0100 +++ b/hgext3rd/evolve/genericcaches.py Tue Dec 12 01:10:44 2017 +0100 @@ -8,12 +8,25 @@ import abc import struct +import time +import os from mercurial import ( node, + pycompat, util, ) +# prior to hg-4.2 there are not util.timer +if util.safehasattr(util, 'timer'): + timer = util.timer +elif util.safehasattr(time, "perf_counter"): + timer = time.perf_counter +elif getattr(pycompat, 'osname', os.name) == 'nt': + timer = time.clock +else: + timer = time.time + class incrementalcachebase(object): """base class for incremental cache from append only source @@ -116,9 +129,9 @@ % self._cachename) self.clear(reset=True) - starttime = util.timer() + starttime = timer() self._updatefrom(repo, data) - duration = util.timer() - starttime + duration = timer() - starttime summary = self._updatesummary(data) repo.ui.log('cache', 'updated %s in %.4f seconds (%s)\n', self._cachename, duration, summary)