/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: Martin Pool
  • Date: 2008-05-27 03:00:53 UTC
  • mfrom: (3452 +trunk)
  • mto: (3724.1.1 lock-hooks)
  • mto: This revision was merged to the branch mainline in revision 3730.
  • Revision ID: mbp@sourcefrog.net-20080527030053-0mct6dypek0ysjc3
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from bzrlib import (
28
28
    add,
29
29
    bzrdir,
 
30
    hooks,
30
31
    )
31
32
from bzrlib.osutils import dirname
32
33
from bzrlib.revisiontree import RevisionTree
95
96
        TODO: Perhaps callback with the ids and paths as they're added.
96
97
        """
97
98
        if isinstance(files, basestring):
98
 
            assert(ids is None or isinstance(ids, basestring))
99
 
            assert(kinds is None or isinstance(kinds, basestring))
 
99
            # XXX: Passing a single string is inconsistent and should be
 
100
            # deprecated.
 
101
            if not (ids is None or isinstance(ids, basestring)):
 
102
                raise AssertionError()
 
103
            if not (kinds is None or isinstance(kinds, basestring)):
 
104
                raise AssertionError()
100
105
            files = [files]
101
106
            if ids is not None:
102
107
                ids = [ids]
108
113
        if ids is None:
109
114
            ids = [None] * len(files)
110
115
        else:
111
 
            assert(len(ids) == len(files))
 
116
            if not (len(ids) == len(files)):
 
117
                raise AssertionError()
112
118
        if kinds is None:
113
119
            kinds = [None] * len(files)
114
 
        else:
115
 
            assert(len(kinds) == len(files))
 
120
        elif not len(kinds) == len(files):
 
121
            raise AssertionError()
116
122
        for f in files:
117
123
            # generic constraint checks:
118
124
            if self.is_control_filename(f):
179
185
            revprops['branch-nick'] = self.branch.nick
180
186
        author = kwargs.pop('author', None)
181
187
        if author is not None:
182
 
            assert 'author' not in revprops
 
188
            if 'author' in revprops:
 
189
                # XXX: maybe we should just accept one of them?
 
190
                raise AssertionError('author property given twice')
183
191
            revprops['author'] = author
184
192
        # args for wt.commit start at message from the Commit.commit method,
185
193
        args = (message, ) + args
 
194
        for hook in MutableTree.hooks['start_commit']:
 
195
            hook(self)
186
196
        committed_id = commit.Commit().commit(working_tree=self,
187
197
            revprops=revprops, *args, **kwargs)
188
198
        return committed_id
237
247
        """
238
248
        raise NotImplementedError(self.mkdir)
239
249
 
 
250
    @needs_write_lock
 
251
    def put_file_bytes_non_atomic(self, file_id, bytes):
 
252
        """Update the content of a file in the tree.
 
253
        
 
254
        Note that the file is written in-place rather than being
 
255
        written to a temporary location and renamed. As a consequence,
 
256
        readers can potentially see the file half-written.
 
257
 
 
258
        :param file_id: file-id of the file
 
259
        :param bytes: the new file contents
 
260
        """
 
261
        raise NotImplementedError(self.put_file_bytes_non_atomic)
 
262
 
240
263
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
241
264
        """Set the parents ids of the working tree.
242
265
 
273
296
        # not in an inner loop; and we want to remove direct use of this,
274
297
        # so here as a reminder for now. RBC 20070703
275
298
        from bzrlib.inventory import InventoryEntry
276
 
        assert isinstance(recurse, bool)
277
299
        if action is None:
278
300
            action = add.AddAction()
279
301
        
466
488
        self.set_parent_trees([(new_revid, rev_tree)])
467
489
 
468
490
 
 
491
class MutableTreeHooks(hooks.Hooks):
 
492
    """A dictionary mapping a hook name to a list of callables for mutabletree 
 
493
    hooks.
 
494
    """
 
495
 
 
496
    def __init__(self):
 
497
        """Create the default hooks.
 
498
 
 
499
        """
 
500
        hooks.Hooks.__init__(self)
 
501
        # Invoked before a commit is done in a tree. New in 1.4
 
502
        self['start_commit'] = []
 
503
 
 
504
 
 
505
# install the default hooks into the MutableTree class.
 
506
MutableTree.hooks = MutableTreeHooks()
 
507
 
 
508
 
469
509
class _FastPath(object):
470
510
    """A path object with fast accessors for things like basename."""
471
511