/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: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-2010 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
32
32
    hooks,
33
33
    osutils,
34
34
    revisiontree,
35
 
    inventory,
 
35
    symbol_versioning,
36
36
    trace,
37
37
    tree,
38
38
    )
79
79
        # used on media which doesn't differentiate the case of names.
80
80
        self.case_sensitive = True
81
81
 
82
 
    def is_control_filename(self, filename):
83
 
        """True if filename is the name of a control file in this tree.
84
 
 
85
 
        :param filename: A filename within the tree. This is a relative path
86
 
        from the root of this tree.
87
 
 
88
 
        This is true IF and ONLY IF the filename is part of the meta data
89
 
        that bzr controls in this tree. I.E. a random .bzr directory placed
90
 
        on disk will not be a control file for this tree.
91
 
        """
92
 
        raise NotImplementedError(self.is_control_filename)
93
 
 
94
82
    @needs_tree_write_lock
95
83
    def add(self, files, ids=None, kinds=None):
96
84
        """Add paths to the set of versioned paths.
194
182
               **kwargs):
195
183
        # avoid circular imports
196
184
        from bzrlib import commit
 
185
        if revprops is None:
 
186
            revprops = {}
197
187
        possible_master_transports=[]
198
 
        revprops = commit.Commit.update_revprops(
199
 
                revprops,
200
 
                self.branch,
201
 
                kwargs.pop('authors', None),
202
 
                kwargs.pop('author', None),
 
188
        if not 'branch-nick' in revprops:
 
189
            revprops['branch-nick'] = self.branch._get_nick(
203
190
                kwargs.get('local', False),
204
191
                possible_master_transports)
 
192
        authors = kwargs.pop('authors', None)
 
193
        author = kwargs.pop('author', None)
 
194
        if authors is not None:
 
195
            if author is not None:
 
196
                raise AssertionError('Specifying both author and authors '
 
197
                        'is not allowed. Specify just authors instead')
 
198
            if 'author' in revprops or 'authors' in revprops:
 
199
                # XXX: maybe we should just accept one of them?
 
200
                raise AssertionError('author property given twice')
 
201
            if authors:
 
202
                for individual in authors:
 
203
                    if '\n' in individual:
 
204
                        raise AssertionError('\\n is not a valid character '
 
205
                                'in an author identity')
 
206
                revprops['authors'] = '\n'.join(authors)
 
207
        if author is not None:
 
208
            symbol_versioning.warn('The parameter author was deprecated'
 
209
                   ' in version 1.13. Use authors instead',
 
210
                   DeprecationWarning)
 
211
            if 'author' in revprops or 'authors' in revprops:
 
212
                # XXX: maybe we should just accept one of them?
 
213
                raise AssertionError('author property given twice')
 
214
            if '\n' in author:
 
215
                raise AssertionError('\\n is not a valid character '
 
216
                        'in an author identity')
 
217
            revprops['authors'] = author
205
218
        # args for wt.commit start at message from the Commit.commit method,
206
219
        args = (message, ) + args
207
220
        for hook in MutableTree.hooks['start_commit']:
387
400
        This is designed more towards DWIM for humans than API clarity.
388
401
        For the specific behaviour see the help for cmd_add().
389
402
 
390
 
        :param file_list: List of zero or more paths.  *NB: these are 
391
 
            interpreted relative to the process cwd, not relative to the 
392
 
            tree.*  (Add and most other tree methods use tree-relative
393
 
            paths.)
394
403
        :param action: A reporter to be called with the inventory, parent_ie,
395
404
            path and kind of the path being added. It may return a file_id if
396
405
            a specific one should be used.
427
436
            for c in self.conflicts():
428
437
                conflicts_related.update(c.associated_filenames())
429
438
 
430
 
        # expand any symlinks in the directory part, while leaving the
431
 
        # filename alone
432
 
        # only expanding if symlinks are supported avoids windows path bugs
433
 
        if osutils.has_symlinks():
434
 
            file_list = map(osutils.normalizepath, file_list)
435
 
 
436
439
        # validate user file paths and convert all paths to tree
437
440
        # relative : it's cheaper to make a tree relative path an abspath
438
441
        # than to convert an abspath to tree relative, and it's cheaper to
558
561
                        this_ie = None
559
562
                    else:
560
563
                        this_ie = inv[this_id]
561
 
                        # Same as in _add_one below, if the inventory doesn't
562
 
                        # think this is a directory, update the inventory
563
 
                        if this_ie.kind != 'directory':
564
 
                            this_ie = inventory.make_entry('directory',
565
 
                                this_ie.name, this_ie.parent_id, this_id)
566
 
                            del inv[this_id]
567
 
                            inv.add(this_ie)
568
564
 
569
565
                for subf in sorted(os.listdir(abspath)):
570
566
                    # here we could use TreeDirectory rather than
651
647
        """Create the default hooks.
652
648
 
653
649
        """
654
 
        hooks.Hooks.__init__(self, "bzrlib.mutabletree", "MutableTree.hooks")
655
 
        self.add_hook('start_commit',
 
650
        hooks.Hooks.__init__(self)
 
651
        self.create_hook(hooks.HookPoint('start_commit',
656
652
            "Called before a commit is performed on a tree. The start commit "
657
653
            "hook is able to change the tree before the commit takes place. "
658
654
            "start_commit is called with the bzrlib.mutabletree.MutableTree "
659
 
            "that the commit is being performed on.", (1, 4))
660
 
        self.add_hook('post_commit',
 
655
            "that the commit is being performed on.", (1, 4), None))
 
656
        self.create_hook(hooks.HookPoint('post_commit',
661
657
            "Called after a commit is performed on a tree. The hook is "
662
658
            "called with a bzrlib.mutabletree.PostCommitHookParams object. "
663
659
            "The mutable tree the commit was performed on is available via "
664
 
            "the mutable_tree attribute of that object.", (2, 0))
 
660
            "the mutable_tree attribute of that object.", (2, 0), None))
665
661
 
666
662
 
667
663
# install the default hooks into the MutableTree class.
744
740
        file_id or None to generate a new file id
745
741
    :returns: None
746
742
    """
747
 
    # if the parent exists, but isn't a directory, we have to do the
748
 
    # kind change now -- really the inventory shouldn't pretend to know
749
 
    # the kind of wt files, but it does.
750
 
    if parent_ie.kind != 'directory':
751
 
        # nb: this relies on someone else checking that the path we're using
752
 
        # doesn't contain symlinks.
753
 
        new_parent_ie = inventory.make_entry('directory', parent_ie.name,
754
 
            parent_ie.parent_id, parent_ie.file_id)
755
 
        del inv[parent_ie.file_id]
756
 
        inv.add(new_parent_ie)
757
 
        parent_ie = new_parent_ie
758
743
    file_id = file_id_callback(inv, parent_ie, path, kind)
759
744
    entry = inv.make_entry(kind, path.base_path, parent_ie.file_id,
760
745
        file_id=file_id)