Patchwork [2,of,6] py3: byteify contrib/dumprevlog

login
register
mail settings
Submitter Matt Harbison
Date Oct. 2, 2018, 4:30 a.m.
Message ID <b5b1d9a89ccecb117232.1538454632@Envy>
Download mbox | patch
Permalink /patch/35282/
State Accepted
Headers show

Comments

Matt Harbison - Oct. 2, 2018, 4:30 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1538444925 14400
#      Mon Oct 01 21:48:45 2018 -0400
# Node ID b5b1d9a89ccecb117232f4175ad80dfe1b66101a
# Parent  f03d553395ca841edc5bd3bc5953758c2ed8e16a
py3: byteify contrib/dumprevlog

Patch

diff --git a/contrib/dumprevlog b/contrib/dumprevlog
--- a/contrib/dumprevlog
+++ b/contrib/dumprevlog
@@ -6,7 +6,9 @@  from __future__ import absolute_import, 
 
 import sys
 from mercurial import (
+    encoding,
     node,
+    pycompat,
     revlog,
 )
 from mercurial.utils import (
@@ -16,22 +18,26 @@  from mercurial.utils import (
 for fp in (sys.stdin, sys.stdout, sys.stderr):
     procutil.setbinary(fp)
 
-def binopen(path, mode='rb'):
-    if 'b' not in mode:
-        mode = mode + 'b'
-    return open(path, mode)
+def binopen(path, mode=b'rb'):
+    if b'b' not in mode:
+        mode = mode + b'b'
+    return open(path, pycompat.sysstr(mode))
+
+def printb(data, end=b'\n'):
+    sys.stdout.flush()
+    pycompat.stdout.write(data + end)
 
 for f in sys.argv[1:]:
-    r = revlog.revlog(binopen, f)
+    r = revlog.revlog(binopen, encoding.strtolocal(f))
     print("file:", f)
     for i in r:
         n = r.node(i)
         p = r.parents(n)
         d = r.revision(n)
-        print("node:", node.hex(n))
-        print("linkrev:", r.linkrev(i))
-        print("parents:", node.hex(p[0]), node.hex(p[1]))
-        print("length:", len(d))
-        print("-start-")
-        print(d)
-        print("-end-")
+        printb(b"node: %s" % node.hex(n))
+        printb(b"linkrev: %d" % r.linkrev(i))
+        printb(b"parents: %s %s" % (node.hex(p[0]), node.hex(p[1])))
+        printb(b"length: %d" % len(d))
+        printb(b"-start-")
+        printb(d)
+        printb(b"-end-")
diff --git a/contrib/python3-whitelist b/contrib/python3-whitelist
--- a/contrib/python3-whitelist
+++ b/contrib/python3-whitelist
@@ -92,6 +92,7 @@  test-convert-cvs-synthetic.t
 test-convert-cvs.t
 test-convert-cvsnt-mergepoints.t
 test-convert-datesort.t
+test-contrib-dumprevlog.t
 test-convert-filemap.t
 test-convert-hg-sink.t
 test-convert-hg-source.t
diff --git a/contrib/undumprevlog b/contrib/undumprevlog
--- a/contrib/undumprevlog
+++ b/contrib/undumprevlog
@@ -7,7 +7,9 @@  from __future__ import absolute_import, 
 
 import sys
 from mercurial import (
+    encoding,
     node,
+    pycompat,
     revlog,
     transaction,
     vfs as vfsmod,
@@ -19,17 +21,17 @@  from mercurial.utils import (
 for fp in (sys.stdin, sys.stdout, sys.stderr):
     procutil.setbinary(fp)
 
-opener = vfsmod.vfs('.', False)
-tr = transaction.transaction(sys.stderr.write, opener, {'store': opener},
-                             "undump.journal")
+opener = vfsmod.vfs(b'.', False)
+tr = transaction.transaction(sys.stderr.write, opener, {b'store': opener},
+                             b"undump.journal")
 while True:
     l = sys.stdin.readline()
     if not l:
         break
     if l.startswith("file:"):
-        f = l[6:-1]
+        f = encoding.strtolocal(l[6:-1])
         r = revlog.revlog(opener, f)
-        print(f)
+        pycompat.stdout.write(b'%s\n' % f)
     elif l.startswith("node:"):
         n = node.bin(l[6:-1])
     elif l.startswith("linkrev:"):
@@ -41,7 +43,7 @@  while True:
     elif l.startswith("length:"):
         length = int(l[8:-1])
         sys.stdin.readline() # start marker
-        d = sys.stdin.read(length)
+        d = encoding.strtolocal(sys.stdin.read(length))
         sys.stdin.readline() # end marker
         r.addrevision(d, tr, lr, p1, p2)