~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/mutabletree.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-10-25 08:29:08 UTC
  • mfrom: (2940.1.2 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20071025082908-abn3kunrb2ivdvth
renaming of experimental pack formats to include knitpack in their name (Ian Clatworthy)

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,
31
30
    )
32
31
from bzrlib.osutils import dirname
33
32
from bzrlib.revisiontree import RevisionTree
96
95
        TODO: Perhaps callback with the ids and paths as they're added.
97
96
        """
98
97
        if isinstance(files, 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()
 
98
            assert(ids is None or isinstance(ids, basestring))
 
99
            assert(kinds is None or isinstance(kinds, basestring))
105
100
            files = [files]
106
101
            if ids is not None:
107
102
                ids = [ids]
113
108
        if ids is None:
114
109
            ids = [None] * len(files)
115
110
        else:
116
 
            if not (len(ids) == len(files)):
117
 
                raise AssertionError()
 
111
            assert(len(ids) == len(files))
118
112
        if kinds is None:
119
113
            kinds = [None] * len(files)
120
 
        elif not len(kinds) == len(files):
121
 
            raise AssertionError()
 
114
        else:
 
115
            assert(len(kinds) == len(files))
122
116
        for f in files:
123
117
            # generic constraint checks:
124
118
            if self.is_control_filename(f):
185
179
            revprops['branch-nick'] = self.branch.nick
186
180
        author = kwargs.pop('author', None)
187
181
        if author is not None:
188
 
            if 'author' in revprops:
189
 
                # XXX: maybe we should just accept one of them?
190
 
                raise AssertionError('author property given twice')
 
182
            assert 'author' not in revprops
191
183
            revprops['author'] = author
192
184
        # args for wt.commit start at message from the Commit.commit method,
193
185
        args = (message, ) + args
194
 
        for hook in MutableTree.hooks['start_commit']:
195
 
            hook(self)
196
186
        committed_id = commit.Commit().commit(working_tree=self,
197
187
            revprops=revprops, *args, **kwargs)
198
188
        return committed_id
247
237
        """
248
238
        raise NotImplementedError(self.mkdir)
249
239
 
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
 
 
263
240
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
264
241
        """Set the parents ids of the working tree.
265
242
 
296
273
        # not in an inner loop; and we want to remove direct use of this,
297
274
        # so here as a reminder for now. RBC 20070703
298
275
        from bzrlib.inventory import InventoryEntry
 
276
        assert isinstance(recurse, bool)
299
277
        if action is None:
300
278
            action = add.AddAction()
301
279
        
459
437
        inventory for the parent new_revid, and all other parent trees are
460
438
        discarded.
461
439
 
462
 
        All the changes in the delta should be changes synchronising the basis
463
 
        tree with some or all of the working tree, with a change to a directory
464
 
        requiring that its contents have been recursively included. That is,
465
 
        this is not a general purpose tree modification routine, but a helper
466
 
        for commit which is not required to handle situations that do not arise
467
 
        outside of commit.
468
 
 
469
440
        :param new_revid: The new revision id for the trees parent.
470
441
        :param delta: An inventory delta (see apply_inventory_delta) describing
471
442
            the changes from the current left most parent revision to new_revid.
488
459
        self.set_parent_trees([(new_revid, rev_tree)])
489
460
 
490
461
 
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
 
 
509
462
class _FastPath(object):
510
463
    """A path object with fast accessors for things like basename."""
511
464