Rev 2654: (Jonathan Lange) Fix bug #110092, when displaying a diff that includes a binary file, make sure the binary filenames are encoded in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Thu Jul 26 23:33:50 BST 2007
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 2654
revision-id: pqm at pqm.ubuntu.com-20070726223348-t2howycr63c04q7r
parent: pqm at pqm.ubuntu.com-20070726134355-tlidmsn3eux09idz
parent: john at arbash-meinel.com-20070726211835-z5v8xam1hk2omnq1
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2007-07-26 23:33:48 +0100
message:
(Jonathan Lange) Fix bug #110092, when displaying a diff that includes a binary file, make sure the binary filenames are encoded
modified:
bzrlib/diff.py diff.py-20050309040759-26944fbbf2ebbf36
bzrlib/inventory.py inventory.py-20050309040759-6648b84ca2005b37
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/test_diff.py testdiff.py-20050727164403-d1a3496ebb12e339
------------------------------------------------------------
revno: 2653.1.1
merged: john at arbash-meinel.com-20070726211835-z5v8xam1hk2omnq1
parent: pqm at pqm.ubuntu.com-20070726134355-tlidmsn3eux09idz
parent: jml at mumak.net-20070726074333-73de3l9k6hufjwbs
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: jam-integration
timestamp: Thu 2007-07-26 16:18:35 -0500
message:
(Jonathan Lange) Fix bug #110092, when displaying a diff that includes a binary file, make sure the binary filenames are encoded
------------------------------------------------------------
revno: 2592.2.5
merged: jml at mumak.net-20070726074333-73de3l9k6hufjwbs
parent: jml at mumak.net-20070718015656-nksl6vzrgwsglg32
committer: Jonathan Lange <jml at mumak.net>
branch nick: show-diff-trees-110092
timestamp: Thu 2007-07-26 17:43:33 +1000
message:
Make UnicodeFilename feature less insane. Add a simple test for it too.
------------------------------------------------------------
revno: 2592.2.4
merged: jml at mumak.net-20070718015656-nksl6vzrgwsglg32
parent: jml at mumak.net-20070717041850-v448ywifdsck5mxl
committer: Jonathan Lange <jml at mumak.net>
branch nick: show-diff-trees-110092
timestamp: Wed 2007-07-18 11:56:56 +1000
message:
Skip the unicode filename test if the platform doesn't support unicode
filenames.
------------------------------------------------------------
revno: 2592.2.3
merged: jml at mumak.net-20070717041850-v448ywifdsck5mxl
parent: jml at mumak.net-20070709073803-i1mxhzhlhs85u32j
parent: pqm at pqm.ubuntu.com-20070716205413-42lqws7bkld2gbju
committer: Jonathan Lange <jml at mumak.net>
branch nick: show-diff-trees-110092
timestamp: Tue 2007-07-17 14:18:50 +1000
message:
Merge bzr.dev.
------------------------------------------------------------
revno: 2592.2.2
merged: jml at mumak.net-20070709073803-i1mxhzhlhs85u32j
parent: jml at mumak.net-20070706122938-w2lpadadsd3do9cu
committer: Jonathan Lange <jml at mumak.net>
branch nick: show-diff-trees-110092
timestamp: Mon 2007-07-09 17:38:03 +1000
message:
Apply jam's comments to test_binary_unicode_filenames. Change the
'=== added' etc lines to print out the str() of the filename, rather than
the repr(). This means that unicode symbols are displayed.
------------------------------------------------------------
revno: 2592.2.1
merged: jml at mumak.net-20070706122938-w2lpadadsd3do9cu
parent: pqm at pqm.ubuntu.com-20070705224207-7pslqt12ofh4vnzx
committer: Jonathan Lange <jml at mumak.net>
branch nick: show-diff-trees-110092
timestamp: Fri 2007-07-06 22:29:38 +1000
message:
Reproduce and fix bug 110092.
When displaying a diff that includes a binary file, make sure the
binary file names are encoded.
=== modified file 'bzrlib/diff.py'
--- a/bzrlib/diff.py 2007-04-11 22:05:16 +0000
+++ b/bzrlib/diff.py 2007-07-09 07:38:03 +0000
@@ -436,7 +436,7 @@
has_changes = 0
for path, file_id, kind in delta.removed:
has_changes = 1
- print >>to_file, '=== removed %s %r' % (kind, path.encode('utf8'))
+ print >>to_file, "=== removed %s '%s'" % (kind, path.encode('utf8'))
old_name = '%s%s\t%s' % (old_label, path,
_patch_header_date(old_tree, file_id, path))
new_name = '%s%s\t%s' % (new_label, path, EPOCH_DATE)
@@ -444,7 +444,7 @@
new_name, None, None, to_file)
for path, file_id, kind in delta.added:
has_changes = 1
- print >>to_file, '=== added %s %r' % (kind, path.encode('utf8'))
+ print >>to_file, "=== added %s '%s'" % (kind, path.encode('utf8'))
old_name = '%s%s\t%s' % (old_label, path, EPOCH_DATE)
new_name = '%s%s\t%s' % (new_label, path,
_patch_header_date(new_tree, file_id, path))
@@ -455,7 +455,7 @@
text_modified, meta_modified) in delta.renamed:
has_changes = 1
prop_str = get_prop_change(meta_modified)
- print >>to_file, '=== renamed %s %r => %r%s' % (
+ print >>to_file, "=== renamed %s '%s' => %r%s" % (
kind, old_path.encode('utf8'),
new_path.encode('utf8'), prop_str)
old_name = '%s%s\t%s' % (old_label, old_path,
@@ -470,7 +470,8 @@
for path, file_id, kind, text_modified, meta_modified in delta.modified:
has_changes = 1
prop_str = get_prop_change(meta_modified)
- print >>to_file, '=== modified %s %r%s' % (kind, path.encode('utf8'), prop_str)
+ print >>to_file, "=== modified %s '%s'%s" % (kind, path.encode('utf8'),
+ prop_str)
# The file may be in a different location in the old tree (because
# the containing dir was renamed, but the file itself was not)
old_path = old_tree.id2path(file_id)
=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py 2007-07-17 20:04:13 +0000
+++ b/bzrlib/inventory.py 2007-07-26 21:18:35 +0000
@@ -665,7 +665,8 @@
label_pair = (to_label, from_label)
else:
label_pair = (from_label, to_label)
- print >> output_to, "Binary files %s and %s differ" % label_pair
+ print >> output_to, \
+ ("Binary files %s and %s differ" % label_pair).encode('utf8')
def has_text(self):
"""See InventoryEntry.has_text."""
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2007-07-22 17:19:18 +0000
+++ b/bzrlib/tests/__init__.py 2007-07-26 21:18:35 +0000
@@ -1640,7 +1640,7 @@
"""Return a writeable transport.
This transport is for the test scratch space relative to
- "self._test_root""
+ "self._test_root"
:param relpath: a path relative to the base url.
"""
=== modified file 'bzrlib/tests/test_diff.py'
--- a/bzrlib/tests/test_diff.py 2007-04-11 22:05:16 +0000
+++ b/bzrlib/tests/test_diff.py 2007-07-26 21:18:35 +0000
@@ -24,10 +24,39 @@
from bzrlib.errors import BinaryFile, NoDiff
import bzrlib.osutils as osutils
import bzrlib.patiencediff
-from bzrlib.tests import (TestCase, TestCaseWithTransport,
+from bzrlib.tests import (Feature, TestCase, TestCaseWithTransport,
TestCaseInTempDir, TestSkipped)
+class _UnicodeFilename(Feature):
+ """Does the filesystem support Unicode filenames?"""
+
+ def _probe(self):
+ try:
+ os.stat(u'\u03b1')
+ except UnicodeEncodeError:
+ return False
+ except (IOError, OSError):
+ # The filesystem allows the Unicode filename but the file doesn't
+ # exist.
+ return True
+ else:
+ # The filesystem allows the Unicode filename and the file exists,
+ # for some reason.
+ return True
+
+UnicodeFilename = _UnicodeFilename()
+
+
+class TestUnicodeFilename(TestCase):
+
+ def test_probe_passes(self):
+ """UnicodeFilename._probe passes."""
+ # We can't test much more than that because the behaviour depends
+ # on the platform.
+ UnicodeFilename._probe()
+
+
def udiff_lines(old, new, allow_binary=False):
output = StringIO()
internal_diff('old', old, 'new', new, output, allow_binary)
@@ -441,6 +470,34 @@
self.assertContainsRe(diff, '-contents\n'
'\\+new contents\n')
+ def test_binary_unicode_filenames(self):
+ """Test that contents of files are *not* encoded in UTF-8 when there
+ is a binary file in the diff.
+ """
+ # See https://bugs.launchpad.net/bugs/110092.
+ self.requireFeature(UnicodeFilename)
+
+ # This bug isn't triggered with cStringIO.
+ from StringIO import StringIO
+ tree = self.make_branch_and_tree('tree')
+ alpha, omega = u'\u03b1', u'\u03c9'
+ alpha_utf8, omega_utf8 = alpha.encode('utf8'), omega.encode('utf8')
+ self.build_tree_contents(
+ [('tree/' + alpha, chr(0)),
+ ('tree/' + omega,
+ ('The %s and the %s\n' % (alpha_utf8, omega_utf8)))])
+ tree.add([alpha], ['file-id'])
+ tree.add([omega], ['file-id-2'])
+ diff_content = StringIO()
+ show_diff_trees(tree.basis_tree(), tree, diff_content)
+ diff = diff_content.getvalue()
+ self.assertContainsRe(diff, r"=== added file '%s'" % alpha_utf8)
+ self.assertContainsRe(
+ diff, "Binary files a/%s.*and b/%s.* differ\n" % (alpha_utf8, alpha_utf8))
+ self.assertContainsRe(diff, r"=== added file '%s'" % omega_utf8)
+ self.assertContainsRe(diff, r"--- a/%s" % (omega_utf8,))
+ self.assertContainsRe(diff, r"\+\+\+ b/%s" % (omega_utf8,))
+
class TestPatienceDiffLib(TestCase):
More information about the bazaar-commits
mailing list