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

  • Committer: Jelmer Vernooij
  • Date: 2018-01-08 16:45:05 UTC
  • mfrom: (6842.1.2 move-add-reference)
  • Revision ID: jelmer@jelmer.uk-20180108164505-yz76bj6rgje62o5c
Merge lp:~jelmer/brz/move-add-reference.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
    )
36
36
 
37
37
 
 
38
class BadReferenceTarget(errors.InternalBzrError):
 
39
 
 
40
    _fmt = "Can't add reference to %(other_tree)s into %(tree)s." \
 
41
           "%(reason)s"
 
42
 
 
43
    def __init__(self, tree, other_tree, reason):
 
44
        self.tree = tree
 
45
        self.other_tree = other_tree
 
46
        self.reason = reason
 
47
 
 
48
 
38
49
class MutableTree(tree.Tree):
39
50
    """A MutableTree is a specialisation of Tree which is able to be mutated.
40
51
 
127
138
            self._add(files, ids, kinds)
128
139
 
129
140
    def add_reference(self, sub_tree):
130
 
        """Add a TreeReference to the tree, pointing at sub_tree"""
 
141
        """Add a TreeReference to the tree, pointing at sub_tree.
 
142
 
 
143
        :param sub_tree: subtree to add.
 
144
        """
131
145
        raise errors.UnsupportedOperation(self.add_reference, self)
132
146
 
133
 
    def _add_reference(self, sub_tree):
134
 
        """Standard add_reference implementation, for use by subclasses"""
135
 
        try:
136
 
            sub_tree_path = self.relpath(sub_tree.basedir)
137
 
        except errors.PathNotChild:
138
 
            raise errors.BadReferenceTarget(self, sub_tree,
139
 
                                            'Target not inside tree.')
140
 
        sub_tree_id = sub_tree.get_root_id()
141
 
        if sub_tree_id == self.get_root_id():
142
 
            raise errors.BadReferenceTarget(self, sub_tree,
143
 
                                     'Trees have the same root id.')
144
 
        if self.has_id(sub_tree_id):
145
 
            raise errors.BadReferenceTarget(self, sub_tree,
146
 
                                            'Root id already present in tree')
147
 
        self._add([sub_tree_path], [sub_tree_id], ['tree-reference'])
148
 
 
149
147
    def _add(self, files, ids, kinds):
150
148
        """Helper function for add - updates the inventory.
151
149