~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/identitymap.py

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 by Canonical Ltd
 
1
# Copyright (C) 2005 Canonical Ltd
2
2
#   Authors: Robert Collins <robert.collins@canonical.com>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
18
18
"""This module provides an IdentityMap."""
19
19
 
20
20
 
21
 
import bzrlib.errors as errors
 
21
from bzrlib import (
 
22
    errors,
 
23
    osutils,
 
24
    )
22
25
 
23
26
 
24
27
class IdentityMap(object):
29
32
    that is store in the map. Look for find_CLASS and add_CLASS methods.
30
33
    """
31
34
 
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
 
 
42
35
    def add_weave(self, id, weave):
43
36
        """Add weave to the map with a given id."""
44
37
        if self._weave_key(id) in self._map:
46
39
        self._map[self._weave_key(id)] = weave
47
40
        self._reverse_map[weave] = self._weave_key(id)
48
41
 
49
 
    def find_revision_history(self):
50
 
        return self._revision_history
51
 
 
52
42
    def find_weave(self, id):
53
43
        """Return the weave for 'id', or None if it is not present."""
54
44
        return self._map.get(self._weave_key(id), None)
57
47
        super(IdentityMap, self).__init__()
58
48
        self._map = {}
59
49
        self._reverse_map = {}
60
 
        self._revision_history = None
61
50
 
62
51
    def remove_object(self, an_object):
63
52
        """Remove object from map."""
64
53
        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)
 
54
            raise KeyError('%r not in identity map' % an_object)
69
55
        else:
70
56
            self._map.pop(self._reverse_map[an_object])
71
57
            self._reverse_map.pop(an_object)
84
70
    def add_weave(self, id, weave):
85
71
        """See IdentityMap.add_weave."""
86
72
 
87
 
    def add_revision_history(self, revision_history):
88
 
        """See IdentityMap.add_revision_history."""
89
 
 
90
73
    def find_weave(self, id):
91
74
        """See IdentityMap.find_weave."""
92
75
        return None
93
 
 
94
 
    def find_revision_history(self):
95
 
        """See IdentityMap.find_revision_history."""