compat: handle lack of 'util.timer' for pre 4.2 version
We keep compatibility with previous Mercurial version by redefining the timer
when needed.
--- a/hgext3rd/evolve/obscache.py Thu May 18 22:12:05 2017 +0200
+++ b/hgext3rd/evolve/obscache.py Thu May 18 22:42:13 2017 +0200
@@ -7,16 +7,19 @@
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
+import errno
import hashlib
+import os
import struct
+import time
import weakref
-import errno
from mercurial import (
error,
localrepo,
obsolete,
phases,
+ pycompat,
node,
util,
)
@@ -29,6 +32,17 @@
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
+
+
try:
obsstorefilecache = localrepo.localrepository.obsstore
except AttributeError:
@@ -209,9 +223,9 @@
repo.ui.log('evoext-cache', 'strip detected, %s cache reset\n' % self._cachename)
self.clear(reset=True)
- starttime = util.timer()
+ starttime = timer()
self._updatefrom(repo, revs, obsmarkers)
- duration = util.timer() - starttime
+ duration = timer() - starttime
repo.ui.log('evoext-cache', 'updated %s in %.4f seconds (%sr, %so)\n',
self._cachename, duration, len(revs), len(obsmarkers))
--- a/hgext3rd/evolve/obsdiscovery.py Thu May 18 22:12:05 2017 +0200
+++ b/hgext3rd/evolve/obsdiscovery.py Thu May 18 22:42:13 2017 +0200
@@ -24,8 +24,10 @@
import hashlib
import heapq
+import os
import sqlite3
import struct
+import time
import weakref
from mercurial import (
@@ -36,6 +38,7 @@
localrepo,
node,
obsolete,
+ pycompat,
scmutil,
setdiscovery,
util,
@@ -51,6 +54,16 @@
stablerange,
)
+# 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
+
_pack = struct.pack
_unpack = struct.unpack
_calcsize = struct.calcsize
@@ -215,7 +228,7 @@
initialsamplesize=100,
fullsamplesize=200):
missing = set()
- starttime = util.timer()
+ starttime = timer()
heads = local.revs('heads(%ld)', probeset)
local.stablerange.warmup(local)
@@ -303,7 +316,7 @@
ui.progress(_("comparing obsmarker with other"), querycount)
ui.progress(_("comparing obsmarker with other"), None)
local.obsstore.rangeobshashcache.save(local)
- duration = util.timer() - starttime
+ duration = timer() - starttime
logmsg = ('obsdiscovery, %d/%d mismatch'
' - %d obshashrange queries in %.4f seconds\n')
logmsg %= (len(missing), len(probeset), querycount, duration)
--- 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)