# HG changeset patch # User Marcin Kuzminski # Date 2012-10-03 18:20:16 # Node ID 2654edfb1700279236a5a0cb8047e08029b56e36 # Parent eb180eb16c18a1982797c88ea062f3136f42775d fixes #591 git backend was causing encoding errors when handling binary files - added a test case for VCS lib tests diff --git a/rhodecode/lib/vcs/backends/git/inmemory.py b/rhodecode/lib/vcs/backends/git/inmemory.py --- a/rhodecode/lib/vcs/backends/git/inmemory.py +++ b/rhodecode/lib/vcs/backends/git/inmemory.py @@ -63,10 +63,16 @@ class GitInMemoryChangeset(BaseInMemoryC # If found, updates parent parent = self.repository._repo[dir_id] ancestors.append((curdir, parent)) - # Now parent is deepest exising tree and we need to create subtrees + # Now parent is deepest existing tree and we need to create subtrees # for dirnames (in reverse order) [this only applies for nodes from added] new_trees = [] - blob = objects.Blob.from_string(node.content.encode(ENCODING)) + + if not node.is_binary: + content = node.content.encode(ENCODING) + else: + content = node.content + blob = objects.Blob.from_string(content) + node_path = node.name.encode(ENCODING) if dirnames: # If there are trees which should be created we need to build diff --git a/rhodecode/tests/vcs/test_inmemchangesets.py b/rhodecode/tests/vcs/test_inmemchangesets.py --- a/rhodecode/tests/vcs/test_inmemchangesets.py +++ b/rhodecode/tests/vcs/test_inmemchangesets.py @@ -44,6 +44,7 @@ class InMemoryChangesetTestMixin(object) FileNode('foobar2', content='Foo & bar, doubled!'), FileNode('foo bar with spaces', content=''), FileNode('foo/bar/baz', content='Inside'), + FileNode('foo/bar/file.bin', content='\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00;\x00\x03\x00\xfe\xff\t\x00\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x1a\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x18\x00\x00\x00\x01\x00\x00\x00\xfe\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff'), ] def test_add(self):