/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/mutabletree.py

  • Committer: Marius Kruger
  • Date: 2007-03-23 18:29:56 UTC
  • mfrom: (2374 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2455.
  • Revision ID: amanic@gmail.com-20070323182956-5vestftm6gx3o9mz
merge with bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 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
20
20
"""
21
21
 
22
22
 
23
 
from bzrlib import tree
 
23
from bzrlib import (
 
24
    errors,
 
25
    osutils,
 
26
    tree,
 
27
    )
24
28
from bzrlib.decorators import needs_read_lock, needs_write_lock
25
29
from bzrlib.osutils import splitpath
26
30
from bzrlib.symbol_versioning import DEPRECATED_PARAMETER
58
62
    branch and bzrdir attributes.
59
63
    """
60
64
 
61
 
    @needs_write_lock
 
65
    @needs_tree_write_lock
62
66
    def add(self, files, ids=None, kinds=None):
63
67
        """Add paths to the set of versioned paths.
64
68
 
86
90
            if kinds is not None:
87
91
                kinds = [kinds]
88
92
 
 
93
        files = [path.strip('/') for path in files]
 
94
 
89
95
        if ids is None:
90
96
            ids = [None] * len(files)
91
97
        else:
92
98
            assert(len(ids) == len(files))
 
99
            ids = [osutils.safe_file_id(file_id) for file_id in ids]
93
100
 
94
101
        if kinds is None:
95
102
            kinds = [None] * len(files)
106
113
        self._gather_kinds(files, kinds)
107
114
        self._add(files, ids, kinds)
108
115
 
 
116
    def add_reference(self, sub_tree):
 
117
        """Add a TreeReference to the tree, pointing at sub_tree"""
 
118
        raise errors.UnsupportedOperation(self.add_reference, self)
 
119
 
 
120
    def _add_reference(self, sub_tree):
 
121
        """Standard add_reference implementation, for use by subclasses"""
 
122
        try:
 
123
            sub_tree_path = self.relpath(sub_tree.basedir)
 
124
        except errors.PathNotChild:
 
125
            raise errors.BadReferenceTarget(self, sub_tree,
 
126
                                            'Target not inside tree.')
 
127
        sub_tree_id = sub_tree.get_root_id()
 
128
        if sub_tree_id == self.get_root_id():
 
129
            raise errors.BadReferenceTarget(self, sub_tree,
 
130
                                     'Trees have the same root id.')
 
131
        if sub_tree_id in self.inventory:
 
132
            raise errors.BadReferenceTarget(self, sub_tree,
 
133
                                            'Root id already present in tree')
 
134
        self._add([sub_tree_path], [sub_tree_id], ['tree-reference'])
 
135
 
109
136
    def _add(self, files, ids, kinds):
110
 
        """Helper function for add - updates the inventory."""
 
137
        """Helper function for add - updates the inventory.
 
138
 
 
139
        :param files: sequence of pathnames, relative to the tree root
 
140
        :param ids: sequence of suggested ids for the files (may be None)
 
141
        :param kinds: sequence of  inventory kinds of the files (i.e. may
 
142
            contain "tree-reference")
 
143
        """
111
144
        raise NotImplementedError(self._add)
112
145
 
113
146
    @needs_write_lock
114
 
    def commit(self, message=None, revprops=None, *args, **kwargs):
 
147
    def commit(self, message=None, revprops=None, *args,
 
148
               **kwargs):
115
149
        # avoid circular imports
116
150
        from bzrlib import commit
117
151
        if revprops is None: