/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: Canonical.com Patch Queue Manager
  • Date: 2009-07-20 08:56:45 UTC
  • mfrom: (4526.9.23 apply-inventory-delta)
  • Revision ID: pqm@pqm.ubuntu.com-20090720085645-54mtgybxua0yx6hw
(robertc) Add checks for inventory deltas which try to ensure that
        deltas that are not an exact fit are not applied. (Robert
        Collins, bug 397705, bug 367633)

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
Updates to a CHKMap are done preferentially via the apply_delta method, to
28
28
allow optimisation of the update operation; but individual map/unmap calls are
29
 
possible and supported. All changes via map/unmap are buffered in memory until
30
 
the _save method is called to force serialisation of the tree. apply_delta
31
 
performs a _save implicitly.
 
29
possible and supported. Individual changes via map/unmap are buffered in memory
 
30
until the _save method is called to force serialisation of the tree.
 
31
apply_delta records its changes immediately by performing an implicit _save.
32
32
 
33
33
TODO:
34
34
-----
41
41
 
42
42
from bzrlib import lazy_import
43
43
lazy_import.lazy_import(globals(), """
44
 
from bzrlib import versionedfile
 
44
from bzrlib import (
 
45
    errors,
 
46
    versionedfile,
 
47
    )
45
48
""")
46
49
from bzrlib import (
47
50
    lru_cache,
105
108
            of old_key is removed.
106
109
        """
107
110
        delete_count = 0
 
111
        # Check preconditions first.
 
112
        new_items = set([key for (old, key, value) in delta if key is not None
 
113
            and old is None])
 
114
        existing_new = list(self.iteritems(key_filter=new_items))
 
115
        if existing_new:
 
116
            raise errors.InconsistentDeltaDelta(delta,
 
117
                "New items are already in the map %r." % existing_new)
 
118
        # Now apply changes.
108
119
        for old, new, value in delta:
109
120
            if old is not None and old != new:
110
121
                self.unmap(old, check_remap=False)
482
493
        return len(self._root_node)
483
494
 
484
495
    def map(self, key, value):
485
 
        """Map a key tuple to value."""
 
496
        """Map a key tuple to value.
 
497
        
 
498
        :param key: A key to map.
 
499
        :param value: The value to assign to key.
 
500
        """
486
501
        # Need a root object.
487
502
        self._ensure_root()
488
503
        prefix, node_details = self._root_node.map(self._store, key, value)