/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: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2011 Canonical Ltd
 
1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
44
44
lazy_import.lazy_import(globals(), """
45
45
from bzrlib import (
46
46
    errors,
 
47
    versionedfile,
47
48
    )
48
49
""")
49
50
from bzrlib import (
89
90
_INTERESTING_NEW_SIZE = 50
90
91
# If a ChildNode shrinks by more than this amount, we check for a remap
91
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
92
95
 
93
96
 
94
97
def _search_key_plain(key):
132
135
            into the map; if old_key is not None, then the old mapping
133
136
            of old_key is removed.
134
137
        """
135
 
        has_deletes = False
 
138
        delete_count = 0
136
139
        # Check preconditions first.
137
140
        as_st = StaticTuple.from_sequence
138
141
        new_items = set([as_st(key) for (old, key, value) in delta
145
148
        for old, new, value in delta:
146
149
            if old is not None and old != new:
147
150
                self.unmap(old, check_remap=False)
148
 
                has_deletes = True
 
151
                delete_count += 1
149
152
        for old, new, value in delta:
150
153
            if new is not None:
151
154
                self.map(new, value)
152
 
        if has_deletes:
 
155
        if delete_count > _INTERESTING_DELETES_LIMIT:
 
156
            trace.mutter("checking remap as %d deletions", delete_count)
153
157
            self._check_remap()
154
158
        return self._save()
155
159
 
569
573
        """Check if nodes can be collapsed."""
570
574
        self._ensure_root()
571
575
        if type(self._root_node) is InternalNode:
572
 
            self._root_node = self._root_node._check_remap(self._store)
 
576
            self._root_node._check_remap(self._store)
573
577
 
574
578
    def _save(self):
575
579
        """Save the map completely.
1368
1372
        return self._search_prefix
1369
1373
 
1370
1374
    def unmap(self, store, key, check_remap=True):
1371
 
        """Remove key from this node and its children."""
 
1375
        """Remove key from this node and it's children."""
1372
1376
        if not len(self._items):
1373
1377
            raise AssertionError("can't unmap in an empty InternalNode.")
1374
1378
        children = [node for node, _
1723
1727
 
1724
1728
try:
1725
1729
    from bzrlib._chk_map_pyx import (
1726
 
        _bytes_to_text_key,
1727
1730
        _search_key_16,
1728
1731
        _search_key_255,
1729
1732
        _deserialise_leaf_node,
1732
1735
except ImportError, e:
1733
1736
    osutils.failed_to_load_extension(e)
1734
1737
    from bzrlib._chk_map_py import (
1735
 
        _bytes_to_text_key,
1736
1738
        _search_key_16,
1737
1739
        _search_key_255,
1738
1740
        _deserialise_leaf_node,