bjoernricks / python-quilt

A quilt implementation in python
MIT License
10 stars 3 forks source link

Avoid writing applied-patches file with CRLFs in Windows #23

Closed vadmium closed 7 years ago

vadmium commented 7 years ago

Demonstration of the trailing CRs confusing Quilt; it seems you have to pop more than one patch, with at least three patches applied:

$ cat <<EOF >patches/series
> a
> b
> c
> EOF
$ pquilt push -a  # Creates ".pc/applied-patches" with CRLFs
Applying patch a
Patch a does not exist; applied empty patch
Applying patch b
Patch b does not exist; applied empty patch
Applying patch c
Patch c does not exist; applied empty patch
Now at patch c
$ quilt pop -a  # Interprets one of the CRs as part of patch name
Patch patches/c appears to be empty, removing

Patch patches/b appears to be empty, removing
rmdir: failed to remove '.pc/b'$'\r': No such file or directory
bjoernricks commented 7 years ago

Do you know where the \r does come from? Does f.write("\n") also add a \r? I was not aware of any problems with this until know. Maybe something has changed in python3.

bjoernricks commented 7 years ago

Ok. Just read the python3 docu for open

"When writing output to the stream, if newline is None, any '\n' characters written are translated to the system default line separator,"

I really wasn't aware of this changed behavior. In python2 it requires to set open(..., "U") to get universal newlines. Thanks for finding this python2/3 error on windows.

vadmium commented 7 years ago

You are right about the newline translation with Python 3. However a similar translation happens with Python 2, so this is not a Python 2 vs 3 thing, just a Windows vs Unix thing.

In Python 2, the w or wb mode is passed directly to ’s fopen function. On Windows, w means text mode and the Windows C library translates newlines to CRLF. In Python 3, it is Python (rather than Windows) that does the translation, but the effect is similar.