~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/chk_map.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-04-05 14:47:26 UTC
  • mfrom: (5752.2.11 2.4-windows-lfstat)
  • Revision ID: pqm@pqm.ubuntu.com-20110405144726-zi3lj2kwvjml4kx5
(jameinel) Add osutils.lstat/fstat so that even on Windows lstat(fname) ==
 fstat(open(fname).fileno()) (John A Meinel)

Show diffs side-by-side

added added

removed removed

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