py3: byteify contrib/dumprevlog
authorMatt Harbison <matt_harbison@yahoo.com>
Mon, 01 Oct 2018 21:48:45 -0400
changeset 39947 a063b84ce064
parent 39946 2b4c8fa08504
child 39948 5ee3146c1b20
py3: byteify contrib/dumprevlog
contrib/dumprevlog
contrib/python3-whitelist
contrib/undumprevlog
--- a/contrib/dumprevlog	Mon Oct 01 19:39:05 2018 -0400
+++ b/contrib/dumprevlog	Mon Oct 01 21:48:45 2018 -0400
@@ -6,7 +6,9 @@
 
 import sys
 from mercurial import (
+    encoding,
     node,
+    pycompat,
     revlog,
 )
 from mercurial.utils import (
@@ -16,22 +18,26 @@
 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-")
--- a/contrib/python3-whitelist	Mon Oct 01 19:39:05 2018 -0400
+++ b/contrib/python3-whitelist	Mon Oct 01 21:48:45 2018 -0400
@@ -92,6 +92,7 @@
 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
--- a/contrib/undumprevlog	Mon Oct 01 19:39:05 2018 -0400
+++ b/contrib/undumprevlog	Mon Oct 01 21:48:45 2018 -0400
@@ -7,7 +7,9 @@
 
 import sys
 from mercurial import (
+    encoding,
     node,
+    pycompat,
     revlog,
     transaction,
     vfs as vfsmod,
@@ -19,17 +21,17 @@
 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 @@
     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)