~bzr/ubuntu/lucid/bzr/beta-ppa

« back to all changes in this revision

Viewing changes to bzrlib/chk_map.py

  • Committer: Martin Pool
  • Date: 2010-08-18 04:26:39 UTC
  • mfrom: (129.1.8 packaging-karmic)
  • Revision ID: mbp@sourcefrog.net-20100818042639-mjoxtngyjwiu05fo
* PPA rebuild for lucid.
* PPA rebuild for karmic.
* PPA rebuild onto jaunty.
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
_INTERESTING_NEW_SIZE = 50
91
91
# If a ChildNode shrinks by more than this amount, we check for a remap
92
92
_INTERESTING_SHRINKAGE_LIMIT = 20
93
 
# If we delete more than this many nodes applying a delta, we check for a remap
94
 
_INTERESTING_DELETES_LIMIT = 5
95
93
 
96
94
 
97
95
def _search_key_plain(key):
135
133
            into the map; if old_key is not None, then the old mapping
136
134
            of old_key is removed.
137
135
        """
138
 
        delete_count = 0
 
136
        has_deletes = False
139
137
        # Check preconditions first.
140
138
        as_st = StaticTuple.from_sequence
141
139
        new_items = set([as_st(key) for (old, key, value) in delta
148
146
        for old, new, value in delta:
149
147
            if old is not None and old != new:
150
148
                self.unmap(old, check_remap=False)
151
 
                delete_count += 1
 
149
                has_deletes = True
152
150
        for old, new, value in delta:
153
151
            if new is not None:
154
152
                self.map(new, value)
155
 
        if delete_count > _INTERESTING_DELETES_LIMIT:
156
 
            trace.mutter("checking remap as %d deletions", delete_count)
 
153
        if has_deletes:
157
154
            self._check_remap()
158
155
        return self._save()
159
156
 
573
570
        """Check if nodes can be collapsed."""
574
571
        self._ensure_root()
575
572
        if type(self._root_node) is InternalNode:
576
 
            self._root_node._check_remap(self._store)
 
573
            self._root_node = self._root_node._check_remap(self._store)
577
574
 
578
575
    def _save(self):
579
576
        """Save the map completely.
692
689
        the key/value pairs.
693
690
    """
694
691
 
695
 
    __slots__ = ('_common_serialised_prefix', '_serialise_key')
 
692
    __slots__ = ('_common_serialised_prefix',)
696
693
 
697
694
    def __init__(self, search_key_func=None):
698
695
        Node.__init__(self)
699
696
        # All of the keys in this leaf node share this common prefix
700
697
        self._common_serialised_prefix = None
701
 
        self._serialise_key = '\x00'.join
702
698
        if search_key_func is None:
703
699
            self._search_key_func = _search_key_plain
704
700
        else:
888
884
                raise AssertionError('%r must be known' % self._search_prefix)
889
885
            return self._search_prefix, [("", self)]
890
886
 
 
887
    _serialise_key = '\x00'.join
 
888
 
891
889
    def serialise(self, store):
892
890
        """Serialise the LeafNode to store.
893
891
 
1726
1724
 
1727
1725
try:
1728
1726
    from bzrlib._chk_map_pyx import (
 
1727
        _bytes_to_text_key,
1729
1728
        _search_key_16,
1730
1729
        _search_key_255,
1731
1730
        _deserialise_leaf_node,
1734
1733
except ImportError, e:
1735
1734
    osutils.failed_to_load_extension(e)
1736
1735
    from bzrlib._chk_map_py import (
 
1736
        _bytes_to_text_key,
1737
1737
        _search_key_16,
1738
1738
        _search_key_255,
1739
1739
        _deserialise_leaf_node,