~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/mutabletree.py

  • Committer: Vincent Ladeuil
  • Date: 2007-03-13 17:00:20 UTC
  • mfrom: (2352 +trunk)
  • mto: (2323.7.1 redirection)
  • mto: This revision was merged to the branch mainline in revision 2390.
  • Revision ID: v.ladeuil+lp@free.fr-20070313170020-d0oimozr96pwconh
Merge 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
21
21
 
22
22
 
23
23
from bzrlib import (
 
24
    errors,
24
25
    osutils,
25
26
    tree,
26
27
    )
61
62
    branch and bzrdir attributes.
62
63
    """
63
64
 
64
 
    @needs_write_lock
 
65
    @needs_tree_write_lock
65
66
    def add(self, files, ids=None, kinds=None):
66
67
        """Add paths to the set of versioned paths.
67
68
 
89
90
            if kinds is not None:
90
91
                kinds = [kinds]
91
92
 
 
93
        files = [path.strip('/') for path in files]
 
94
 
92
95
        if ids is None:
93
96
            ids = [None] * len(files)
94
97
        else:
110
113
        self._gather_kinds(files, kinds)
111
114
        self._add(files, ids, kinds)
112
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
 
113
136
    def _add(self, files, ids, kinds):
114
 
        """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
        """
115
144
        raise NotImplementedError(self._add)
116
145
 
117
146
    @needs_write_lock
118
 
    def commit(self, message=None, revprops=None, *args, **kwargs):
 
147
    def commit(self, message=None, revprops=None, *args,
 
148
               **kwargs):
119
149
        # avoid circular imports
120
150
        from bzrlib import commit
121
151
        if revprops is None: