/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: Jelmer Vernooij
  • Date: 2011-12-19 10:58:39 UTC
  • mfrom: (6383 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6386.
  • Revision ID: jelmer@canonical.com-20111219105839-uji05ck4rkm1mj4j
Merge bzr.dev.

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
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
 
18
 
17
19
"""Persistent maps from tuple_of_strings->string using CHK stores.
18
20
 
19
21
Overview and current status:
37
39
 
38
40
"""
39
41
 
 
42
from __future__ import absolute_import
 
43
 
40
44
import heapq
41
45
import threading
42
46
 
44
48
lazy_import.lazy_import(globals(), """
45
49
from bzrlib import (
46
50
    errors,
47
 
    versionedfile,
48
51
    )
49
52
""")
50
53
from bzrlib import (
 
54
    errors,
51
55
    lru_cache,
52
56
    osutils,
53
57
    registry,
90
94
_INTERESTING_NEW_SIZE = 50
91
95
# If a ChildNode shrinks by more than this amount, we check for a remap
92
96
_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
97
 
96
98
 
97
99
def _search_key_plain(key):
135
137
            into the map; if old_key is not None, then the old mapping
136
138
            of old_key is removed.
137
139
        """
138
 
        delete_count = 0
 
140
        has_deletes = False
139
141
        # Check preconditions first.
140
142
        as_st = StaticTuple.from_sequence
141
143
        new_items = set([as_st(key) for (old, key, value) in delta
148
150
        for old, new, value in delta:
149
151
            if old is not None and old != new:
150
152
                self.unmap(old, check_remap=False)
151
 
                delete_count += 1
 
153
                has_deletes = True
152
154
        for old, new, value in delta:
153
155
            if new is not None:
154
156
                self.map(new, value)
155
 
        if delete_count > _INTERESTING_DELETES_LIMIT:
156
 
            trace.mutter("checking remap as %d deletions", delete_count)
 
157
        if has_deletes:
157
158
            self._check_remap()
158
159
        return self._save()
159
160
 
573
574
        """Check if nodes can be collapsed."""
574
575
        self._ensure_root()
575
576
        if type(self._root_node) is InternalNode:
576
 
            self._root_node._check_remap(self._store)
 
577
            self._root_node = self._root_node._check_remap(self._store)
577
578
 
578
579
    def _save(self):
579
580
        """Save the map completely.
923
924
        bytes = ''.join(lines)
924
925
        if len(bytes) != self._current_size():
925
926
            raise AssertionError('Invalid _current_size')
926
 
        _get_cache().add(self._key, bytes)
 
927
        _get_cache()[self._key] = bytes
927
928
        return [self._key]
928
929
 
929
930
    def refs(self):
1196
1197
                    prefix, node_key_filter = keys[record.key]
1197
1198
                    node_and_filters.append((node, node_key_filter))
1198
1199
                    self._items[prefix] = node
1199
 
                    _get_cache().add(record.key, bytes)
 
1200
                    _get_cache()[record.key] = bytes
1200
1201
                for info in node_and_filters:
1201
1202
                    yield info
1202
1203
 
1322
1323
            lines.append(serialised[prefix_len:])
1323
1324
        sha1, _, _ = store.add_lines((None,), (), lines)
1324
1325
        self._key = StaticTuple("sha1:" + sha1,).intern()
1325
 
        _get_cache().add(self._key, ''.join(lines))
 
1326
        _get_cache()[self._key] = ''.join(lines)
1326
1327
        yield self._key
1327
1328
 
1328
1329
    def _search_key(self, key):
1372
1373
        return self._search_prefix
1373
1374
 
1374
1375
    def unmap(self, store, key, check_remap=True):
1375
 
        """Remove key from this node and it's children."""
 
1376
        """Remove key from this node and its children."""
1376
1377
        if not len(self._items):
1377
1378
            raise AssertionError("can't unmap in an empty InternalNode.")
1378
1379
        children = [node for node, _
1727
1728
 
1728
1729
try:
1729
1730
    from bzrlib._chk_map_pyx import (
 
1731
        _bytes_to_text_key,
1730
1732
        _search_key_16,
1731
1733
        _search_key_255,
1732
1734
        _deserialise_leaf_node,
1735
1737
except ImportError, e:
1736
1738
    osutils.failed_to_load_extension(e)
1737
1739
    from bzrlib._chk_map_py import (
 
1740
        _bytes_to_text_key,
1738
1741
        _search_key_16,
1739
1742
        _search_key_255,
1740
1743
        _deserialise_leaf_node,