/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/chk_map.py

  • Committer: John Arbash Meinel
  • Date: 2009-10-21 21:19:41 UTC
  • mto: This revision was merged to the branch mainline in revision 4771.
  • Revision ID: john@arbash-meinel.com-20091021211941-3kldzti7r77q9q74
Cleanup some code paths. Make _check_key a helper that can be used
but isn't currently used.

Show diffs side-by-side

added added

removed removed

Lines of Context:
222
222
        root_key = klass._create_directly(store, initial_value,
223
223
            maximum_size=maximum_size, key_width=key_width,
224
224
            search_key_func=search_key_func)
225
 
        assert type(root_key) is StaticTuple
 
225
        if type(root_key) is not StaticTuple:
 
226
            raise AssertionError('we got a %s instead of a StaticTuple'
 
227
                                 % (type(root_key),))
226
228
        return root_key
227
229
 
228
230
    @classmethod
263
265
            for split, subnode in node_details:
264
266
                node.add_node(split, subnode)
265
267
        keys = list(node.serialise(store))
266
 
        root_node = keys[-1]
267
 
        assert (type(root_node) is StaticTuple
268
 
                and len(root_node) == 1 and
269
 
                type(root_node[0]) is str)
270
 
        return root_node
 
268
        return keys[-1]
271
269
 
272
270
    def iter_changes(self, basis):
273
271
        """Iterate over the changes between basis and self.
493
491
    def iteritems(self, key_filter=None):
494
492
        """Iterate over the entire CHKMap's contents."""
495
493
        self._ensure_root()
496
 
        # TODO: StaticTuple Barrier here
497
494
        if key_filter is not None:
498
495
            as_st = StaticTuple.from_sequence
499
496
            key_filter = [as_st(key) for key in key_filter]
502
499
    def key(self):
503
500
        """Return the key for this map."""
504
501
        if type(self._root_node) is StaticTuple:
505
 
            _check_key(self._root_node)
506
502
            return self._root_node
507
503
        else:
508
504
            return self._root_node._key
536
532
        if type(node) is tuple:
537
533
            node = StaticTuple.from_sequence(node)
538
534
        if type(node) is StaticTuple:
539
 
            _check_key(node)
540
535
            return node
541
536
        else:
542
537
            return node._key
567
562
            # Already saved.
568
563
            return self._root_node
569
564
        keys = list(self._root_node.serialise(self._store))
570
 
        assert type(keys[-1]) is StaticTuple
571
565
        return keys[-1]
572
566
 
573
567
 
1025
1019
        :return: An InternalNode instance.
1026
1020
        """
1027
1021
        if type(key) is not StaticTuple:
1028
 
            import pdb; pdb.set_trace()
1029
 
        key = StaticTuple.from_sequence(key).intern()
 
1022
            raise AssertionError('deserialise should be called with a'
 
1023
                                 ' StaticTuple not %s' % (type(key),))
1030
1024
        return _deserialise_internal_node(bytes, key,
1031
1025
                                          search_key_func=search_key_func)
1032
1026
 
1460
1454
 
1461
1455
    def __init__(self, store, new_root_keys, old_root_keys,
1462
1456
                 search_key_func, pb=None):
 
1457
        # TODO: Should we add a StaticTuple barrier here? It would be nice to
 
1458
        #       force callers to use StaticTuple, because there will often be
 
1459
        #       lots of keys passed in here. And even if we cast it locally,
 
1460
        #       that just meanst that we will have *both* a StaticTuple and a
 
1461
        #       tuple() in memory, referring to the same object. (so a net
 
1462
        #       increase in memory, not a decrease.)
1463
1463
        self._store = store
1464
1464
        self._new_root_keys = new_root_keys
1465
1465
        self._old_root_keys = old_root_keys
1684
1684
search_key_registry.register('hash-16-way', _search_key_16)
1685
1685
search_key_registry.register('hash-255-way', _search_key_255)
1686
1686
 
 
1687
 
1687
1688
def _check_key(key):
 
1689
    """Helper function to assert that a key is properly formatted.
 
1690
 
 
1691
    This generally shouldn't be used in production code, but it can be helpful
 
1692
    to debug problems.
 
1693
    """
1688
1694
    if type(key) is not StaticTuple:
1689
1695
        raise TypeError('key %r is not StaticTuple but %s' % (key, type(key)))
1690
1696
    if len(key) != 1: