[MERGE] Make annotate behave in a non-ASCII world (v2)
Adeodato Simó
dato at net.com.org.es
Fri Jul 6 21:30:13 BST 2007
* John Arbash Meinel [Fri, 06 Jul 2007 14:50:28 -0400]:
> John Arbash Meinel has voted +1 (conditional).
> Status is now: Semi-approved
Okay, many thanks for the review. Attached is a bundle addressing all of
the raised issues, and here is the partial diff:
=== modified file 'bzrlib/annotate.py'
--- bzrlib/annotate.py 2007-07-06 17:21:57 +0000
+++ bzrlib/annotate.py 2007-07-06 20:25:37 +0000
@@ -30,6 +30,7 @@
from bzrlib import (
errors,
+ osutils,
patiencediff,
tsort,
)
@@ -82,7 +83,15 @@
try:
to_file.write(anno)
except UnicodeEncodeError:
- to_file.write(anno.encode(to_file.encoding, 'replace'))
+ # 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.
+ encoding = getattr(to_file, 'encoding', None) or \
+ osutils.get_terminal_encoding()
+ to_file.write(anno.encode(encoding, 'replace'))
print >>to_file, '| %s' % (text,)
prevanno=anno
=== modified file 'bzrlib/tests/test_annotate.py'
--- bzrlib/tests/test_annotate.py 2007-07-06 17:45:52 +0000
+++ bzrlib/tests/test_annotate.py 2007-07-06 20:22:29 +0000
@@ -327,6 +327,17 @@
annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
self.assertEqualDiff('2 p?rez | bye\n', sio.getvalue())
+ # test now with to_file.encoding = None
+ to_file = tests.StringIOWrapper()
+ to_file.encoding = None
+ annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
+ self.assertContainsRe('2 p.rez | bye\n', sio.getvalue())
+
+ # and when it does not exist
+ to_file = StringIO()
+ annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
+ self.assertContainsRe('2 p.rez | bye\n', sio.getvalue())
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
The output depends on the actual terminal encoding, so I
thought this was the best way to cope with that.
Cheers,
--
Adeodato Simó dato at net.com.org.es
Debian Developer adeodato at debian.org
Hey, I am a young, desirable woman.
-- Lorelai Gilmore, addressing two cats in her porch
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bzr.annotate_fixes.diff
Type: text/x-diff
Size: 13864 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20070706/3bc2be13/attachment.bin
More information about the bazaar
mailing list