Rev 3825: Merge latest brisbane-core in http://bzr.arbash-meinel.com/branches/bzr/brisbane/generic_fetch_ordering

John Arbash Meinel john at arbash-meinel.com
Wed Feb 18 19:06:54 GMT 2009


At http://bzr.arbash-meinel.com/branches/bzr/brisbane/generic_fetch_ordering

------------------------------------------------------------
revno: 3825
revision-id: john at arbash-meinel.com-20090218190640-8gg8c7fpxfarfhqi
parent: john at arbash-meinel.com-20090218174043-p6k4m0d4x9qchyxt
parent: john at arbash-meinel.com-20090218190455-017wzogx5qzao31b
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: generic_fetch_ordering
timestamp: Wed 2009-02-18 13:06:40 -0600
message:
  Merge latest brisbane-core
modified:
  bzrlib/chk_map.py              chk_map.py-20081001014447-ue6kkuhofvdecvxa-1
  bzrlib/tests/test_chk_map.py   test_chk_map.py-20081001014447-ue6kkuhofvdecvxa-2
    ------------------------------------------------------------
    revno: 3821.1.6
    revision-id: john at arbash-meinel.com-20090218190455-017wzogx5qzao31b
    parent: john at arbash-meinel.com-20090218185430-2p19pxixb42vvi96
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: brisbane-core
    timestamp: Wed 2009-02-18 13:04:55 -0600
    message:
      Update the test suite for the new crc32 code.
    modified:
      bzrlib/tests/test_chk_map.py   test_chk_map.py-20081001014447-ue6kkuhofvdecvxa-2
    ------------------------------------------------------------
    revno: 3821.1.5
    revision-id: john at arbash-meinel.com-20090218185430-2p19pxixb42vvi96
    parent: v.ladeuil+lp at free.fr-20090218183029-pxxh3pa0c37fpr71
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: brisbane-core
    timestamp: Wed 2009-02-18 12:54:30 -0600
    message:
      Remove an accidental pdb statement.
    modified:
      bzrlib/tests/test_chk_map.py   test_chk_map.py-20081001014447-ue6kkuhofvdecvxa-2
    ------------------------------------------------------------
    revno: 3821.1.4
    revision-id: v.ladeuil+lp at free.fr-20090218183029-pxxh3pa0c37fpr71
    parent: v.ladeuil+lp at free.fr-20090218174441-hnuhu4umzhe0iia2
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: brisbane-core
    timestamp: Wed 2009-02-18 19:30:29 +0100
    message:
      Fix the bogus previous fix.
      
      * tests/test_chk_map.py:
      (TestNode.assertCommonPrefix): Also check the expected result.
      
      * chk_map.py:
      (Node.common_prefix): Oops, off-by-one error in the previous fix.
    modified:
      bzrlib/chk_map.py              chk_map.py-20081001014447-ue6kkuhofvdecvxa-1
      bzrlib/tests/test_chk_map.py   test_chk_map.py-20081001014447-ue6kkuhofvdecvxa-2
    ------------------------------------------------------------
    revno: 3821.1.3
    revision-id: v.ladeuil+lp at free.fr-20090218174441-hnuhu4umzhe0iia2
    parent: v.ladeuil+lp at free.fr-20090218174058-78wmg76zgjgu1o32
    parent: john at arbash-meinel.com-20090218163618-isb3yg01ygdx3m2n
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: brisbane-core
    timestamp: Wed 2009-02-18 18:44:41 +0100
    message:
      Merge John pb fixes
    modified:
      bzrlib/chk_map.py              chk_map.py-20081001014447-ue6kkuhofvdecvxa-1
      bzrlib/fetch.py                fetch.py-20050818234941-26fea6105696365d
    ------------------------------------------------------------
    revno: 3821.1.2
    revision-id: v.ladeuil+lp at free.fr-20090218174058-78wmg76zgjgu1o32
    parent: v.ladeuil+lp at free.fr-20090218165051-75ql383s2rhyv24j
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: brisbane-core
    timestamp: Wed 2009-02-18 18:40:58 +0100
    message:
      Same player shoots again, zlib.crc32, we'll get you.
      
      * bzrlib/tests/test_chk_map.py:
      (TestMapSearchKeys.test_search_key_16): Update tests.
      
      * bzrlib/chk_map.py:
      (_crc32): Factor out the problematic use of zlib.crc32 and mask it
      to ensure python version/platform compatibility.
      (_search_key_16, _search_key_255): Use _crc32.
    modified:
      bzrlib/chk_map.py              chk_map.py-20081001014447-ue6kkuhofvdecvxa-1
      bzrlib/tests/test_chk_map.py   test_chk_map.py-20081001014447-ue6kkuhofvdecvxa-2
    ------------------------------------------------------------
    revno: 3821.1.1
    revision-id: v.ladeuil+lp at free.fr-20090218165051-75ql383s2rhyv24j
    parent: john at arbash-meinel.com-20090218161422-9ncxfaeoqnmy59ee
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: brisbane-core
    timestamp: Wed 2009-02-18 17:50:51 +0100
    message:
      Stop using assert in code.
      
      * bzrlib/tests/test_chk_map.py:
      (TestNode): Related tests.
      
      * bzrlib/chk_map.py:
      (Node.common_prefix): Asserts are for tests not code :)
    modified:
      bzrlib/chk_map.py              chk_map.py-20081001014447-ue6kkuhofvdecvxa-1
      bzrlib/tests/test_chk_map.py   test_chk_map.py-20081001014447-ue6kkuhofvdecvxa-2
-------------- next part --------------
=== modified file 'bzrlib/chk_map.py'
--- a/bzrlib/chk_map.py	2009-02-18 16:36:18 +0000
+++ b/bzrlib/chk_map.py	2009-02-18 18:30:29 +0000
@@ -65,17 +65,7 @@
     return '\x00'.join(key)
 
 
-def _search_key_16(key):
-    """Map the key tuple into a search key string which has 16-way fan out."""
-    return '\x00'.join(['%08X' % abs(zlib.crc32(bit)) for bit in key])
-
-
-def _search_key_255(key):
-    """Map the key tuple into a search key string which has 255-way fan out.
-
-    We use 255-way because '\n' is used as a delimiter, and causes problems
-    while parsing.
-    """
+def _crc32(bit):
     # Depending on python version and platform, zlib.crc32 will return either a
     # signed (<= 2.5 >= 3.0) or an unsigned (2.5, 2.6).
     # http://docs.python.org/library/zlib.html recommends using a mask to force
@@ -87,8 +77,21 @@
     #       anyway.
     #       Though we really don't need that 32nd bit of accuracy. (even 2**24
     #       is probably enough node fan out for realistic trees.)
-    bytes = '\x00'.join([struct.pack('>L', zlib.crc32(bit)&0xFFFFFFFF)
-                         for bit in key])
+    return zlib.crc32(bit)&0xFFFFFFFF
+
+
+def _search_key_16(key):
+    """Map the key tuple into a search key string which has 16-way fan out."""
+    return '\x00'.join(['%08X' % _crc32(bit) for bit in key])
+
+
+def _search_key_255(key):
+    """Map the key tuple into a search key string which has 255-way fan out.
+
+    We use 255-way because '\n' is used as a delimiter, and causes problems
+    while parsing.
+    """
+    bytes = '\x00'.join([struct.pack('>L', _crc32(bit)) for bit in key])
     return bytes.replace('\n', '_')
 
 
@@ -511,10 +514,7 @@
             if left != right:
                 pos -= 1
                 break
-        assert pos <= len(prefix)
-        assert pos <= len(key)
         common = prefix[:pos+1]
-        assert key.startswith(common)
         return common
 
     @classmethod

=== modified file 'bzrlib/tests/test_chk_map.py'
--- a/bzrlib/tests/test_chk_map.py	2009-02-13 20:28:20 +0000
+++ b/bzrlib/tests/test_chk_map.py	2009-02-18 19:04:55 +0000
@@ -27,11 +27,32 @@
     CHKMap,
     InternalNode,
     LeafNode,
+    Node,
     )
-from bzrlib.tests import TestCaseWithTransport
-
-
-class TestCaseWithStore(TestCaseWithTransport):
+
+
+class TestNode(tests.TestCase):
+
+    def assertCommonPrefix(self, expected_common, prefix, key):
+        common = Node.common_prefix(prefix, key)
+        self.assertTrue(len(common) <= len(prefix))
+        self.assertTrue(len(common) <= len(key))
+        self.assertStartsWith(prefix, common)
+        self.assertStartsWith(key, common)
+        self.assertEquals(expected_common, common)
+
+    def test_common_prefix(self):
+        self.assertCommonPrefix('beg', 'beg', 'begin')
+
+    def test_no_common_prefix(self):
+        self.assertCommonPrefix('', 'begin', 'end')
+
+    def test_equal(self):
+        self.assertCommonPrefix('begin', 'begin', 'begin')
+
+    def test_not_a_prefix(self):
+        self.assertCommonPrefix('b', 'begin', 'b')
+class TestCaseWithStore(tests.TestCaseWithTransport):
 
     def get_chk_bytes(self):
         # The eassiest way to get a CHK store is a development5 repository and
@@ -1083,7 +1104,7 @@
                              "      ('2',) 'bar'\n"
                              "  '6' LeafNode\n"
                              "      ('3',) 'baz'\n"
-                             "  '7' LeafNode\n"
+                             "  '8' LeafNode\n"
                              "      ('1',) 'foo'\n"
                              , chkmap._dump_tree())
         root_key = chkmap._save()
@@ -1097,7 +1118,7 @@
                              "      ('2',) 'bar'\n"
                              "  '6' LeafNode\n"
                              "      ('3',) 'baz'\n"
-                             "  '7' LeafNode\n"
+                             "  '8' LeafNode\n"
                              "      ('1',) 'foo'\n"
                              , chkmap._dump_tree())
 
@@ -1158,10 +1179,10 @@
         self.assertEqual(expected, actual, 'actual: %r' % (actual,))
 
     def test_simple_16(self):
-        self.assertSearchKey16('738C9ADF', ('foo',))
-        self.assertSearchKey16('738C9ADF\x00738C9ADF', ('foo', 'foo'))
-        self.assertSearchKey16('738C9ADF\x0076FF8CAA', ('foo', 'bar'))
-        self.assertSearchKey16('127D32EF', ('abcd',))
+        self.assertSearchKey16('8C736521', ('foo',))
+        self.assertSearchKey16('8C736521\x008C736521', ('foo', 'foo'))
+        self.assertSearchKey16('8C736521\x0076FF8CAA', ('foo', 'bar'))
+        self.assertSearchKey16('ED82CD11', ('abcd',))
 
     def test_simple_255(self):
         self.assertSearchKey255('\x8cse!', ('foo',))



More information about the bazaar-commits mailing list