[BUG] bundle cannot handle binary files

Alexander Belchenko bialix at ukr.net
Sat Jul 8 14:06:28 BST 2006


Alexander Belchenko пишет:
> I run merge process in debugger and I think I found where problem is.
> Here the code in bundle_data.py:
> 
> def patched_file(file_patch, original):
>     """Produce a file-like object with the patched version of a text"""
>     from bzrlib.patches import iter_patched
>     from bzrlib.iterablefile import IterableFile
>     if file_patch == "":
>         return IterableFile(())
>     return IterableFile(iter_patched(original, 
> file_patch.splitlines(True)))
> 
> 
> Here file_patch is string that contain diff of binary file. 
> Unfortunately inside this diff (i.e. inside binary file itself) there is 
> '\r' character. And function
> 
> file_patch.splitlines(True)
> 
> split lines of patch by '\n' and '\r' *also*. And therefore this 
> function breaks normal diff into malformed diff.
> 
> So, yes, I agree, it's win32-specific bug in string.splitlines().
> 
> In [3]: 'aaaa\rbbbb\r\nccc\nddd'.splitlines(True)
> Out[3]: ['aaaa\r', 'bbbb\r\n', 'ccc\n', 'ddd']
> 
> BTW, in bundle_data.py inside function def _get_inventory() (approx. 
> line 645) there is also potentially non-cross-platforming statement:
> 
> from os.path import dirname, basename

I propose next fix to avoid .splitlines() method and use fast 
alternative StringIO.readlines():

=== modified file 'bzrlib/bundle/bundle_data.py'
--- bzrlib/bundle/bundle_data.py	2006-06-22 18:24:25 +0000
+++ bzrlib/bundle/bundle_data.py	2006-07-08 13:05:08 +0000
@@ -723,4 +723,5 @@
      from bzrlib.iterablefile import IterableFile
      if file_patch == "":
          return IterableFile(())
-    return IterableFile(iter_patched(original, 
file_patch.splitlines(True)))
+    return IterableFile(iter_patched(original,
+                                     StringIO(file_patch).readlines()))


In this file already use StringIO class from cStringIO module.
After making this change I can merge my binary.patch successfully.

--
Alexander





More information about the bazaar mailing list