~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/identitymap.py

  • Committer: Martin Pool
  • Date: 2005-08-17 02:06:19 UTC
  • Revision ID: mbp@sourcefrog.net-20050817020618-c7ae430253df8532
- rearrangement of modules, contributed by Gustavo Niemeyer


1) Moved plugins directory to bzrlib/, so that there's a standard
  plugin directory which is not only installed with bzr itself
  but is also available when using bzr from the development tree.
  BZR_PLUGIN_PATH and DEFAULT_PLUGIN_PATH are then added to the
  standard plugins directory.

2) Moved the needed third-party tools to an internal directory under
  bzrlib/util.  This makes sure that needed tools are available in
  the bzr installation, including the correct/expected version, and
  eases the process of packaging and redistribution of bzr
  ('setup.py bdist*' creates a working distribution).

3) Fixed setup.py including the needed package entries.

I hope you find them useful.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
2
 
#   Authors: Robert Collins <robert.collins@canonical.com>
3
 
#
4
 
# This program is free software; you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation; either version 2 of the License, or
7
 
# (at your option) any later version.
8
 
#
9
 
# This program is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
# GNU General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU General Public License
15
 
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
 
 
18
 
"""This module provides an IdentityMap."""
19
 
 
20
 
 
21
 
from bzrlib import (
22
 
    errors,
23
 
    )
24
 
 
25
 
 
26
 
class IdentityMap(object):
27
 
    """An in memory map from object id to instance.
28
 
 
29
 
    An IdentityMap maps from keys to single instances of objects in memory.
30
 
    We have explicit calls on the map for the root of each inheritance tree
31
 
    that is store in the map. Look for find_CLASS and add_CLASS methods.
32
 
    """
33
 
 
34
 
    def add_weave(self, id, weave):
35
 
        """Add weave to the map with a given id."""
36
 
        if self._weave_key(id) in self._map:
37
 
            raise errors.BzrError('weave %s already in the identity map' % id)
38
 
        self._map[self._weave_key(id)] = weave
39
 
        self._reverse_map[weave] = self._weave_key(id)
40
 
 
41
 
    def find_weave(self, id):
42
 
        """Return the weave for 'id', or None if it is not present."""
43
 
        return self._map.get(self._weave_key(id), None)
44
 
 
45
 
    def __init__(self):
46
 
        super(IdentityMap, self).__init__()
47
 
        self._map = {}
48
 
        self._reverse_map = {}
49
 
 
50
 
    def remove_object(self, an_object):
51
 
        """Remove object from map."""
52
 
        if isinstance(an_object, list):
53
 
            raise KeyError('%r not in identity map' % an_object)
54
 
        else:
55
 
            self._map.pop(self._reverse_map[an_object])
56
 
            self._reverse_map.pop(an_object)
57
 
 
58
 
    def _weave_key(self, id):
59
 
        """Return the key for a weaves id."""
60
 
        return "weave-" + id
61
 
 
62
 
 
63
 
class NullIdentityMap(object):
64
 
    """A pretend in memory map from object id to instance.
65
 
 
66
 
    A NullIdentityMap is an Identity map that does not store anything in it.
67
 
    """
68
 
 
69
 
    def add_weave(self, id, weave):
70
 
        """See IdentityMap.add_weave."""
71
 
 
72
 
    def find_weave(self, id):
73
 
        """See IdentityMap.find_weave."""
74
 
        return None