diff --git a/hgext/hgk.py b/hgext/hgk.py --- a/hgext/hgk.py +++ b/hgext/hgk.py @@ -221,18 +221,17 @@ def revtree(ui, args, repo, full="tree", # 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: diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -112,8 +112,8 @@ class patchheader(object): 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 @@ class queue: 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 @@ class queue: 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: diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py --- a/mercurial/mdiff.py +++ b/mercurial/mdiff.py @@ -185,7 +185,7 @@ def bunidiff(t1, t2, l1, l2, header1, he # 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 @@ def bunidiff(t1, t2, l1, l2, header1, he else: s = [0, 0, 0, 0] delta = [] - s1 = diff[i] a1 = s[1] a2 = s1[0] b1 = s[3] diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -307,8 +307,7 @@ class patchfile: 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): diff --git a/mercurial/pure/base85.py b/mercurial/pure/base85.py --- a/mercurial/pure/base85.py +++ b/mercurial/pure/base85.py @@ -13,8 +13,8 @@ import struct _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 @@ def b85decode(text): 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: