/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: Martin Pool
  • Date: 2011-05-20 14:46:02 UTC
  • mto: This revision was merged to the branch mainline in revision 5923.
  • Revision ID: mbp@canonical.com-20110520144602-bqli0t6dj01gl0pv
Various pyflakes import fixes.

Some modules were used for subclassing or at module load time, so there is no
point loading them lazily.

Some were not imported when they should be.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2008-2011 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,
48
47
    )
49
48
""")
50
49
from bzrlib import (
 
50
    errors,
51
51
    lru_cache,
52
52
    osutils,
53
53
    registry,
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.
1372
1369
        return self._search_prefix
1373
1370
 
1374
1371
    def unmap(self, store, key, check_remap=True):
1375
 
        """Remove key from this node and it's children."""
 
1372
        """Remove key from this node and its children."""
1376
1373
        if not len(self._items):
1377
1374
            raise AssertionError("can't unmap in an empty InternalNode.")
1378
1375
        children = [node for node, _
1727
1724
 
1728
1725
try:
1729
1726
    from bzrlib._chk_map_pyx import (
 
1727
        _bytes_to_text_key,
1730
1728
        _search_key_16,
1731
1729
        _search_key_255,
1732
1730
        _deserialise_leaf_node,
1735
1733
except ImportError, e:
1736
1734
    osutils.failed_to_load_extension(e)
1737
1735
    from bzrlib._chk_map_py import (
 
1736
        _bytes_to_text_key,
1738
1737
        _search_key_16,
1739
1738
        _search_key_255,
1740
1739
        _deserialise_leaf_node,