hgext3rd/evolve/stablerange.py
branchstable
changeset 2424 4afbcdcfa9b2
parent 2400 9a53ed7e5540
child 2503 cdf6a0e028c0
--- a/hgext3rd/evolve/stablerange.py	Thu May 18 22:12:05 2017 +0200
+++ b/hgext3rd/evolve/stablerange.py	Thu May 18 22:42:13 2017 +0200
@@ -10,7 +10,9 @@
 import collections
 import heapq
 import math
+import os
 import sqlite3
+import time
 import weakref
 
 from mercurial import (
@@ -19,6 +21,7 @@
     error,
     localrepo,
     node as nodemod,
+    pycompat,
     scmutil,
     util,
 )
@@ -31,6 +34,16 @@
 
 eh = exthelper.exthelper()
 
+# 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
+
 ##################################
 ### Stable topological sorting ###
 ##################################
@@ -263,7 +276,7 @@
         #
         # we use the revnumber as an approximation for depth
         ui = repo.ui
-        starttime = util.timer()
+        starttime = timer()
 
         if upto is None:
             upto = len(cl) - 1
@@ -309,7 +322,7 @@
         self._tiprev = upto
         self._tipnode = cl.node(upto)
 
-        duration = util.timer() - starttime
+        duration = timer() - starttime
         repo.ui.log('evoext-cache', 'updated stablerange cache in %.4f seconds\n',
                     duration)