Exception redirecting merge output to a file

Bug #196881 reported by Ian Clatworthy
10
Affects Status Importance Assigned to Milestone
Bazaar
Fix Released
High
Ian Clatworthy

Bug Description

running "bzr merge > /tmp/merge.out" causes an exception. That's really annoying when running benchmarks, e.g. in usertest where output is redirected to /dev/null. Here's the exception:

bzr: ERROR: exceptions.AssertionError: you cannot specify None for the display encoding.

Traceback (most recent call last):
  File "/home/ian/bzr/repo.packs/bzr.dev/bzrlib/commands.py", line 834, in run_bzr_catch_errors
    return run_bzr(argv)
  File "/home/ian/bzr/repo.packs/bzr.dev/bzrlib/commands.py", line 790, in run_bzr
    ret = run(*run_argv)
  File "/home/ian/bzr/repo.packs/bzr.dev/bzrlib/commands.py", line 492, in run_argv_aliases
    return self.run(**all_cmd_args)
  File "/home/ian/bzr/repo.packs/bzr.dev/bzrlib/builtins.py", line 2852, in run
    location, revision, remember, possible_transports, pb)
  File "/home/ian/bzr/repo.packs/bzr.dev/bzrlib/builtins.py", line 2923, in _get_merger_from_branch
    revision, -1)
  File "/home/ian/bzr/repo.packs/bzr.dev/bzrlib/builtins.py", line 2990, in _select_branch_location
    location = self._get_remembered(tree, 'Merging from')
  File "/home/ian/bzr/repo.packs/bzr.dev/bzrlib/builtins.py", line 3007, in _get_remembered
    self.outf.encoding)
  File "/home/ian/bzr/repo.packs/bzr.dev/bzrlib/urlutils.py", line 576, in unescape_for_display
    assert encoding is not None, 'you cannot specify None for the display encoding.'
AssertionError: you cannot specify None for the display encoding.

bzr 1.3.0.dev.0 on python 2.5.1.final.0 (linux2)
arguments: ['/home/ian/bin/bzr', 'merge']
encoding: 'UTF-8', fsenc: 'UTF-8', lang: 'en_AU.UTF-8'

Related branches

Revision history for this message
Alexander Belchenko (bialix) wrote :

it should be actually easy fix.

Changed in bzr:
importance: Undecided → Medium
status: New → Confirmed
importance: Medium → High
Revision history for this message
Alexander Belchenko (bialix) 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

Revision history for this message
Robert Collins (lifeless) wrote : Re: [Bug 196881] Re: Exception redirecting merge output to a file

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)

?

--
GPG key available at: <http://www.robertcollins.net/keys.txt>.

Revision history for this message
Alexander Belchenko (bialix) wrote :

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

Changed in bzr:
assignee: nobody → ian-clatworthy
status: Confirmed → Fix Committed
Revision history for this message
Vincent Ladeuil (vila) wrote :

Fix Released in revno 3254 included in 1.3

Changed in bzr:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.