genericcaches: handle the lack of util.timer in 4.1
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 12 Dec 2017 01:10:44 +0100
changeset 3279 4a9718a83602
parent 3276 26b604d7e1a8
child 3280 e642bad8174a
genericcaches: handle the lack of util.timer in 4.1 We do the same trick as usual.
hgext3rd/evolve/genericcaches.py
--- 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)