##// END OF EJS Templates
py3: remove xrange() compatibility code...
Manuel Jacob -
r50180:56f98406 default
parent child Browse files
Show More
@@ -14,11 +14,6 b' from mercurial import ('
14 14
15 15 from hgext import rebase
16 16
17 try:
18 xrange
19 except NameError:
20 xrange = range
21
22 17 cmdtable = {}
23 18 command = registrar.command(cmdtable)
24 19
@@ -41,7 +36,7 b' def debugbruterebase(ui, repo, source, d'
41 36 result += b"'"
42 37 return result
43 38
44 for i in xrange(1, 2 ** len(srevs)):
39 for i in range(1, 2 ** len(srevs)):
45 40 subset = [rev for j, rev in enumerate(srevs) if i & (1 << j) != 0]
46 41 spec = revsetlang.formatspec(b'%ld', subset)
47 42 tr = repo.transaction(b'rebase')
@@ -58,7 +53,7 b' def debugbruterebase(ui, repo, source, d'
58 53 # short summary about new nodes
59 54 cl = repo.changelog
60 55 descs = []
61 for rev in xrange(repolen, len(repo)):
56 for rev in range(repolen, len(repo)):
62 57 desc = b'%s:' % getdesc(rev)
63 58 for prev in cl.parentrevs(rev):
64 59 if prev > -1:
@@ -26,7 +26,6 b" osenvironb = getattr(os, 'environb', os."
26 26
27 27 if sys.version_info > (3, 5, 0):
28 28 PYTHON3 = True
29 xrange = range # we use xrange in one place, and we'd rather not use range
30 29
31 30 def _sys2bytes(p):
32 31 return p.encode('utf-8')
@@ -151,9 +151,6 b' if pygmentspresent:'
151 151 origenviron = os.environ.copy()
152 152
153 153
154 xrange = range # we use xrange in one place, and we'd rather not use range
155
156
157 154 def _sys2bytes(p):
158 155 if p is None:
159 156 return p
@@ -1422,7 +1419,7 b' class Test(unittest.TestCase):'
1422 1419 env['HGTEST_TIMEOUT_DEFAULT'] = formated_timeout
1423 1420 env['HGTEST_TIMEOUT'] = _bytes2sys(b"%d" % self._timeout)
1424 1421 # This number should match portneeded in _getport
1425 for port in xrange(3):
1422 for port in range(3):
1426 1423 # This list should be parallel to _portmap in _getreplacements
1427 1424 defineport(port)
1428 1425 env["HGRCPATH"] = _bytes2sys(os.path.join(self._threadtmp, b'.hgrc'))
@@ -2503,7 +2500,7 b' class TestSuite(unittest.TestSuite):'
2503 2500
2504 2501 if ignored:
2505 2502 continue
2506 for _ in xrange(self._runs_per_test):
2503 for _ in range(self._runs_per_test):
2507 2504 tests.append(get())
2508 2505
2509 2506 runtests = list(tests)
@@ -2552,7 +2549,7 b' class TestSuite(unittest.TestSuite):'
2552 2549 with iolock:
2553 2550 sys.stdout.write(d + ' ')
2554 2551 sys.stdout.flush()
2555 for x in xrange(10):
2552 for x in range(10):
2556 2553 if channels:
2557 2554 time.sleep(0.1)
2558 2555 count += 1
@@ -3502,10 +3499,10 b' class TestRunner:'
3502 3499 if port is None:
3503 3500 portneeded = 3
3504 3501 # above 100 tries we just give up and let test reports failure
3505 for tries in xrange(100):
3502 for tries in range(100):
3506 3503 allfree = True
3507 3504 port = self.options.port + self._portoffset
3508 for idx in xrange(portneeded):
3505 for idx in range(portneeded):
3509 3506 if not checkportisavailable(port + idx):
3510 3507 allfree = False
3511 3508 break
@@ -19,9 +19,6 b' try:'
19 19 except ImportError:
20 20 pass
21 21
22 if sys.version_info[0] >= 3:
23 xrange = range
24
25 22 start = 1
26 23 if len(sys.argv) > 2:
27 24 start = int(sys.argv[1])
@@ -32,5 +29,5 b' if len(sys.argv) > 3:'
32 29
33 30 stop = int(sys.argv[-1]) + 1
34 31
35 for i in xrange(start, stop, step):
32 for i in range(start, stop, step):
36 33 print(i)
@@ -18,7 +18,6 b' from mercurial import ('
18 18
19 19 if pycompat.ispy3:
20 20 long = int
21 xrange = range
22 21
23 22
24 23 def buildgraph(rng, nodes=100, rootprob=0.05, mergeprob=0.2, prevprob=0.7):
@@ -30,7 +29,7 b' def buildgraph(rng, nodes=100, rootprob='
30 29 return value is a graph represented as an adjacency list.
31 30 """
32 31 graph = [None] * nodes
33 for i in xrange(nodes):
32 for i in range(nodes):
34 33 if i == 0 or rng.random() < rootprob:
35 34 graph[i] = [nullrev]
36 35 elif i == 1:
@@ -53,7 +52,7 b' def buildgraph(rng, nodes=100, rootprob='
53 52
54 53 def buildancestorsets(graph):
55 54 ancs = [None] * len(graph)
56 for i in xrange(len(graph)):
55 for i in range(len(graph)):
57 56 ancs[i] = {i}
58 57 if graph[i] == [nullrev]:
59 58 continue
@@ -114,11 +113,11 b' def test_missingancestors(seed, rng):'
114 113 nerrs[0] += 1
115 114 gerrs[0] += 1
116 115
117 for g in xrange(graphcount):
116 for g in range(graphcount):
118 117 graph = buildgraph(rng)
119 118 ancs = buildancestorsets(graph)
120 119 gerrs = [0]
121 for _ in xrange(testcount):
120 for _ in range(testcount):
122 121 # start from nullrev to include it as a possibility
123 122 graphnodes = range(nullrev, len(graph))
124 123 bases = samplerevs(graphnodes)
@@ -128,7 +127,7 b' def test_missingancestors(seed, rng):'
128 127 # reference slow algorithm
129 128 naiveinc = naiveincrementalmissingancestors(ancs, bases)
130 129 seq = []
131 for _ in xrange(inccount):
130 for _ in range(inccount):
132 131 if rng.random() < 0.2:
133 132 newbases = samplerevs(graphnodes)
134 133 seq.append(('addbases', newbases))
@@ -215,7 +214,7 b' def test_missingancestors_explicit():'
215 214 """
216 215 for i, (bases, revs) in enumerate(
217 216 (
218 ({1, 2, 3, 4, 7}, set(xrange(10))),
217 ({1, 2, 3, 4, 7}, set(range(10))),
219 218 ({10}, set({11, 12, 13, 14})),
220 219 ({7}, set({1, 2, 3, 4, 5})),
221 220 )
@@ -6,15 +6,11 b' import tempfile'
6 6 import unittest
7 7
8 8 from mercurial import (
9 pycompat,
10 9 util,
11 10 )
12 11
13 12 atomictempfile = util.atomictempfile
14 13
15 if pycompat.ispy3:
16 xrange = range
17
18 14
19 15 class testatomictempfile(unittest.TestCase):
20 16 def setUp(self):
@@ -68,7 +64,7 b' class testatomictempfile(unittest.TestCa'
68 64
69 65 # try some times, because reproduction of ambiguity depends on
70 66 # "filesystem time"
71 for i in xrange(5):
67 for i in range(5):
72 68 atomicwrite(False)
73 69 oldstat = os.stat(self._filename)
74 70 if oldstat[stat.ST_CTIME] != oldstat[stat.ST_MTIME]:
@@ -79,7 +75,7 b' class testatomictempfile(unittest.TestCa'
79 75
80 76 # repeat atomic write with checkambig=True, to examine
81 77 # whether st_mtime is advanced multiple times as expected
82 for j in xrange(repetition):
78 for j in range(repetition):
83 79 atomicwrite(True)
84 80 newstat = os.stat(self._filename)
85 81 if oldstat[stat.ST_CTIME] != newstat[stat.ST_CTIME]:
@@ -8,9 +8,6 b' from mercurial import ('
8 8
9 9 from hgext.fastannotate import error, revmap
10 10
11 if pycompat.ispy3:
12 xrange = range
13
14 11
15 12 def genhsh(i):
16 13 return pycompat.bytechr(i) + b'\0' * 19
@@ -33,7 +30,7 b' def testbasicreadwrite():'
33 30
34 31 rm = revmap.revmap(path)
35 32 ensure(rm.maxrev == 0)
36 for i in xrange(5):
33 for i in range(5):
37 34 ensure(rm.rev2hsh(i) is None)
38 35 ensure(rm.hsh2rev(b'\0' * 20) is None)
39 36
@@ -51,11 +48,11 b' def testbasicreadwrite():'
51 48 b'a',
52 49 b'a',
53 50 ]
54 for i in xrange(1, 5):
51 for i in range(1, 5):
55 52 ensure(rm.append(genhsh(i), sidebranch=(i & 1), path=paths[i]) == i)
56 53
57 54 ensure(rm.maxrev == 4)
58 for i in xrange(1, 5):
55 for i in range(1, 5):
59 56 ensure(rm.hsh2rev(genhsh(i)) == i)
60 57 ensure(rm.rev2hsh(i) == genhsh(i))
61 58
@@ -63,13 +60,13 b' def testbasicreadwrite():'
63 60 rm.flush()
64 61 rm = revmap.revmap(path)
65 62 ensure(rm.maxrev == 4)
66 for i in xrange(1, 5):
63 for i in range(1, 5):
67 64 ensure(rm.hsh2rev(genhsh(i)) == i)
68 65 ensure(rm.rev2hsh(i) == genhsh(i))
69 66 ensure(bool(rm.rev2flag(i) & revmap.sidebranchflag) == bool(i & 1))
70 67
71 68 # append without calling save() explicitly
72 for i in xrange(5, 12):
69 for i in range(5, 12):
73 70 ensure(
74 71 rm.append(genhsh(i), sidebranch=(i & 1), path=paths[i], flush=True)
75 72 == i
@@ -78,7 +75,7 b' def testbasicreadwrite():'
78 75 # re-load and verify
79 76 rm = revmap.revmap(path)
80 77 ensure(rm.maxrev == 11)
81 for i in xrange(1, 12):
78 for i in range(1, 12):
82 79 ensure(rm.hsh2rev(genhsh(i)) == i)
83 80 ensure(rm.rev2hsh(i) == genhsh(i))
84 81 ensure(rm.rev2path(i) == paths[i] or paths[i - 1])
@@ -148,7 +145,7 b' def testcorruptformat():'
148 145 def testcopyfrom():
149 146 path = gettemppath()
150 147 rm = revmap.revmap(path)
151 for i in xrange(1, 10):
148 for i in range(1, 10):
152 149 ensure(
153 150 rm.append(genhsh(i), sidebranch=(i & 1), path=(b'%d' % (i // 3)))
154 151 == i
@@ -185,21 +182,21 b' def testcontains():'
185 182 path = gettemppath()
186 183
187 184 rm = revmap.revmap(path)
188 for i in xrange(1, 5):
185 for i in range(1, 5):
189 186 ensure(rm.append(genhsh(i), sidebranch=(i & 1)) == i)
190 187
191 for i in xrange(1, 5):
188 for i in range(1, 5):
192 189 ensure(((genhsh(i), None) in rm) == ((i & 1) == 0))
193 190 ensure((fakefctx(genhsh(i)) in rm) == ((i & 1) == 0))
194 for i in xrange(5, 10):
191 for i in range(5, 10):
195 192 ensure(fakefctx(genhsh(i)) not in rm)
196 193 ensure((genhsh(i), None) not in rm)
197 194
198 195 # "contains" checks paths
199 196 rm = revmap.revmap()
200 for i in xrange(1, 5):
197 for i in range(1, 5):
201 198 ensure(rm.append(genhsh(i), path=(b'%d' % (i // 2))) == i)
202 for i in xrange(1, 5):
199 for i in range(1, 5):
203 200 ensure(fakefctx(genhsh(i), path=(b'%d' % (i // 2))) in rm)
204 201 ensure(fakefctx(genhsh(i), path=b'a') not in rm)
205 202
@@ -209,7 +206,7 b' def testlastnode():'
209 206 ensure(revmap.getlastnode(path) is None)
210 207 rm = revmap.revmap(path)
211 208 ensure(revmap.getlastnode(path) is None)
212 for i in xrange(1, 10):
209 for i in range(1, 10):
213 210 hsh = genhsh(i)
214 211 rm.append(hsh, path=(b'%d' % (i // 2)), flush=True)
215 212 ensure(revmap.getlastnode(path) == hsh)
@@ -31,9 +31,6 b' from mercurial import ('
31 31 vfs as vfsmod,
32 32 )
33 33
34 if pycompat.ispy3:
35 xrange = range
36
37 34
38 35 class fakerepo:
39 36 def __init__(self):
@@ -214,7 +211,7 b' def antiambiguity():'
214 211
215 212 # try some times, because reproduction of ambiguity depends on
216 213 # "filesystem time"
217 for i in xrange(5):
214 for i in range(5):
218 215 fp = open(filename, 'w')
219 216 fp.write('FOO')
220 217 fp.close()
@@ -228,7 +225,7 b' def antiambiguity():'
228 225
229 226 # repeat changing via checkambigatclosing, to examine whether
230 227 # st_mtime is advanced multiple times as expected
231 for i in xrange(repetition):
228 for i in range(repetition):
232 229 # explicit closing
233 230 fp = vfsmod.checkambigatclosing(open(filename, 'a'))
234 231 fp.write('FOO')
@@ -59,14 +59,12 b' A_DEEPER_MANIFEST = ('
59 59 HUGE_MANIFEST_ENTRIES = 200001
60 60
61 61 izip = getattr(itertools, 'izip', zip)
62 if 'xrange' not in globals():
63 xrange = range
64 62
65 63 A_HUGE_MANIFEST = b''.join(
66 64 sorted(
67 65 b'file%d\0%s%s\n' % (i, h, f)
68 66 for i, h, f in izip(
69 xrange(200001),
67 range(200001),
70 68 itertools.cycle((HASH_1, HASH_2)),
71 69 itertools.cycle((b'', b'x', b'l')),
72 70 )
@@ -19,11 +19,6 b' from mercurial import ('
19 19 store,
20 20 )
21 21
22 try:
23 xrange
24 except NameError:
25 xrange = range
26
27 22 validchars = set(map(pycompat.bytechr, range(0, 256)))
28 23 alphanum = range(ord('A'), ord('Z'))
29 24
@@ -32,8 +27,8 b" for c in (b'\\0', b'/'):"
32 27
33 28 winreserved = (
34 29 b'aux con prn nul'.split()
35 + [b'com%d' % i for i in xrange(1, 10)]
36 + [b'lpt%d' % i for i in xrange(1, 10)]
30 + [b'com%d' % i for i in range(1, 10)]
31 + [b'lpt%d' % i for i in range(1, 10)]
37 32 )
38 33
39 34
@@ -43,8 +38,8 b' def casecombinations(names):'
43 38 combos = set()
44 39
45 40 for r in names:
46 for i in xrange(len(r) + 1):
47 for c in itertools.combinations(xrange(len(r)), i):
41 for i in range(len(r) + 1):
42 for c in itertools.combinations(range(len(r)), i):
48 43 d = r
49 44 for j in c:
50 45 d = b''.join((d[:j], d[j : j + 1].upper(), d[j + 1 :]))
@@ -211,7 +206,7 b' def makepath(rng, j, k):'
211 206
212 207 return (
213 208 b'data/'
214 + b'/'.join(makepart(rng, k) for _ in xrange(j))
209 + b'/'.join(makepart(rng, k) for _ in range(j))
215 210 + rng.choice([b'.d', b'.i'])
216 211 )
217 212
@@ -222,7 +217,7 b' def genpath(rng, count):'
222 217 mink, maxk = 1, 4096
223 218
224 219 def steps():
225 for i in xrange(count):
220 for i in range(count):
226 221 yield mink + int(round(math.sqrt((maxk - mink) * float(i) / count)))
227 222
228 223 for k in steps():
@@ -18,8 +18,6 b''
18 18 > import os
19 19 > import shutil
20 20 > import sys
21 > if sys.version_info[0] > 2:
22 > xrange = range
23 21 > f = open('$TESTTMP/cachelog.log', 'w')
24 22 > srccache = os.path.join('$TESTTMP', 'oldhgcache')
25 23 > def log(message):
@@ -36,7 +34,7 b''
36 34 > count = int(sys.stdin.readline())
37 35 > log('client wants %r blobs\n' % count)
38 36 > wants = []
39 > for _ in xrange(count):
37 > for _ in range(count):
40 38 > key = sys.stdin.readline()[:-1]
41 39 > wants.append(key)
42 40 > if '\0' in key:
@@ -4,9 +4,6 b' from mercurial import ('
4 4 ui as uimod,
5 5 )
6 6
7 if pycompat.ispy3:
8 xrange = range
9
10 7 hgrc = os.environ['HGRCPATH']
11 8 f = open(hgrc)
12 9 basehgrc = f.read()
@@ -15,7 +12,7 b' f.close()'
15 12 print(' hgrc settings command line options final result ')
16 13 print(' quiet verbo debug quiet verbo debug quiet verbo debug')
17 14
18 for i in xrange(64):
15 for i in range(64):
19 16 hgrc_quiet = bool(i & 1 << 0)
20 17 hgrc_verbose = bool(i & 1 << 1)
21 18 hgrc_debug = bool(i & 1 << 2)
General Comments 0
You need to be logged in to leave comments. Login now