diff --git a/hgext/acl.py b/hgext/acl.py --- a/hgext/acl.py +++ b/hgext/acl.py @@ -220,6 +220,7 @@ from mercurial import ( error, extensions, match, + pycompat, registrar, util, ) @@ -403,7 +404,7 @@ def _txnhook(ui, repo, hooktype, node, s allow = buildmatch(ui, repo, user, 'acl.allow') deny = buildmatch(ui, repo, user, 'acl.deny') - for rev in xrange(repo[node].rev(), len(repo)): + for rev in pycompat.xrange(repo[node].rev(), len(repo)): ctx = repo[rev] branch = ctx.branch() if denybranches and denybranches(branch): diff --git a/hgext/beautifygraph.py b/hgext/beautifygraph.py --- a/hgext/beautifygraph.py +++ b/hgext/beautifygraph.py @@ -18,6 +18,7 @@ from mercurial import ( encoding, extensions, graphmod, + pycompat, templatekw, ) @@ -53,7 +54,7 @@ def prettyedge(before, edge, after): def convertedges(line): line = ' %s ' % line pretty = [] - for idx in xrange(len(line) - 2): + for idx in pycompat.xrange(len(line) - 2): pretty.append(prettyedge(line[idx], line[idx + 1], line[idx + 2])) return ''.join(pretty) diff --git a/hgext/blackbox.py b/hgext/blackbox.py --- a/hgext/blackbox.py +++ b/hgext/blackbox.py @@ -45,6 +45,7 @@ from mercurial.node import hex from mercurial import ( encoding, + pycompat, registrar, ui as uimod, util, @@ -111,7 +112,7 @@ def _openlogfile(ui, vfs): if st.st_size >= maxsize: path = vfs.join(name) maxfiles = ui.configint('blackbox', 'maxfiles') - for i in xrange(maxfiles - 1, 1, -1): + for i in pycompat.xrange(maxfiles - 1, 1, -1): rotate(oldpath='%s.%d' % (path, i - 1), newpath='%s.%d' % (path, i)) rotate(oldpath=path, diff --git a/hgext/censor.py b/hgext/censor.py --- a/hgext/censor.py +++ b/hgext/censor.py @@ -32,6 +32,7 @@ from mercurial.node import short from mercurial import ( error, + pycompat, registrar, revlog, scmutil, @@ -160,7 +161,7 @@ def _docensor(ui, repo, path, rev='', to offset += rewrite(crev, offset, tombstone + pad, revlog.REVIDX_ISCENSORED) # Rewrite all following filelog revisions fixing up offsets and deltas. - for srev in xrange(crev + 1, len(flog)): + for srev in pycompat.xrange(crev + 1, len(flog)): if crev in flog.parentrevs(srev): # Immediate children of censored node must be re-added as fulltext. try: diff --git a/hgext/convert/cvsps.py b/hgext/convert/cvsps.py --- a/hgext/convert/cvsps.py +++ b/hgext/convert/cvsps.py @@ -763,7 +763,7 @@ def createchangeset(ui, log, fuzz=60, me # branchpoints such that it is the latest possible # commit without any intervening, unrelated commits. - for candidate in xrange(i): + for candidate in pycompat.xrange(i): if c.branch not in changesets[candidate].branchpoints: if p is not None: break diff --git a/hgext/eol.py b/hgext/eol.py --- a/hgext/eol.py +++ b/hgext/eol.py @@ -266,7 +266,7 @@ def _checkhook(ui, repo, node, headsonly ensureenabled(ui) files = set() revs = set() - for rev in xrange(repo[node].rev(), len(repo)): + for rev in pycompat.xrange(repo[node].rev(), len(repo)): revs.add(rev) if headsonly: ctx = repo[rev] diff --git a/hgext/hgk.py b/hgext/hgk.py --- a/hgext/hgk.py +++ b/hgext/hgk.py @@ -227,7 +227,7 @@ def revtree(ui, args, repo, full="tree", else: i -= chunk - for x in xrange(chunk): + for x in pycompat.xrange(chunk): if i + x >= count: l[chunk - x:] = [0] * (chunk - x) break @@ -238,7 +238,7 @@ def revtree(ui, args, repo, full="tree", else: if (i + x) in repo: l[x] = 1 - for x in xrange(chunk - 1, -1, -1): + for x in pycompat.xrange(chunk - 1, -1, -1): if l[x] != 0: yield (i + x, full is not None and l[x] or None) if i == 0: @@ -249,7 +249,7 @@ def revtree(ui, args, repo, full="tree", if len(ar) == 0: return 1 mask = 0 - for i in xrange(len(ar)): + for i in pycompat.xrange(len(ar)): if sha in reachable[i]: mask |= 1 << i diff --git a/hgext/histedit.py b/hgext/histedit.py --- a/hgext/histedit.py +++ b/hgext/histedit.py @@ -386,7 +386,7 @@ class histeditstate(object): rules = [] rulelen = int(lines[index]) index += 1 - for i in xrange(rulelen): + for i in pycompat.xrange(rulelen): ruleaction = lines[index] index += 1 rule = lines[index] @@ -397,7 +397,7 @@ class histeditstate(object): replacements = [] replacementlen = int(lines[index]) index += 1 - for i in xrange(replacementlen): + for i in pycompat.xrange(replacementlen): replacement = lines[index] original = node.bin(replacement[:40]) succ = [node.bin(replacement[i:i + 40]) for i in diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -414,7 +414,7 @@ class patchheader(object): the field and a blank line.''' if self.message: subj = 'subject: ' + self.message[0].lower() - for i in xrange(len(self.comments)): + for i in pycompat.xrange(len(self.comments)): if subj == self.comments[i].lower(): del self.comments[i] self.message = self.message[2:] @@ -1800,7 +1800,7 @@ class queue(object): # if the patch excludes a modified file, mark that # file with mtime=0 so status can see it. mm = [] - for i in xrange(len(m) - 1, -1, -1): + for i in pycompat.xrange(len(m) - 1, -1, -1): if not match1(m[i]): mm.append(m[i]) del m[i] @@ -1908,7 +1908,7 @@ class queue(object): else: start = self.series.index(patch) + 1 unapplied = [] - for i in xrange(start, len(self.series)): + for i in pycompat.xrange(start, len(self.series)): pushable, reason = self.pushable(i) if pushable: unapplied.append((i, self.series[i])) @@ -1946,7 +1946,7 @@ class queue(object): if not missing: if self.ui.verbose: idxwidth = len("%d" % (start + length - 1)) - for i in xrange(start, start + length): + for i in pycompat.xrange(start, start + length): patch = self.series[i] if patch in applied: char, state = 'A', 'applied' @@ -2091,7 +2091,7 @@ class queue(object): def nextpatch(start): if all_patches or start >= len(self.series): return start - for i in xrange(start, len(self.series)): + for i in pycompat.xrange(start, len(self.series)): p, reason = self.pushable(i) if p: return i @@ -2876,7 +2876,7 @@ def guard(ui, repo, *args, **opts): if args or opts.get(r'none'): raise error.Abort(_('cannot mix -l/--list with options or ' 'arguments')) - for i in xrange(len(q.series)): + for i in pycompat.xrange(len(q.series)): status(i) return if not args or args[0][0:1] in '-+': @@ -3179,14 +3179,16 @@ def select(ui, repo, *args, **opts): pushable = lambda i: q.pushable(q.applied[i].name)[0] if args or opts.get('none'): old_unapplied = q.unapplied(repo) - old_guarded = [i for i in xrange(len(q.applied)) if not pushable(i)] + old_guarded = [i for i in pycompat.xrange(len(q.applied)) + if not pushable(i)] q.setactive(args) q.savedirty() if not args: ui.status(_('guards deactivated\n')) if not opts.get('pop') and not opts.get('reapply'): unapplied = q.unapplied(repo) - guarded = [i for i in xrange(len(q.applied)) if not pushable(i)] + guarded = [i for i in pycompat.xrange(len(q.applied)) + if not pushable(i)] if len(unapplied) != len(old_unapplied): ui.status(_('number of unguarded, unapplied patches has ' 'changed from %d to %d\n') % @@ -3225,7 +3227,7 @@ def select(ui, repo, *args, **opts): reapply = opts.get('reapply') and q.applied and q.applied[-1].name popped = False if opts.get('pop') or opts.get('reapply'): - for i in xrange(len(q.applied)): + for i in pycompat.xrange(len(q.applied)): if not pushable(i): ui.status(_('popping guarded patches\n')) popped = True diff --git a/hgext/narrow/narrowchangegroup.py b/hgext/narrow/narrowchangegroup.py --- a/hgext/narrow/narrowchangegroup.py +++ b/hgext/narrow/narrowchangegroup.py @@ -16,6 +16,7 @@ from mercurial import ( match as matchmod, mdiff, node, + pycompat, revlog, util, ) @@ -332,7 +333,7 @@ def setup(): # somewhat unsurprised to find a case in the wild # where this breaks down a bit. That said, I don't # know if it would hurt anything. - for i in xrange(rev, 0, -1): + for i in pycompat.xrange(rev, 0, -1): if revlog.linkrev(i) == clrev: return i # We failed to resolve a parent for this node, so diff --git a/hgext/shelve.py b/hgext/shelve.py --- a/hgext/shelve.py +++ b/hgext/shelve.py @@ -783,7 +783,7 @@ def _rebaserestoredcommit(ui, repo, opts tr.close() nodestoremove = [repo.changelog.node(rev) - for rev in xrange(oldtiprev, len(repo))] + for rev in pycompat.xrange(oldtiprev, len(repo))] shelvedstate.save(repo, basename, pctx, tmpwctx, nodestoremove, branchtorestore, opts.get('keep'), activebookmark) raise error.InterventionRequired( diff --git a/hgext/win32text.py b/hgext/win32text.py --- a/hgext/win32text.py +++ b/hgext/win32text.py @@ -49,6 +49,7 @@ from mercurial.node import ( short, ) from mercurial import ( + pycompat, registrar, ) from mercurial.utils import ( @@ -141,7 +142,8 @@ def forbidnewline(ui, repo, hooktype, no # changegroup that contains an unacceptable commit followed later # by a commit that fixes the problem. tip = repo['tip'] - for rev in xrange(repo.changelog.tiprev(), repo[node].rev() - 1, -1): + for rev in pycompat.xrange(repo.changelog.tiprev(), + repo[node].rev() - 1, -1): c = repo[rev] for f in c.files(): if f in seen or f not in tip or f not in c: diff --git a/mercurial/ancestor.py b/mercurial/ancestor.py --- a/mercurial/ancestor.py +++ b/mercurial/ancestor.py @@ -11,6 +11,9 @@ import collections import heapq from .node import nullrev +from . import ( + pycompat, +) def commonancestorsheads(pfunc, *nodes): """Returns a set with the heads of all common ancestors of all nodes, @@ -174,7 +177,7 @@ class incrementalmissingancestors(object # no revs to consider return - for curr in xrange(start, min(revs) - 1, -1): + for curr in pycompat.xrange(start, min(revs) - 1, -1): if curr not in bases: continue revs.discard(curr) @@ -215,7 +218,7 @@ class incrementalmissingancestors(object # exit. missing = [] - for curr in xrange(start, nullrev, -1): + for curr in pycompat.xrange(start, nullrev, -1): if not revsvisit: break diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py --- a/mercurial/bundle2.py +++ b/mercurial/bundle2.py @@ -2223,11 +2223,11 @@ def handlerbc(op, inpart): total += header[1] + header[2] utf8branch = inpart.read(header[0]) branch = encoding.tolocal(utf8branch) - for x in xrange(header[1]): + for x in pycompat.xrange(header[1]): node = inpart.read(20) rev = cl.rev(node) cache.setdata(branch, rev, node, False) - for x in xrange(header[2]): + for x in pycompat.xrange(header[2]): node = inpart.read(20) rev = cl.rev(node) cache.setdata(branch, rev, node, True) diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py --- a/mercurial/changegroup.py +++ b/mercurial/changegroup.py @@ -325,7 +325,7 @@ class cg1unpacker(object): cl = repo.changelog ml = repo.manifestlog # validate incoming csets have their manifests - for cset in xrange(clstart, clend): + for cset in pycompat.xrange(clstart, clend): mfnode = cl.changelogrevision(cset).manifest mfest = ml[mfnode].readdelta() # store file cgnodes we must see @@ -367,7 +367,7 @@ class cg1unpacker(object): repo.hook('pretxnchangegroup', throw=True, **pycompat.strkwargs(hookargs)) - added = [cl.node(r) for r in xrange(clstart, clend)] + added = [cl.node(r) for r in pycompat.xrange(clstart, clend)] phaseall = None if srctype in ('push', 'serve'): # Old servers can not push the boundary themselves. @@ -568,7 +568,7 @@ class cg1packer(object): if units is not None: progress = self._repo.ui.makeprogress(_('bundling'), unit=units, total=(len(revs) - 1)) - for r in xrange(len(revs) - 1): + for r in pycompat.xrange(len(revs) - 1): if progress: progress.update(r + 1) prev, curr = revs[r], revs[r + 1] @@ -989,7 +989,7 @@ def _addchangegroupfiles(repo, source, r revisions += len(fl) - o if f in needfiles: needs = needfiles[f] - for new in xrange(o, len(fl)): + for new in pycompat.xrange(o, len(fl)): n = fl.node(new) if n in needs: needs.remove(n) diff --git a/mercurial/changelog.py b/mercurial/changelog.py --- a/mercurial/changelog.py +++ b/mercurial/changelog.py @@ -313,7 +313,7 @@ class changelog(revlog.revlog): self.filteredrevs = frozenset() def tiprev(self): - for i in xrange(len(self) -1, -2, -1): + for i in pycompat.xrange(len(self) -1, -2, -1): if i not in self.filteredrevs: return i @@ -332,7 +332,7 @@ class changelog(revlog.revlog): return revlog.revlog.__iter__(self) def filterediter(): - for i in xrange(len(self)): + for i in pycompat.xrange(len(self)): if i not in self.filteredrevs: yield i @@ -563,8 +563,8 @@ class changelog(revlog.revlog): if revs is not None: if revs: assert revs[-1] + 1 == rev - revs = xrange(revs[0], rev + 1) + revs = pycompat.xrange(revs[0], rev + 1) else: - revs = xrange(rev, rev + 1) + revs = pycompat.xrange(rev, rev + 1) transaction.changes['revs'] = revs return node diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -1755,7 +1755,7 @@ def walkfilerevs(repo, match, follow, re """ cl_count = len(repo) revs = [] - for j in xrange(0, last + 1): + for j in pycompat.xrange(0, last + 1): linkrev = filelog.linkrev(j) if linkrev < minrev: continue @@ -1966,7 +1966,7 @@ def walkchangerevs(repo, match, opts, pr rev = repo[rev].rev() ff = _followfilter(repo) stop = min(revs[0], revs[-1]) - for x in xrange(rev, stop - 1, -1): + for x in pycompat.xrange(rev, stop - 1, -1): if ff.match(x): wanted = wanted - [x] @@ -1985,7 +1985,7 @@ def walkchangerevs(repo, match, opts, pr stopiteration = False for windowsize in increasingwindows(): nrevs = [] - for i in xrange(windowsize): + for i in pycompat.xrange(windowsize): rev = next(it, None) if rev is None: stopiteration = True diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -2607,15 +2607,15 @@ def grep(ui, repo, pattern, *pats, **opt sm = difflib.SequenceMatcher(None, a, b) for tag, alo, ahi, blo, bhi in sm.get_opcodes(): if tag == 'insert': - for i in xrange(blo, bhi): + for i in pycompat.xrange(blo, bhi): yield ('+', b[i]) elif tag == 'delete': - for i in xrange(alo, ahi): + for i in pycompat.xrange(alo, ahi): yield ('-', a[i]) elif tag == 'replace': - for i in xrange(alo, ahi): + for i in pycompat.xrange(alo, ahi): yield ('-', a[i]) - for i in xrange(blo, bhi): + for i in pycompat.xrange(blo, bhi): yield ('+', b[i]) def display(fm, fn, ctx, pstates, states): diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -1896,7 +1896,7 @@ class overlayworkingctx(committablectx): # Test that each new directory to be created to write this path from p2 # is not a file in p1. components = path.split('/') - for i in xrange(len(components)): + for i in pycompat.xrange(len(components)): component = "/".join(components[0:i]) if component in self.p1(): fail(path, component) diff --git a/mercurial/dagop.py b/mercurial/dagop.py --- a/mercurial/dagop.py +++ b/mercurial/dagop.py @@ -195,7 +195,7 @@ def _builddescendantsmap(repo, startrev, """Build map of 'rev -> child revs', offset from startrev""" cl = repo.changelog nullrev = node.nullrev - descmap = [[] for _rev in xrange(startrev, len(cl))] + descmap = [[] for _rev in pycompat.xrange(startrev, len(cl))] for currev in cl.revs(startrev + 1): p1rev, p2rev = cl.parentrevs(currev) if p1rev >= startrev: @@ -435,7 +435,7 @@ def _annotatepair(parents, childfctx, ch for idx, (parent, blocks) in enumerate(pblocks): for (a1, a2, b1, b2), _t in blocks: if a2 - a1 >= b2 - b1: - for bk in xrange(b1, b2): + for bk in pycompat.xrange(b1, b2): if child.fctxs[bk] == childfctx: ak = min(a1 + (bk - b1), a2 - 1) child.fctxs[bk] = parent.fctxs[ak] @@ -448,7 +448,7 @@ def _annotatepair(parents, childfctx, ch # line. for parent, blocks in remaining: for a1, a2, b1, b2 in blocks: - for bk in xrange(b1, b2): + for bk in pycompat.xrange(b1, b2): if child.fctxs[bk] == childfctx: ak = min(a1 + (bk - b1), a2 - 1) child.fctxs[bk] = parent.fctxs[ak] diff --git a/mercurial/dagparser.py b/mercurial/dagparser.py --- a/mercurial/dagparser.py +++ b/mercurial/dagparser.py @@ -222,7 +222,7 @@ def parsedag(desc): elif c == '+': c, digs = nextrun(nextch(), pycompat.bytestr(string.digits)) n = int(digs) - for i in xrange(0, n): + for i in pycompat.xrange(0, n): yield 'n', (r, [p1]) p1 = r r += 1 diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py --- a/mercurial/debugcommands.py +++ b/mercurial/debugcommands.py @@ -177,7 +177,8 @@ def debugbuilddag(ui, repo, text=None, if mergeable_file: linesperrev = 2 # make a file with k lines per rev - initialmergedlines = ['%d' % i for i in xrange(0, total * linesperrev)] + initialmergedlines = ['%d' % i + for i in pycompat.xrange(0, total * linesperrev)] initialmergedlines.append("") tags = [] @@ -2018,7 +2019,7 @@ def debugrevlog(ui, repo, file_=None, ** ts = 0 heads = set() - for rev in xrange(numrevs): + for rev in pycompat.xrange(numrevs): dbase = r.deltaparent(rev) if dbase == -1: dbase = rev @@ -2079,7 +2080,7 @@ def debugrevlog(ui, repo, file_=None, ** l[2] += size numrevs = len(r) - for rev in xrange(numrevs): + for rev in pycompat.xrange(numrevs): p1, p2 = r.parentrevs(rev) delta = r.deltaparent(rev) if format > 0: diff --git a/mercurial/diffhelper.py b/mercurial/diffhelper.py --- a/mercurial/diffhelper.py +++ b/mercurial/diffhelper.py @@ -11,6 +11,7 @@ from .i18n import _ from . import ( error, + pycompat, ) def addlines(fp, hunk, lena, lenb, a, b): @@ -26,7 +27,7 @@ def addlines(fp, hunk, lena, lenb, a, b) num = max(todoa, todob) if num == 0: break - for i in xrange(num): + for i in pycompat.xrange(num): s = fp.readline() if not s: raise error.ParseError(_('incomplete hunk')) @@ -71,7 +72,7 @@ def testhunk(a, b, bstart): blen = len(b) if alen > blen - bstart or bstart < 0: return False - for i in xrange(alen): + for i in pycompat.xrange(alen): if a[i][1:] != b[i + bstart]: return False return True diff --git a/mercurial/encoding.py b/mercurial/encoding.py --- a/mercurial/encoding.py +++ b/mercurial/encoding.py @@ -251,7 +251,7 @@ def ucolwidth(d): def getcols(s, start, c): '''Use colwidth to find a c-column substring of s starting at byte index start''' - for x in xrange(start + c, len(s)): + for x in pycompat.xrange(start + c, len(s)): t = s[start:x] if colwidth(t) == c: return t @@ -346,7 +346,7 @@ def trim(s, width, ellipsis='', leftside else: uslice = lambda i: u[:-i] concat = lambda s: s + ellipsis - for i in xrange(1, len(u)): + for i in pycompat.xrange(1, len(u)): usub = uslice(i) if ucolwidth(usub) <= width: return concat(usub.encode(_sysstr(encoding))) diff --git a/mercurial/graphmod.py b/mercurial/graphmod.py --- a/mercurial/graphmod.py +++ b/mercurial/graphmod.py @@ -22,6 +22,7 @@ from __future__ import absolute_import from .node import nullrev from . import ( dagop, + pycompat, smartset, util, ) @@ -426,16 +427,16 @@ def ascii(ui, state, type, char, text, c # shift_interline is the line containing the non-vertical # edges between this entry and the next shift_interline = echars[:idx * 2] - for i in xrange(2 + coldiff): + for i in pycompat.xrange(2 + coldiff): shift_interline.append(' ') count = ncols - idx - 1 if coldiff == -1: - for i in xrange(count): + for i in pycompat.xrange(count): shift_interline.extend(['/', ' ']) elif coldiff == 0: shift_interline.extend(echars[(idx + 1) * 2:ncols * 2]) else: - for i in xrange(count): + for i in pycompat.xrange(count): shift_interline.extend(['\\', ' ']) # draw edges from the current node to its parents diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py --- a/mercurial/hgweb/webcommands.py +++ b/mercurial/hgweb/webcommands.py @@ -215,7 +215,7 @@ def _search(web): def revgen(): cl = web.repo.changelog - for i in xrange(len(web.repo) - 1, 0, -100): + for i in pycompat.xrange(len(web.repo) - 1, 0, -100): l = [] for j in cl.revs(max(0, i - 99), i): ctx = web.repo[j] diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py --- a/mercurial/hgweb/webutil.py +++ b/mercurial/hgweb/webutil.py @@ -613,21 +613,21 @@ def _getcompblockgen(context, leftlines, len1 = lhi - llo len2 = rhi - rlo count = min(len1, len2) - for i in xrange(count): + for i in pycompat.xrange(count): yield _compline(type=type, leftlineno=llo + i + 1, leftline=leftlines[llo + i], rightlineno=rlo + i + 1, rightline=rightlines[rlo + i]) if len1 > len2: - for i in xrange(llo + count, lhi): + for i in pycompat.xrange(llo + count, lhi): yield _compline(type=type, leftlineno=i + 1, leftline=leftlines[i], rightlineno=None, rightline=None) elif len2 > len1: - for i in xrange(rlo + count, rhi): + for i in pycompat.xrange(rlo + count, rhi): yield _compline(type=type, leftlineno=None, leftline=None, diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py --- a/mercurial/httppeer.py +++ b/mercurial/httppeer.py @@ -64,7 +64,7 @@ def encodevalueinheaders(value, header, result = [] n = 0 - for i in xrange(0, len(value), valuelen): + for i in pycompat.xrange(0, len(value), valuelen): n += 1 result.append((fmt % str(n), pycompat.strurl(value[i:i + valuelen]))) diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -850,7 +850,7 @@ class localrepository(object): if isinstance(changeid, slice): # wdirrev isn't contiguous so the slice shouldn't include it return [context.changectx(self, i) - for i in xrange(*changeid.indices(len(self))) + for i in pycompat.xrange(*changeid.indices(len(self))) if i not in self.changelog.filteredrevs] try: return context.changectx(self, changeid) @@ -1385,7 +1385,7 @@ class localrepository(object): releasefn=releasefn, checkambigfiles=_cachedfiles, name=desc) - tr.changes['revs'] = xrange(0, 0) + tr.changes['revs'] = pycompat.xrange(0, 0) tr.changes['obsmarkers'] = set() tr.changes['phases'] = {} tr.changes['bookmarks'] = {} diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py --- a/mercurial/mdiff.py +++ b/mercurial/mdiff.py @@ -357,7 +357,7 @@ def _unidiff(t1, t2, opts=defaultopts): # walk backwards from the start of the context up to the start of # the previous hunk context until we find a line starting with an # alphanumeric char. - for i in xrange(astart - 1, lastpos - 1, -1): + for i in pycompat.xrange(astart - 1, lastpos - 1, -1): if l1[i][0:1].isalnum(): func = b' ' + l1[i].rstrip() # split long function name if ASCII. otherwise we have no @@ -381,7 +381,7 @@ def _unidiff(t1, t2, opts=defaultopts): hunklines = ( ["@@ -%d,%d +%d,%d @@%s\n" % (hunkrange + (func,))] + delta - + [' ' + l1[x] for x in xrange(a2, aend)] + + [' ' + l1[x] for x in pycompat.xrange(a2, aend)] ) # If either file ends without a newline and the last line of # that file is part of a hunk, a marker is printed. If the @@ -390,7 +390,7 @@ def _unidiff(t1, t2, opts=defaultopts): # which the hunk can end in a shared line without a newline. skip = False if not t1.endswith('\n') and astart + alen == len(l1) + 1: - for i in xrange(len(hunklines) - 1, -1, -1): + for i in pycompat.xrange(len(hunklines) - 1, -1, -1): if hunklines[i].startswith(('-', ' ')): if hunklines[i].startswith(' '): skip = True @@ -398,7 +398,7 @@ def _unidiff(t1, t2, opts=defaultopts): hunklines.insert(i + 1, _missing_newline_marker) break if not skip and not t2.endswith('\n') and bstart + blen == len(l2) + 1: - for i in xrange(len(hunklines) - 1, -1, -1): + for i in pycompat.xrange(len(hunklines) - 1, -1, -1): if hunklines[i].startswith('+'): hunklines[i] += '\n' hunklines.insert(i + 1, _missing_newline_marker) diff --git a/mercurial/minirst.py b/mercurial/minirst.py --- a/mercurial/minirst.py +++ b/mercurial/minirst.py @@ -316,7 +316,7 @@ def findtables(blocks): # column markers are ASCII so we can calculate column # position in bytes - columns = [x for x in xrange(len(div)) + columns = [x for x in pycompat.xrange(len(div)) if div[x:x + 1] == '=' and (x == 0 or div[x - 1:x] == ' ')] rows = [] @@ -685,7 +685,7 @@ def format(text, width=80, indent=0, kee if llen and llen != plen: collapse = False s = [] - for j in xrange(3, plen - 1): + for j in pycompat.xrange(3, plen - 1): parent = parents[j] if (j >= llen or lastparents[j] != parent): diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py --- a/mercurial/obsolete.py +++ b/mercurial/obsolete.py @@ -394,7 +394,7 @@ def _fm1purereadmarkers(data, off, stop) off = o3 + metasize * nummeta metapairsize = unpack('>' + (metafmt * nummeta), data[o3:off]) metadata = [] - for idx in xrange(0, len(metapairsize), 2): + for idx in pycompat.xrange(0, len(metapairsize), 2): o1 = off + metapairsize[idx] o2 = o1 + metapairsize[idx + 1] metadata.append((data[off:o1], data[o1:o2])) diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -815,7 +815,7 @@ class patchfile(object): for x, s in enumerate(self.lines): self.hash.setdefault(s, []).append(x) - for fuzzlen in xrange(self.ui.configint("patch", "fuzz") + 1): + for fuzzlen in pycompat.xrange(self.ui.configint("patch", "fuzz") + 1): for toponly in [True, False]: old, oldstart, new, newstart = h.fuzzit(fuzzlen, toponly) oldstart = oldstart + self.offset + self.skew @@ -1286,7 +1286,7 @@ class hunk(object): self.lena = int(aend) - self.starta if self.starta: self.lena += 1 - for x in xrange(self.lena): + for x in pycompat.xrange(self.lena): l = lr.readline() if l.startswith('---'): # lines addition, old block is empty @@ -1320,7 +1320,7 @@ class hunk(object): if self.startb: self.lenb += 1 hunki = 1 - for x in xrange(self.lenb): + for x in pycompat.xrange(self.lenb): l = lr.readline() if l.startswith('\ '): # XXX: the only way to hit this is with an invalid line range. @@ -1396,14 +1396,14 @@ class hunk(object): top = 0 bot = 0 hlen = len(self.hunk) - for x in xrange(hlen - 1): + for x in pycompat.xrange(hlen - 1): # the hunk starts with the @@ line, so use x+1 if self.hunk[x + 1].startswith(' '): top += 1 else: break if not toponly: - for x in xrange(hlen - 1): + for x in pycompat.xrange(hlen - 1): if self.hunk[hlen - bot - 1].startswith(' '): bot += 1 else: diff --git a/mercurial/phases.py b/mercurial/phases.py --- a/mercurial/phases.py +++ b/mercurial/phases.py @@ -374,7 +374,7 @@ class phasecache(object): changes = set() # set of revisions to be changed delroots = [] # set of root deleted by this path - for phase in xrange(targetphase + 1, len(allphases)): + for phase in pycompat.xrange(targetphase + 1, len(allphases)): # filter nodes that are not in a compatible phase already nodes = [n for n in nodes if self.phase(repo, repo[n].rev()) >= phase] @@ -420,7 +420,7 @@ class phasecache(object): affected = set(repo.revs('(%ln::) - (%ln::)', new, old)) # find the phase of the affected revision - for phase in xrange(targetphase, -1, -1): + for phase in pycompat.xrange(targetphase, -1, -1): if phase: roots = oldroots[phase] revs = set(repo.revs('%ln::%ld', roots, affected)) diff --git a/mercurial/pure/osutil.py b/mercurial/pure/osutil.py --- a/mercurial/pure/osutil.py +++ b/mercurial/pure/osutil.py @@ -150,7 +150,7 @@ if not pycompat.iswindows: rfds = ctypes.cast(cmsg.cmsg_data, ctypes.POINTER(ctypes.c_int)) rfdscount = ((cmsg.cmsg_len - _cmsghdr.cmsg_data.offset) / ctypes.sizeof(ctypes.c_int)) - return [rfds[i] for i in xrange(rfdscount)] + return [rfds[i] for i in pycompat.xrange(rfdscount)] else: import msvcrt diff --git a/mercurial/pvec.py b/mercurial/pvec.py --- a/mercurial/pvec.py +++ b/mercurial/pvec.py @@ -52,6 +52,7 @@ from __future__ import absolute_import from .node import nullrev from . import ( + pycompat, util, ) @@ -72,7 +73,7 @@ def _bin(bs): def _str(v, l): bs = "" - for p in xrange(l): + for p in pycompat.xrange(l): bs = chr(v & 255) + bs v >>= 8 return bs @@ -91,7 +92,7 @@ def _hweight(x): c += 1 x >>= 1 return c -_htab = [_hweight(x) for x in xrange(256)] +_htab = [_hweight(x) for x in pycompat.xrange(256)] def _hamming(a, b): '''find the hamming distance between two longs''' @@ -152,7 +153,7 @@ def ctxpvec(ctx): pvc = r._pveccache if ctx.rev() not in pvc: cl = r.changelog - for n in xrange(ctx.rev() + 1): + for n in pycompat.xrange(ctx.rev() + 1): if n not in pvc: node = cl.node(n) p1, p2 = cl.parentrevs(n) diff --git a/mercurial/repair.py b/mercurial/repair.py --- a/mercurial/repair.py +++ b/mercurial/repair.py @@ -24,6 +24,7 @@ from . import ( exchange, obsolete, obsutil, + pycompat, util, ) from .utils import ( @@ -70,7 +71,7 @@ def _collectfiles(repo, striprev): """find out the filelogs affected by the strip""" files = set() - for x in xrange(striprev, len(repo)): + for x in pycompat.xrange(striprev, len(repo)): files.update(repo[x].files()) return sorted(files) @@ -199,7 +200,7 @@ def strip(ui, repo, nodelist, backup=Tru repo.file(fn).strip(striprev, tr) tr.endgroup() - for i in xrange(offset, len(tr.entries)): + for i in pycompat.xrange(offset, len(tr.entries)): file, troffset, ignore = tr.entries[i] with repo.svfs(file, 'a', checkambig=True) as fp: fp.truncate(troffset) diff --git a/mercurial/repoview.py b/mercurial/repoview.py --- a/mercurial/repoview.py +++ b/mercurial/repoview.py @@ -128,7 +128,7 @@ def computeimpactable(repo, visibilityex firstmutable = min(firstmutable, min(cl.rev(r) for r in roots)) # protect from nullrev root firstmutable = max(0, firstmutable) - return frozenset(xrange(firstmutable, len(cl))) + return frozenset(pycompat.xrange(firstmutable, len(cl))) # function to compute filtered set # diff --git a/mercurial/revlog.py b/mercurial/revlog.py --- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -1066,7 +1066,7 @@ class revlog(object): def __len__(self): return len(self.index) - 1 def __iter__(self): - return iter(xrange(len(self))) + return iter(pycompat.xrange(len(self))) def revs(self, start=0, stop=None): """iterate over all rev in this revlog (from start to stop)""" step = 1 @@ -1079,7 +1079,7 @@ class revlog(object): stop = length else: stop = length - return xrange(start, stop, step) + return pycompat.xrange(start, stop, step) @util.propertycache def nodemap(self): @@ -1136,7 +1136,7 @@ class revlog(object): p = len(i) - 2 else: assert p < len(i) - for r in xrange(p, -1, -1): + for r in pycompat.xrange(p, -1, -1): v = i[r][7] n[v] = r if v == node: @@ -2789,7 +2789,7 @@ class revlog(object): self._cache = None self._chaininfocache = {} self._chunkclear() - for x in xrange(rev, len(self)): + for x in pycompat.xrange(rev, len(self)): del self.nodemap[self.node(x)] del self.index[rev:-1] diff --git a/mercurial/revsetlang.py b/mercurial/revsetlang.py --- a/mercurial/revsetlang.py +++ b/mercurial/revsetlang.py @@ -63,7 +63,7 @@ symbols = {} _syminitletters = set(pycompat.iterbytestr( string.ascii_letters.encode('ascii') + string.digits.encode('ascii') + - '._@')) | set(map(pycompat.bytechr, xrange(128, 256))) + '._@')) | set(map(pycompat.bytechr, pycompat.xrange(128, 256))) # default set of valid characters for non-initial letters of symbols _symletters = _syminitletters | set(pycompat.iterbytestr('-/')) diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -1542,7 +1542,7 @@ def registersummarycallback(repo, otr, t @reportsummary def reportnewcs(repo, tr): """Report the range of new revisions pulled/unbundled.""" - newrevs = tr.changes.get('revs', xrange(0, 0)) + newrevs = tr.changes.get('revs', pycompat.xrange(0, 0)) if not newrevs: return @@ -1565,7 +1565,7 @@ def registersummarycallback(repo, otr, t """Report statistics of phase changes for changesets pre-existing pull/unbundle. """ - newrevs = tr.changes.get('revs', xrange(0, 0)) + newrevs = tr.changes.get('revs', pycompat.xrange(0, 0)) phasetracking = tr.changes.get('phases', {}) if not phasetracking: return diff --git a/mercurial/server.py b/mercurial/server.py --- a/mercurial/server.py +++ b/mercurial/server.py @@ -79,7 +79,7 @@ def runservice(opts, parentfn=None, init runargs.append('--daemon-postexec=unlink:%s' % lockpath) # Don't pass --cwd to the child process, because we've already # changed directory. - for i in xrange(1, len(runargs)): + for i in pycompat.xrange(1, len(runargs)): if runargs[i].startswith('--cwd='): del runargs[i] break diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py --- a/mercurial/simplemerge.py +++ b/mercurial/simplemerge.py @@ -58,7 +58,8 @@ def compare_range(a, astart, aend, b, bs """ if (aend - astart) != (bend - bstart): return False - for ia, ib in zip(xrange(astart, aend), xrange(bstart, bend)): + for ia, ib in zip(pycompat.xrange(astart, aend), + pycompat.xrange(bstart, bend)): if a[ia] != b[ib]: return False else: diff --git a/mercurial/smartset.py b/mercurial/smartset.py --- a/mercurial/smartset.py +++ b/mercurial/smartset.py @@ -152,11 +152,11 @@ class abstractsmartset(object): # but start > stop is allowed, which should be an empty set. ys = [] it = iter(self) - for x in xrange(start): + for x in pycompat.xrange(start): y = next(it, None) if y is None: break - for x in xrange(stop - start): + for x in pycompat.xrange(stop - start): y = next(it, None) if y is None: break @@ -1005,13 +1005,13 @@ class _spanset(abstractsmartset): return self.fastdesc() def fastasc(self): - iterrange = xrange(self._start, self._end) + iterrange = pycompat.xrange(self._start, self._end) if self._hiddenrevs: return self._iterfilter(iterrange) return iter(iterrange) def fastdesc(self): - iterrange = xrange(self._end - 1, self._start - 1, -1) + iterrange = pycompat.xrange(self._end - 1, self._start - 1, -1) if self._hiddenrevs: return self._iterfilter(iterrange) return iter(iterrange) diff --git a/mercurial/store.py b/mercurial/store.py --- a/mercurial/store.py +++ b/mercurial/store.py @@ -118,7 +118,7 @@ def _buildencodefun(): def decode(s): i = 0 while i < len(s): - for l in xrange(1, 4): + for l in pycompat.xrange(1, 4): try: yield dmap[s[i:i + l]] i += l @@ -127,7 +127,8 @@ def _buildencodefun(): pass else: raise KeyError - return (lambda s: ''.join([cmap[s[c:c + 1]] for c in xrange(len(s))]), + return (lambda s: ''.join([cmap[s[c:c + 1]] + for c in pycompat.xrange(len(s))]), lambda s: ''.join(list(decode(s)))) _encodefname, _decodefname = _buildencodefun() @@ -159,7 +160,7 @@ def _buildlowerencodefun(): 'the~07quick~adshot' ''' xchr = pycompat.bytechr - cmap = dict([(xchr(x), xchr(x)) for x in xrange(127)]) + cmap = dict([(xchr(x), xchr(x)) for x in pycompat.xrange(127)]) for x in _reserved(): cmap[xchr(x)] = "~%02x" % x for x in range(ord("A"), ord("Z") + 1): diff --git a/mercurial/streamclone.py b/mercurial/streamclone.py --- a/mercurial/streamclone.py +++ b/mercurial/streamclone.py @@ -358,7 +358,7 @@ def consumev1(repo, fp, filecount, bytec with repo.transaction('clone'): with repo.svfs.backgroundclosing(repo.ui, expectedcount=filecount): - for i in xrange(filecount): + for i in pycompat.xrange(filecount): # XXX doesn't support '\n' or '\r' in filenames l = fp.readline() try: diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py --- a/mercurial/templatefilters.py +++ b/mercurial/templatefilters.py @@ -119,7 +119,7 @@ def commondir(filelist): b = b[:len(a)] if a == b: return a - for i in xrange(len(a)): + for i in pycompat.xrange(len(a)): if a[i] != b[i]: return a[:i] return a @@ -266,7 +266,7 @@ def indent(text, prefix): num_lines = len(lines) endswithnewline = text[-1:] == '\n' def indenter(): - for i in xrange(num_lines): + for i in pycompat.xrange(num_lines): l = lines[i] if i and l.strip(): yield prefix diff --git a/mercurial/treediscovery.py b/mercurial/treediscovery.py --- a/mercurial/treediscovery.py +++ b/mercurial/treediscovery.py @@ -16,6 +16,7 @@ from .node import ( ) from . import ( error, + pycompat, ) def findcommonincoming(repo, remote, heads=None, force=False): @@ -111,7 +112,7 @@ def findcommonincoming(repo, remote, hea progress.increment() repo.ui.debug("request %d: %s\n" % (reqcnt, " ".join(map(short, r)))) - for p in xrange(0, len(r), 10): + for p in pycompat.xrange(0, len(r), 10): with remote.commandexecutor() as e: branches = e.callcommand('branches', { 'nodes': r[p:p + 10], diff --git a/mercurial/utils/stringutil.py b/mercurial/utils/stringutil.py --- a/mercurial/utils/stringutil.py +++ b/mercurial/utils/stringutil.py @@ -464,7 +464,7 @@ def _MBTextWrapper(**kwargs): def _cutdown(self, ucstr, space_left): l = 0 colwidth = encoding.ucolwidth - for i in xrange(len(ucstr)): + for i in pycompat.xrange(len(ucstr)): l += colwidth(ucstr[i]) if space_left < l: return (ucstr[:i], ucstr[i:]) diff --git a/mercurial/win32.py b/mercurial/win32.py --- a/mercurial/win32.py +++ b/mercurial/win32.py @@ -615,7 +615,7 @@ def unlink(f): # callers to recreate f immediately while having other readers do their # implicit zombie filename blocking on a temporary name. - for tries in xrange(10): + for tries in pycompat.xrange(10): temp = '%s-%08x' % (f, random.randint(0, 0xffffffff)) try: os.rename(f, temp) # raises OSError EEXIST if temp exists diff --git a/mercurial/wireprotoserver.py b/mercurial/wireprotoserver.py --- a/mercurial/wireprotoserver.py +++ b/mercurial/wireprotoserver.py @@ -502,14 +502,14 @@ class sshv1protocolhandler(object): def getargs(self, args): data = {} keys = args.split() - for n in xrange(len(keys)): + for n in pycompat.xrange(len(keys)): argline = self._fin.readline()[:-1] arg, l = argline.split() if arg not in keys: raise error.Abort(_("unexpected parameter %r") % arg) if arg == '*': star = {} - for k in xrange(int(l)): + for k in pycompat.xrange(int(l)): argline = self._fin.readline()[:-1] arg, l = argline.split() val = self._fin.read(int(l)) diff --git a/mercurial/wireprotov1peer.py b/mercurial/wireprotov1peer.py --- a/mercurial/wireprotov1peer.py +++ b/mercurial/wireprotov1peer.py @@ -497,7 +497,7 @@ class wirepeer(repository.peer): def between(self, pairs): batch = 8 # avoid giant requests r = [] - for i in xrange(0, len(pairs), batch): + for i in pycompat.xrange(0, len(pairs), batch): n = " ".join([wireprototypes.encodelist(p, '-') for p in pairs[i:i + batch]]) d = self._call("between", pairs=n)