Patchwork [5,of,8,py3] bruterebase: port to python 3

login
register
mail settings
Submitter Augie Fackler
Date Sept. 15, 2017, 11:14 p.m.
Message ID <370f8212917c1af7e618.1505517248@augie-macbookpro2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/23925/
State Accepted
Headers show

Comments

Augie Fackler - Sept. 15, 2017, 11:14 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1503465779 14400
#      Wed Aug 23 01:22:59 2017 -0400
# Node ID 370f8212917c1af7e6189d3f0a7ca59ec49d1a4a
# Parent  050dd624a9a887c3efde65b7750311d3d3bd716c
bruterebase: port to python 3
Yuya Nishihara - Sept. 16, 2017, 12:14 p.m.
On Fri, 15 Sep 2017 19:14:08 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1503465779 14400
> #      Wed Aug 23 01:22:59 2017 -0400
> # Node ID 370f8212917c1af7e6189d3f0a7ca59ec49d1a4a
> # Parent  050dd624a9a887c3efde65b7750311d3d3bd716c
> bruterebase: port to python 3

Queued this, thanks.

> diff --git a/tests/bruterebase.py b/tests/bruterebase.py
> --- a/tests/bruterebase.py
> +++ b/tests/bruterebase.py
> @@ -15,10 +15,15 @@ from mercurial import (
>  
>  from hgext import rebase
>  
> +try:
> +    xrange
> +except NameError:
> +    xrange = range
> +
>  cmdtable = {}
>  command = registrar.command(cmdtable)
>  
> -@command('debugbruterebase')
> +@command(b'debugbruterebase')
>  def debugbruterebase(ui, repo, source, dest):
>      """for every non-empty subset of source, run rebase -r subset -d dest
>  
> @@ -33,28 +38,28 @@ def debugbruterebase(ui, repo, source, d
>          def getdesc(rev):
>              result = cl.changelogrevision(rev).description
>              if rev >= repolen:
> -                result += "'"
> +                result += b"'"
>              return result
>  
> -        for i in xrange(1, 2 ** len(srevs)):
> +        for i in range(1, 2 ** len(srevs)):

Dropped this change as we do xrange = range.

Patch

diff --git a/tests/bruterebase.py b/tests/bruterebase.py
--- a/tests/bruterebase.py
+++ b/tests/bruterebase.py
@@ -15,10 +15,15 @@  from mercurial import (
 
 from hgext import rebase
 
+try:
+    xrange
+except NameError:
+    xrange = range
+
 cmdtable = {}
 command = registrar.command(cmdtable)
 
-@command('debugbruterebase')
+@command(b'debugbruterebase')
 def debugbruterebase(ui, repo, source, dest):
     """for every non-empty subset of source, run rebase -r subset -d dest
 
@@ -33,28 +38,28 @@  def debugbruterebase(ui, repo, source, d
         def getdesc(rev):
             result = cl.changelogrevision(rev).description
             if rev >= repolen:
-                result += "'"
+                result += b"'"
             return result
 
-        for i in xrange(1, 2 ** len(srevs)):
+        for i in range(1, 2 ** len(srevs)):
             subset = [rev for j, rev in enumerate(srevs) if i & (1 << j) != 0]
-            spec = revsetlang.formatspec('%ld', subset)
-            tr = repo.transaction('rebase')
+            spec = revsetlang.formatspec(b'%ld', subset)
+            tr = repo.transaction(b'rebase')
             tr.report = lambda x: 0 # hide "transaction abort"
 
             ui.pushbuffer()
             try:
                 rebase.rebase(ui, repo, dest=dest, rev=[spec])
             except error.Abort as ex:
-                summary = 'ABORT: %s' % ex
+                summary = b'ABORT: %s' % ex
             except Exception as ex:
-                summary = 'CRASH: %s' % ex
+                summary = b'CRASH: %s' % ex
             else:
                 # short summary about new nodes
                 cl = repo.changelog
                 descs = []
                 for rev in xrange(repolen, len(repo)):
-                    desc = '%s:' % getdesc(rev)
+                    desc = b'%s:' % getdesc(rev)
                     for prev in cl.parentrevs(rev):
                         if prev > -1:
                             desc += getdesc(prev)
@@ -62,8 +67,8 @@  def debugbruterebase(ui, repo, source, d
                 descs.sort()
                 summary = ' '.join(descs)
             ui.popbuffer()
-            repo.vfs.tryunlink('rebasestate')
+            repo.vfs.tryunlink(b'rebasestate')
 
-            subsetdesc = ''.join(getdesc(rev) for rev in subset)
-            ui.write(('%s: %s\n') % (subsetdesc.rjust(len(srevs)), summary))
+            subsetdesc = b''.join(getdesc(rev) for rev in subset)
+            ui.write((b'%s: %s\n') % (subsetdesc.rjust(len(srevs)), summary))
             tr.abort()