[MERGE] Make annotate behave in a non-ASCII world (v1)
John Arbash Meinel
john at arbash-meinel.com
Fri Jul 6 19:50:28 BST 2007
John Arbash Meinel has voted +1 (conditional).
Status is now: Semi-approved
Comment:
to_file.encoding can be None (it happens when you redirect stdout such
as:
bzr annotate foo | vim -R -)
So this line:
+ to_file.write(anno.encode(to_file.encoding, 'replace'))
Should probably be:
encoding = osutils.get_terminal_encoding()
to_file.write(anno.encode(encoding, 'replace'))
We should also have a test for that. You might look at
bzrlib.tests.StringIOWrapper which allows you to set an 'encoding'
attribute on a StringIO object. (This is especially important because it
is a time when you are fairly likely to get an encoding error).
I think we should have a mention of why the try/except happens in a
comment next to the try/except. Something like:
# cmd_annotate should be passing in an 'exact' object, which means we
have
# a direct handle to sys.stdout or equivalent.
# It may not be able to handle the exact Unicode characters, but
'annotate'
# is a user function (non-scripting), so shouldn't die because of
# unrepresentable annotation characters.
# So encode using 'replace', and write them again.
For details, see:
http://bundlebuggy.aaronbentley.com/request/%3C20070706174823.GA16658%40chistera.yi.org%3E
More information about the bazaar
mailing list