Mercurial > hg
changeset 8632:9e055cfdd620
replace "i in range(len(xs))" with "i, x in enumerate(xs)"
The remaining occurrences should be the ones where "xs" is mutated or
where "i" is used for index arithmetic.
author | Martin Geisler <mg@lazybytes.net> |
---|---|
date | Tue, 26 May 2009 22:59:52 +0200 |
parents | a87c41f65aff |
children | c31fe74a6633 |
files | hgext/hgk.py hgext/mq.py mercurial/mdiff.py mercurial/patch.py mercurial/pure/base85.py |
diffstat | 5 files changed, 20 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/hgk.py Tue May 26 22:37:26 2009 +0200 +++ b/hgext/hgk.py Tue May 26 22:59:52 2009 +0200 @@ -221,18 +221,17 @@ # figure out which commits they are asking for and which ones they # want us to stop on - for i in xrange(len(args)): - if args[i].startswith('^'): - s = repo.lookup(args[i][1:]) + for i, arg in enumerate(args): + if arg.startswith('^'): + s = repo.lookup(arg[1:]) stop_sha1.append(s) want_sha1.append(s) - elif args[i] != 'HEAD': - want_sha1.append(repo.lookup(args[i])) + elif arg != 'HEAD': + want_sha1.append(repo.lookup(arg)) # calculate the graph for the supplied commits - for i in xrange(len(want_sha1)): + for i, n in enumerate(want_sha1): reachable.append(set()); - n = want_sha1[i]; visit = [n]; reachable[i].add(n) while visit:
--- a/hgext/mq.py Tue May 26 22:37:26 2009 +0200 +++ b/hgext/mq.py Tue May 26 22:59:52 2009 +0200 @@ -112,8 +112,8 @@ self.message = self.message[2:] break ci = 0 - for mi in xrange(len(self.message)): - while self.message[mi] != self.comments[ci]: + for mi in self.message: + while mi != self.comments[ci]: ci += 1 del self.comments[ci] @@ -827,8 +827,7 @@ def isapplied(self, patch): """returns (index, rev, patch)""" - for i in xrange(len(self.applied)): - a = self.applied[i] + for i, a in enumerate(self.applied): if a.name == patch: return (i, a.rev, a.name) return None @@ -1407,15 +1406,15 @@ series = [] applied = [] qpp = None - for i in xrange(len(lines)): - if lines[i] == 'Patch Data:': + for i, line in enumerate(lines): + if line == 'Patch Data:': datastart = i + 1 - elif lines[i].startswith('Dirstate:'): - l = lines[i].rstrip() + elif line.startswith('Dirstate:'): + l = line.rstrip() l = l[10:].split(' ') qpp = [ bin(x) for x in l ] elif datastart != None: - l = lines[i].rstrip() + l = line.rstrip() se = statusentry(l) file_ = se.name if se.rev:
--- a/mercurial/mdiff.py Tue May 26 22:37:26 2009 +0200 +++ b/mercurial/mdiff.py Tue May 26 22:59:52 2009 +0200 @@ -185,7 +185,7 @@ # diff = bdiff.blocks(t1, t2) hunk = None - for i in xrange(len(diff)): + for i, s1 in enumerate(diff): # The first match is special. # we've either found a match starting at line 0 or a match later # in the file. If it starts later, old and new below will both be @@ -195,7 +195,6 @@ else: s = [0, 0, 0, 0] delta = [] - s1 = diff[i] a1 = s[1] a2 = s1[0] b1 = s[3]
--- a/mercurial/patch.py Tue May 26 22:37:26 2009 +0200 +++ b/mercurial/patch.py Tue May 26 22:59:52 2009 +0200 @@ -307,8 +307,7 @@ def hashlines(self): self.hash = {} - for x in xrange(len(self.lines)): - s = self.lines[x] + for x, s in enumerate(self.lines): self.hash.setdefault(s, []).append(x) def write_rej(self):
--- a/mercurial/pure/base85.py Tue May 26 22:37:26 2009 +0200 +++ b/mercurial/pure/base85.py Tue May 26 22:59:52 2009 +0200 @@ -13,8 +13,8 @@ _b85dec = {} def _mkb85dec(): - for i in range(len(_b85chars)): - _b85dec[_b85chars[i]] = i + for i, c in enumerate(_b85chars): + _b85dec[c] = i def b85encode(text, pad=False): """encode text in base85 format""" @@ -50,9 +50,9 @@ for i in range(0, len(text), 5): chunk = text[i:i+5] acc = 0 - for j in range(len(chunk)): + for j, c in enumerate(chunk): try: - acc = acc * 85 + _b85dec[chunk[j]] + acc = acc * 85 + _b85dec[c] except KeyError: raise TypeError('Bad base85 character at byte %d' % (i + j)) if acc > 4294967295: