# HG changeset patch # User Matt Harbison # Date 2018-10-02 01:48:45 # Node ID a063b84ce064e173c052ced424feede2ca6b1cd7 # Parent 2b4c8fa0850403d63949b0d34da4fdad116f18bf py3: byteify contrib/dumprevlog 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)