win32: bzr cat is unusable on Windows

Bug #55276 reported by Alexander Belchenko
4
Affects Status Importance Assigned to Milestone
Bazaar
Fix Released
High
Alexander Belchenko

Bug Description

bzr command 'cat' is unusable on Windows because it emit content of file to stabdard stdout that opened on win32 in text mode. So all '\n' converted to '\r\n'. It's make it unusable to obtain past version of file because it mangle line-endings. Especially it affects binary files.

Possible solutions:

1. Reopen sys.stdout in binary mode
2. Provide additional flag for command like '--output=filename' to write file content directly to specified file (as alternative to usage 'bzr cat file1 -rN > file2').

This issue also affects 'diff' and 'bundle-revisions' commands.

Revision history for this message
John A Meinel (jameinel) wrote :

I did write this plugin:
http://bzr.arbash-meinel.com/plugins/binary_sys/

Which changes sys.stdout, and sys.stderr so that they are switched to binary mode.

I was planning on making something more explicit (commands that need exact preservation would call a function to enable binary mode).

But I haven't gotten around to it yet.
It could be a simple helper function on Command. And a command like cmd_diff could just call 'self.set_binary_output()' before it continued to do more work.

Revision history for this message
Alexander Belchenko (bialix) wrote : Re: [Bug 55276] Re: win32: bzr cat is unusable on Windows

John A Meinel пишет:
> I did write this plugin:
> http://bzr.arbash-meinel.com/plugins/binary_sys/
>
> Which changes sys.stdout, and sys.stderr so that they are switched to
> binary mode.
>
> I was planning on making something more explicit (commands that need
> exact preservation would call a function to enable binary mode).
>
> But I haven't gotten around to it yet.
> It could be a simple helper function on Command. And a command like cmd_diff could just call 'self.set_binary_output()' before it continued to do more work.

I'm thinking about another special attribute as part of Command object
definition. Something similar to encoding_type that you did for encoding
stuff.

Per example, commands like cat, diff, bundle could have attribute

 binary_stdout = True

and when outf object is created based on this flag sys.stdout will be
forced to binary mode.

Revision history for this message
John A Meinel (jameinel) wrote :

It is fairly important that we make sys.stdout work in binary mode when necessary. I'm marking this as high, though we can decrease the importance if we decide it isn't critical.

Changed in bzr:
importance: Undecided → High
status: Unconfirmed → Confirmed
Revision history for this message
Henry Ludemann (misc-hl) wrote :

The way I did this to test 'bundle' was to add

fileobj = sys.stdout
# On Windows switch to binary output (we don't want new line
# conversion on the output stream)
if sys.platform == "win32":
    import os, msvcrt
    msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)

This allowed
   bzr bundle >changes.bundle
...go to another branch...
   bzr merge ..\changes.bundle
which previously failed with
   bzr: ERROR: End of line marker was not \n in bzr revision-bundle

Changed in bzr:
assignee: nobody → bialix
Changed in bzr:
status: Confirmed → In Progress
Revision history for this message
Alexander Belchenko (bialix) wrote :

It's finally happens!

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

Other bug subscribers

Remote bug watches

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