Comment 4 for bug 196881

Revision history for this message
Alexander Belchenko (bialix) wrote : Re: [Bug 196881] Re: Exception redirecting merge output to a file

Robert Collins пишет:
> On Fri, 2008-02-29 at 10:07 +0000, Alexander Belchenko wrote:
>> Here the simple patch. Someone need to write test for it :-)
>>
>> === modified file 'bzrlib/builtins.py'
>> --- bzrlib/builtins.py 2008-02-25 07:28:29 +0000
>> +++ bzrlib/builtins.py 2008-02-29 10:06:23 +0000
>> @@ -3003,8 +3003,9 @@
>> mutter("%s", stored_location)
>> if stored_location is None:
>> raise errors.BzrCommandError("No location specified or remembered")
>> + terminal_encoding = self.outf.encoding or osutils.get_terminal_encoding()
>> display_url = urlutils.unescape_for_display(stored_location,
>> - self.outf.encoding)
>> + terminal_encoding)
>> self.outf.write("%s remembered location %s\n" % (verb_string,
>> display_url))
>> return stored_location
>
> perhaps we should set self.outf_encoding in the command infrastructure,
> and have a
> self.unescape_for_display(stored_location)
> which does
> return urlutils.unescape_for_display(url, self.outf_encoding)

The problem in this particular bug is the fact the 'merge' command uses
encoding = 'exact' so self.outf is actually sys.stdout and therefore is not encoded.
So for situation `bzr merge > /tmp/foo` sys.stdout.encoding is None.
And therefore self.outf.encoding is None. So the bug occurs.
Introducing self.outf_encoding in this situation is artificial.
Because it will be different value than sys.stdout.encoding.

Actually my patch could be simplified even more:

=== modified file 'bzrlib/builtins.py'
--- bzrlib/builtins.py 2008-02-25 07:28:29 +0000
+++ bzrlib/builtins.py 2008-02-29 11:38:47 +0000
@@ -3004,7 +3004,7 @@
          if stored_location is None:
              raise errors.BzrCommandError("No location specified or remembered")
          display_url = urlutils.unescape_for_display(stored_location,
- self.outf.encoding)
+ osutils.get_terminal_encoding())
          self.outf.write("%s remembered location %s\n" % (verb_string,
              display_url))
          return stored_location