~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/identitymap.py

  • Committer: Robert Collins
  • Date: 2005-10-11 02:41:25 UTC
  • mto: This revision was merged to the branch mainline in revision 1438.
  • Revision ID: robertc@robertcollins.net-20051011024125-4e05fd2ffc83c965
cache revision history during read transactions

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    that is store in the map. Look for find_CLASS and add_CLASS methods.
30
30
    """
31
31
 
 
32
    def add_revision_history(self, revision_history):
 
33
        """Add a revision_history object to the map.
 
34
 
 
35
        There can only be one!
 
36
        """
 
37
        if self._revision_history is not None:
 
38
            raise errors.BzrError("A revision history (%s) is already "
 
39
                                  "identity map" % self._revision_history)
 
40
        self._revision_history = revision_history
 
41
 
32
42
    def add_weave(self, id, weave):
33
43
        """Add weave to the map with a given id."""
34
44
        if self._weave_key(id) in self._map:
36
46
        self._map[self._weave_key(id)] = weave
37
47
        self._reverse_map[weave] = self._weave_key(id)
38
48
 
 
49
    def find_revision_history(self):
 
50
        return self._revision_history
 
51
 
39
52
    def find_weave(self, id):
40
53
        """Return the weave for 'id', or None if it is not present."""
41
54
        return self._map.get(self._weave_key(id), None)
44
57
        super(IdentityMap, self).__init__()
45
58
        self._map = {}
46
59
        self._reverse_map = {}
 
60
        self._revision_history = None
47
61
 
48
62
    def remove_object(self, an_object):
49
 
        """Remove object from map if it is present."""
50
 
        if an_object in self._reverse_map:
 
63
        """Remove object from map."""
 
64
        if isinstance(an_object, list):
 
65
            if self._revision_history is an_object:
 
66
                self._revision_history = None
 
67
            else:
 
68
                raise KeyError('%r not in identity map' % an_object)
 
69
        else:
51
70
            self._map.pop(self._reverse_map[an_object])
52
71
            self._reverse_map.pop(an_object)
53
72
        
66
85
    def add_weave(self, id, weave):
67
86
        """See IdentityMap.add_weave."""
68
87
 
 
88
    def add_revision_history(self, revision_history):
 
89
        """See IdentityMap.add_revision_history."""
 
90
 
69
91
    def find_weave(self, id):
70
92
        """See IdentityMap.find_weave."""
71
93
        return None
72
94
 
 
95
    def find_revision_history(self):
 
96
        """See IdentityMap.find_revision_history."""