Rev 6070: Fix bug #1010339. in http://bazaar.launchpad.net/~jameinel/bzr/2.4-testament-binary-1010339

John Arbash Meinel john at arbash-meinel.com
Fri Jun 8 06:59:46 UTC 2012


At http://bazaar.launchpad.net/~jameinel/bzr/2.4-testament-binary-1010339

------------------------------------------------------------
revno: 6070
revision-id: john at arbash-meinel.com-20120608065950-3ldv3l9qal3g1rtu
parent: pqm at pqm.ubuntu.com-20120329104349-70dq6u8qbionntav
fixes bug: https://launchpad.net/bugs/1010339
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.4-testament-binary-1010339
timestamp: Fri 2012-06-08 08:59:50 +0200
message:
  Fix bug #1010339.
  
  'bzr testament' should use exact encoding for its output. It previously simulated
  this by using sys.stdout directly, but that does not set binary mode on Windows.
-------------- next part --------------
=== modified file 'bzrlib/btree_index.py'
--- a/bzrlib/btree_index.py	2011-05-19 09:32:38 +0000
+++ b/bzrlib/btree_index.py	2012-06-08 06:59:50 +0000
@@ -294,7 +294,9 @@
             flag when writing out. This is used by the _spill_mem_keys_to_disk
             functionality.
         """
+        new_leaf = False
         if rows[-1].writer is None:
+            new_leaf = True
             # opening a new leaf chunk;
             for pos, internal_row in enumerate(rows[:-1]):
                 # flesh out any internal nodes that are needed to
@@ -320,6 +322,10 @@
                 optimize_for_size=self._optimize_for_size)
             rows[-1].writer.write(_LEAF_FLAG)
         if rows[-1].writer.write(line):
+            if new_leaf:
+                # We just created this leaf, and now the line doesn't fit.
+                # Clearly it will never fit, so punt.
+                raise errors.BadIndexKey(line)
             # this key did not fit in the node:
             rows[-1].finish_node()
             key_line = string_key + "\n"

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2011-09-26 08:48:20 +0000
+++ b/bzrlib/builtins.py	2012-06-08 06:59:50 +0000
@@ -4718,6 +4718,7 @@
             Option('strict',
                    help='Produce a strict-format testament.')]
     takes_args = ['branch?']
+    encoding_type = 'exact'
     @display_command
     def run(self, branch=u'.', revision=None, long=False, strict=False):
         from bzrlib.testament import Testament, StrictTestament
@@ -4736,9 +4737,9 @@
             rev_id = revision[0].as_revision_id(b)
         t = testament_class.from_revision(b.repository, rev_id)
         if long:
-            sys.stdout.writelines(t.as_text_lines())
+            self.outf.writelines(t.as_text_lines())
         else:
-            sys.stdout.write(t.as_short_text())
+            self.outf.write(t.as_short_text())
 
 
 class cmd_annotate(Command):

=== modified file 'bzrlib/tests/blackbox/test_testament.py'
--- a/bzrlib/tests/blackbox/test_testament.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/blackbox/test_testament.py	2012-06-08 06:59:50 +0000
@@ -16,8 +16,10 @@
 
 """Blackbox tests for the 'bzr testament' command"""
 
+import re
 
 from bzrlib.tests.test_testament import (
+    osutils,
     REV_1_SHORT,
     REV_1_SHORT_STRICT,
     REV_2_TESTAMENT,
@@ -46,3 +48,12 @@
         self.assertEqualDiff(err, '')
         self.assertEqualDiff(out, REV_1_SHORT_STRICT)
 
+    def test_testament_non_ascii(self):
+        self.wt.commit(u"Non \xe5ssci message")
+        long_out, err = self.run_bzr('testament --long')
+        self.assertEqualDiff(err, '')
+        short_out, err = self.run_bzr('testament')
+        self.assertEqualDiff(err, '')
+        sha1_re = re.compile('sha1: (?P<sha1>[a-f0-9]+)$', re.M)
+        sha1 = sha1_re.search(short_out).group('sha1')
+        self.assertEqual(sha1, osutils.sha_string(long_out))

=== modified file 'doc/en/release-notes/bzr-2.4.txt'
--- a/doc/en/release-notes/bzr-2.4.txt	2012-03-28 14:04:31 +0000
+++ b/doc/en/release-notes/bzr-2.4.txt	2012-06-08 06:59:50 +0000
@@ -55,6 +55,10 @@
 * Prevent a traceback being printed to stderr when logging has problems and
   accept utf-8 byte string without breaking. (Martin Packman, #714449)
 
+* Use ``encoding_type='exact'`` for ``bzr testament`` so that on Windows
+  the sha hash of the long testament matches the sha hash in the short
+  form. (John Arbash Meinel, #1010339)
+
 * _Win32Stat object provides members st_uid and st_gid, those are present
   in Python's os.stat object. These members required for external tools like
   bzr-git and dulwich. (Alexander Belchenko, #967060)



More information about the bazaar-commits mailing list