Mercurial > hg
view contrib/dumprevlog @ 49248:63fd0282ad40
node: stop converting binascii.Error to TypeError in bin()
Changeset f574cc00831a introduced the wrapper, to make bin() behave like on
Python 2, where it raised TypeError in many cases. Another previous approach,
changing callers to catch binascii.Error in addition to TypeError, was backed
out after negative review feedback [1].
However, I think it’s worth reconsidering the approach. Now that we’re on
Python 3 only, callers have to catch only binascii.Error instead of both.
Catching binascii.Error instead of TypeError has the advantage that it’s less
likely to cover a programming error (e.g. passing an int to bin() raises
TypeError). Also, raising TypeError never made sense semantically when bin()
got an argument of valid type.
As a side-effect, this fixed an exception in test-http-bad-server.t. The TODO
was outdated: it was not an uncaught ValueError in batch.results() but uncaught
TypeError from the now removed wrapper. Now that bin() raises binascii.Error
instead of TypeError, it gets converted to a proper error in
wirepeer.heads.<locals>.decode() that catches ValueError (superclass of
binascii.Error). This is a good example of why this changeset is a good idea.
Catching TypeError instead of ValueError there would not make much sense.
[1] https://phab.mercurial-scm.org/D2244
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Mon, 30 May 2022 16:18:12 +0200 |
parents | 6000f5b25c9b |
children |
line wrap: on
line source
#!/usr/bin/env python3 # Dump revlogs as raw data stream # $ find .hg/store/ -name "*.i" | xargs dumprevlog > repo.dump import sys from mercurial.node import hex from mercurial import ( encoding, pycompat, revlog, ) from mercurial.utils import procutil from mercurial.revlogutils import ( constants as revlog_constants, ) for fp in (sys.stdin, sys.stdout, sys.stderr): procutil.setbinary(fp) def binopen(path, mode=b'rb'): if b'b' not in mode: mode = mode + b'b' return open(path, pycompat.sysstr(mode)) binopen.options = {} def printb(data, end=b'\n'): sys.stdout.flush() procutil.stdout.write(data + end) for f in sys.argv[1:]: localf = encoding.strtolocal(f) if not localf.endswith(b'.i'): print("file:", f, file=sys.stderr) print(" invalid filename", file=sys.stderr) r = revlog.revlog( binopen, target=(revlog_constants.KIND_OTHER, b'dump-revlog'), radix=localf[:-2], ) print("file:", f) for i in r: n = r.node(i) p = r.parents(n) d = r.revision(n) printb(b"node: %s" % hex(n)) printb(b"linkrev: %d" % r.linkrev(i)) printb(b"parents: %s %s" % (hex(p[0]), hex(p[1]))) printb(b"length: %d" % len(d)) printb(b"-start-") printb(d) printb(b"-end-")