/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.7 by John Arbash Meinel
Merge in the bzr.dev 5582
1
# Copyright (C) 2006-2011 Canonical Ltd
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
16
17
"""MutableTree object.
18
19
See MutableTree for more details.
20
"""
21
6379.6.7 by Jelmer Vernooij
Move importing from future until after doc string, otherwise the doc string will disappear.
22
from __future__ import absolute_import
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
23
6672.2.4 by Jelmer Vernooij
Fix imports.
24
from . import (
4721.3.1 by Vincent Ladeuil
Cleanup imports.
25
    errors,
3335.1.2 by Jelmer Vernooij
Add mutabletree hooks class and start_commit hook.
26
    hooks,
4721.3.1 by Vincent Ladeuil
Cleanup imports.
27
    osutils,
28
    trace,
29
    tree,
2568.2.6 by Robert Collins
Review feedback.
30
    )
6670.4.1 by Jelmer Vernooij
Update imports.
31
6656.1.1 by Martin
Apply 2to3 dict fixer and clean up resulting mess using view helpers
32
from .sixish import (
6695.3.1 by Martin
Remove remaining uses of basestring from the codebase
33
    text_type,
6656.1.1 by Martin
Apply 2to3 dict fixer and clean up resulting mess using view helpers
34
    )
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
35
36
6842.1.1 by Jelmer Vernooij
Move add_reference implementation to bzr-specific workingtree.
37
class BadReferenceTarget(errors.InternalBzrError):
38
39
    _fmt = "Can't add reference to %(other_tree)s into %(tree)s." \
40
           "%(reason)s"
41
42
    def __init__(self, tree, other_tree, reason):
43
        self.tree = tree
44
        self.other_tree = other_tree
45
        self.reason = reason
46
47
5777.4.1 by Jelmer Vernooij
Split inventory-specific code out of MutableTree into MutableInventoryTree.
48
class MutableTree(tree.Tree):
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
49
    """A MutableTree is a specialisation of Tree which is able to be mutated.
50
51
    Generally speaking these mutations are only possible within a lock_write
52
    context, and will revert if the lock is broken abnormally - but this cannot
53
    be guaranteed - depending on the exact implementation of the mutable state.
54
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
55
    The most common form of Mutable Tree is WorkingTree, see breezy.workingtree.
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
56
    For tests we also have MemoryTree which is a MutableTree whose contents are
57
    entirely in memory.
58
59
    For now, we are not treating MutableTree as an interface to provide
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
60
    conformance tests for - rather we are testing MemoryTree specifically, and
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
61
    interface testing implementations of WorkingTree.
62
6207.3.3 by jelmer at samba
Fix tests and the like.
63
    A mutable tree always has an associated Branch and ControlDir object - the
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
64
    branch and bzrdir attributes.
65
    """
3794.5.19 by Mark Hammond
MutableTree gets case_sensitive attribute and smart_add takes advantage of it to enforce sane CICP-filesystem semantics
66
    def __init__(self, *args, **kw):
67
        super(MutableTree, self).__init__(*args, **kw)
68
        # Is this tree on a case-insensitive or case-preserving file-system?
69
        # Sub-classes may initialize to False if they detect they are being
70
        # used on media which doesn't differentiate the case of names.
71
        self.case_sensitive = True
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
72
5699.2.1 by Jelmer Vernooij
Move is_control_filename() from Tree to MutableTree.
73
    def is_control_filename(self, filename):
74
        """True if filename is the name of a control file in this tree.
75
76
        :param filename: A filename within the tree. This is a relative path
5891.1.2 by Andrew Bennetts
Fix a bunch of docstring formatting nits, making pydoctor a bit happier.
77
            from the root of this tree.
5699.2.1 by Jelmer Vernooij
Move is_control_filename() from Tree to MutableTree.
78
79
        This is true IF and ONLY IF the filename is part of the meta data
80
        that bzr controls in this tree. I.E. a random .bzr directory placed
81
        on disk will not be a control file for this tree.
82
        """
83
        raise NotImplementedError(self.is_control_filename)
84
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
85
    def add(self, files, ids=None, kinds=None):
86
        """Add paths to the set of versioned paths.
87
88
        Note that the command line normally calls smart_add instead,
89
        which can automatically recurse.
90
7141.3.2 by Jelmer Vernooij
add some tests.
91
        This adds the files to the tree, so that they will be
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
92
        recorded by the next commit.
93
94
        :param files: List of paths to add, relative to the base of the tree.
95
        :param ids: If set, use these instead of automatically generated ids.
96
            Must be the same length as the list of files, but may
97
            contain None for ids that are to be autogenerated.
98
        :param kinds: Optional parameter to specify the kinds to be used for
99
            each file.
100
101
        TODO: Perhaps callback with the ids and paths as they're added.
102
        """
6695.3.1 by Martin
Remove remaining uses of basestring from the codebase
103
        if isinstance(files, (str, text_type)):
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
104
            # XXX: Passing a single string is inconsistent and should be
105
            # deprecated.
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
106
            if not (ids is None or isinstance(ids, bytes)):
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
107
                raise AssertionError()
6695.3.1 by Martin
Remove remaining uses of basestring from the codebase
108
            if not (kinds is None or isinstance(kinds, (str, text_type))):
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
109
                raise AssertionError()
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
110
            files = [files]
111
            if ids is not None:
112
                ids = [ids]
113
            if kinds is not None:
114
                kinds = [kinds]
115
2323.4.2 by Robert Collins
Fix the behaviour of dirstate optimised iter_changes recursing its disk iterator into subtrees inappropriately.
116
        files = [path.strip('/') for path in files]
117
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
118
        if ids is None:
119
            ids = [None] * len(files)
120
        else:
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
121
            if not (len(ids) == len(files)):
122
                raise AssertionError()
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
123
        if kinds is None:
124
            kinds = [None] * len(files)
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
125
        elif not len(kinds) == len(files):
126
            raise AssertionError()
6754.8.18 by Jelmer Vernooij
Get rid of lock_tree_write.
127
        with self.lock_tree_write():
128
            for f in files:
129
                # generic constraint checks:
130
                if self.is_control_filename(f):
131
                    raise errors.ForbiddenControlFileError(filename=f)
132
                fp = osutils.splitpath(f)
133
            # fill out file kinds for all files [not needed when we stop
134
            # caring about the instantaneous file kind within a uncommmitted tree
135
            #
136
            self._gather_kinds(files, kinds)
137
            self._add(files, ids, kinds)
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
138
2255.6.8 by Aaron Bentley
Merge refactoring of add_reference
139
    def add_reference(self, sub_tree):
6842.1.1 by Jelmer Vernooij
Move add_reference implementation to bzr-specific workingtree.
140
        """Add a TreeReference to the tree, pointing at sub_tree.
141
142
        :param sub_tree: subtree to add.
143
        """
2255.6.8 by Aaron Bentley
Merge refactoring of add_reference
144
        raise errors.UnsupportedOperation(self.add_reference, self)
145
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
146
    def _add(self, files, ids, kinds):
2255.6.8 by Aaron Bentley
Merge refactoring of add_reference
147
        """Helper function for add - updates the inventory.
148
149
        :param files: sequence of pathnames, relative to the tree root
150
        :param ids: sequence of suggested ids for the files (may be None)
151
        :param kinds: sequence of  inventory kinds of the files (i.e. may
152
            contain "tree-reference")
153
        """
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
154
        raise NotImplementedError(self._add)
155
6630.1.1 by Jelmer Vernooij
Remove deprecated functionality.
156
    def commit(self, message=None, revprops=None, *args, **kwargs):
1986.1.3 by Robert Collins
Merge bzr.dev.
157
        # avoid circular imports
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
158
        from breezy import commit
3565.6.9 by Marius Kruger
Jump through hoops not to open multiple connections when committing to a bound branch.
159
        possible_master_transports=[]
6754.8.17 by Jelmer Vernooij
Remove uses of needs_write_lock.
160
        with self.lock_write():
161
            revprops = commit.Commit.update_revprops(
162
                    revprops,
163
                    self.branch,
164
                    kwargs.pop('authors', None),
165
                    kwargs.get('local', False),
166
                    possible_master_transports)
167
            # args for wt.commit start at message from the Commit.commit method,
168
            args = (message, ) + args
169
            for hook in MutableTree.hooks['start_commit']:
170
                hook(self)
171
            committed_id = commit.Commit().commit(working_tree=self,
172
                revprops=revprops,
173
                possible_master_transports=possible_master_transports,
174
                *args, **kwargs)
175
            post_hook_params = PostCommitHookParams(self)
176
            for hook in MutableTree.hooks['post_commit']:
177
                hook(post_hook_params)
178
            return committed_id
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
179
180
    def _gather_kinds(self, files, kinds):
181
        """Helper function for add - sets the entries of kinds."""
182
        raise NotImplementedError(self._gather_kinds)
183
4721.3.2 by Vincent Ladeuil
Simplify mutable_tree.has_changes() and update call sites.
184
    def has_changes(self, _from_tree=None):
185
        """Quickly check that the tree contains at least one commitable change.
186
187
        :param _from_tree: tree to compare against to find changes (default to
188
            the basis tree and is intended to be used by tests).
4503.1.3 by Vincent Ladeuil
Take review comments into account.
189
190
        :return: True if a change is found. False otherwise
191
        """
6754.8.16 by Jelmer Vernooij
Get rid of all uses of needs_read_lock
192
        with self.lock_read():
193
            # Check pending merges
194
            if len(self.get_parent_ids()) > 1:
195
                return True
196
            if _from_tree is None:
197
                _from_tree = self.basis_tree()
198
            changes = self.iter_changes(_from_tree)
199
            try:
6634.2.1 by Martin
Apply 2to3 next fixer and make compatible
200
                change = next(changes)
6754.8.16 by Jelmer Vernooij
Get rid of all uses of needs_read_lock
201
                # Exclude root (talk about black magic... --vila 20090629)
202
                if change[4] == (None, None):
203
                    change = next(changes)
204
                return True
205
            except StopIteration:
206
                # No changes
207
                return False
4503.1.3 by Vincent Ladeuil
Take review comments into account.
208
5171.2.2 by Vincent Ladeuil
Explain that the uncommitted changes are not processed when
209
    def check_changed_or_out_of_date(self, strict, opt_name,
210
                                     more_error, more_warning):
5147.2.2 by Vincent Ladeuil
Fix bug #519319 by defaulting to a warning for dirty trees.
211
        """Check the tree for uncommitted changes and branch synchronization.
212
213
        If strict is None and not set in the config files, a warning is issued.
214
        If strict is True, an error is raised.
215
        If strict is False, no checks are done and no warning is issued.
216
217
        :param strict: True, False or None, searched in branch config if None.
218
219
        :param opt_name: strict option name to search in config file.
220
5171.2.2 by Vincent Ladeuil
Explain that the uncommitted changes are not processed when
221
        :param more_error: Details about how to avoid the check.
222
223
        :param more_warning: Details about what is happening.
5147.2.2 by Vincent Ladeuil
Fix bug #519319 by defaulting to a warning for dirty trees.
224
        """
6754.8.16 by Jelmer Vernooij
Get rid of all uses of needs_read_lock
225
        with self.lock_read():
226
            if strict is None:
227
                strict = self.branch.get_config_stack().get(opt_name)
228
            if strict is not False:
229
                err_class = None
230
                if (self.has_changes()):
231
                    err_class = errors.UncommittedChanges
232
                elif self.last_revision() != self.branch.last_revision():
233
                    # The tree has lost sync with its branch, there is little
234
                    # chance that the user is aware of it but he can still
235
                    # force the action with --no-strict
236
                    err_class = errors.OutOfDateTree
237
                if err_class is not None:
238
                    if strict is None:
239
                        err = err_class(self, more=more_warning)
240
                        # We don't want to interrupt the user if he expressed
241
                        # no preference about strict.
242
                        trace.warning('%s', err._format())
243
                    else:
244
                        err = err_class(self, more=more_error)
245
                        raise err
5147.2.2 by Vincent Ladeuil
Fix bug #519319 by defaulting to a warning for dirty trees.
246
1986.1.6 by Robert Collins
Add MemoryTree.last_revision.
247
    def last_revision(self):
1986.1.7 by Robert Collins
Merge bzr.dev.
248
        """Return the revision id of the last commit performed in this tree.
249
250
        In early tree formats the result of last_revision is the same as the
251
        branch last_revision, but that is no longer the case for modern tree
252
        formats.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
253
1986.1.7 by Robert Collins
Merge bzr.dev.
254
        last_revision returns the left most parent id, or None if there are no
255
        parents.
256
257
        last_revision was deprecated as of 0.11. Please use get_parent_ids
258
        instead.
259
        """
1986.1.6 by Robert Collins
Add MemoryTree.last_revision.
260
        raise NotImplementedError(self.last_revision)
261
1986.1.8 by Robert Collins
Update to bzr.dev, which involves adding lock_tree_write to MutableTree and MemoryTree.
262
    def lock_tree_write(self):
263
        """Lock the working tree for write, and the branch for read.
264
265
        This is useful for operations which only need to mutate the working
266
        tree. Taking out branch write locks is a relatively expensive process
267
        and may fail if the branch is on read only media. So branch write locks
268
        should only be taken out when we are modifying branch data - such as in
269
        operations like commit, pull, uncommit and update.
270
        """
271
        raise NotImplementedError(self.lock_tree_write)
272
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
273
    def lock_write(self):
274
        """Lock the tree and its branch. This allows mutating calls to be made.
275
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
276
        Some mutating methods will take out implicit write locks, but in
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
277
        general you should always obtain a write lock before calling mutating
278
        methods on a tree.
279
        """
280
        raise NotImplementedError(self.lock_write)
281
282
    def mkdir(self, path, file_id=None):
283
        """Create a directory in the tree. if file_id is None, one is assigned.
284
285
        :param path: A unicode file path.
286
        :param file_id: An optional file-id.
287
        :return: the file id of the new directory.
288
        """
289
        raise NotImplementedError(self.mkdir)
290
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
291
    def _observed_sha1(self, path, sha_and_stat):
3709.3.1 by Robert Collins
First cut - make it work - at updating the tree stat cache during commit.
292
        """Tell the tree we have observed a paths sha1.
293
294
        The intent of this function is to allow trees that have a hashcache to
3709.3.2 by Robert Collins
Race-free stat-fingerprint updating during commit via a new method get_file_with_stat.
295
        update the hashcache during commit. If the observed file is too new
296
        (based on the stat_value) to be safely hash-cached the tree will ignore
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
297
        it.
3709.3.1 by Robert Collins
First cut - make it work - at updating the tree stat cache during commit.
298
299
        The default implementation does nothing.
300
301
        :param path: The file path
6621.20.1 by Martin
Run 2to3 tuple_params fixer and tidy up.
302
        :param sha_and_stat: The sha 1 and stat result observed.
3709.3.1 by Robert Collins
First cut - make it work - at updating the tree stat cache during commit.
303
        :return: None
304
        """
305
6809.4.8 by Jelmer Vernooij
Fix some test failures.
306
    def put_file_bytes_non_atomic(self, path, bytes, file_id=None):
3394.2.1 by Ian Clatworthy
add docstring for put_file_bytes_non_atomic
307
        """Update the content of a file in the tree.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
308
3394.2.1 by Ian Clatworthy
add docstring for put_file_bytes_non_atomic
309
        Note that the file is written in-place rather than being
310
        written to a temporary location and renamed. As a consequence,
311
        readers can potentially see the file half-written.
312
313
        :param file_id: file-id of the file
314
        :param bytes: the new file contents
315
        """
316
        raise NotImplementedError(self.put_file_bytes_non_atomic)
317
2418.5.1 by John Arbash Meinel
Make a Branch helper which can create a very basic MemoryTree with history.
318
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
319
        """Set the parents ids of the working tree.
320
321
        :param revision_ids: A list of revision_ids.
322
        """
323
        raise NotImplementedError(self.set_parent_ids)
324
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
325
    def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
326
        """Set the parents of the working tree.
327
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
328
        :param parents_list: A list of (revision_id, tree) tuples.
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
329
            If tree is None, then that element is treated as an unreachable
330
            parent tree - i.e. a ghost.
331
        """
332
        raise NotImplementedError(self.set_parent_trees)
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
333
5777.4.1 by Jelmer Vernooij
Split inventory-specific code out of MutableTree into MutableInventoryTree.
334
    def smart_add(self, file_list, recurse=True, action=None, save=True):
335
        """Version file_list, optionally recursing into directories.
336
337
        This is designed more towards DWIM for humans than API clarity.
338
        For the specific behaviour see the help for cmd_add().
339
340
        :param file_list: List of zero or more paths.  *NB: these are 
341
            interpreted relative to the process cwd, not relative to the 
342
            tree.*  (Add and most other tree methods use tree-relative
343
            paths.)
7141.3.2 by Jelmer Vernooij
add some tests.
344
        :param action: A reporter to be called with the working tree, parent_ie,
5777.4.1 by Jelmer Vernooij
Split inventory-specific code out of MutableTree into MutableInventoryTree.
345
            path and kind of the path being added. It may return a file_id if
346
            a specific one should be used.
7141.3.2 by Jelmer Vernooij
add some tests.
347
        :param save: Save the changes after completing the adds. If False
5777.4.1 by Jelmer Vernooij
Split inventory-specific code out of MutableTree into MutableInventoryTree.
348
            this provides dry-run functionality by doing the add and not saving
7141.3.2 by Jelmer Vernooij
add some tests.
349
            the changes.
5777.4.1 by Jelmer Vernooij
Split inventory-specific code out of MutableTree into MutableInventoryTree.
350
        :return: A tuple - files_added, ignored_files. files_added is the count
351
            of added files, and ignored_files is a dict mapping files that were
352
            ignored to the rule that caused them to be ignored.
353
        """
354
        raise NotImplementedError(self.smart_add)
355
6853 by Jelmer Vernooij
Add MutableTree.copy_one.
356
    def rename_one(self, from_rel, to_rel, after=False):
357
        """Rename one file.
358
359
        This can change the directory or the filename or both.
360
361
        rename_one has several 'modes' to work. First, it can rename a physical
362
        file and change the file_id. That is the normal mode. Second, it can
363
        only change the file_id without touching any physical file.
364
365
        rename_one uses the second mode if 'after == True' and 'to_rel' is
366
        either not versioned or newly added, and present in the working tree.
367
368
        rename_one uses the second mode if 'after == False' and 'from_rel' is
369
        versioned but no longer in the working tree, and 'to_rel' is not
370
        versioned but present in the working tree.
371
372
        rename_one uses the first mode if 'after == False' and 'from_rel' is
373
        versioned and present in the working tree, and 'to_rel' is not
374
        versioned and not present in the working tree.
375
376
        Everything else results in an error.
377
        """
378
        raise NotImplementedError(self.rename_one)
379
380
    def copy_one(self, from_rel, to_rel):
381
        """Copy one file or directory.
382
383
        This can change the directory or the filename or both.
384
385
        """
386
        raise NotImplementedError(self.copy_one)
387
5870.1.42 by Jelmer Vernooij
Review feedback from John.
388
5870.1.31 by Jelmer Vernooij
Move smart_add into a helper.
389
class MutableTreeHooks(hooks.Hooks):
390
    """A dictionary mapping a hook name to a list of callables for mutabletree
391
    hooks.
392
    """
393
394
    def __init__(self):
395
        """Create the default hooks.
396
397
        """
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
398
        hooks.Hooks.__init__(self, "breezy.mutabletree", "MutableTree.hooks")
5870.1.31 by Jelmer Vernooij
Move smart_add into a helper.
399
        self.add_hook('start_commit',
400
            "Called before a commit is performed on a tree. The start commit "
401
            "hook is able to change the tree before the commit takes place. "
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
402
            "start_commit is called with the breezy.mutabletree.MutableTree "
5870.1.31 by Jelmer Vernooij
Move smart_add into a helper.
403
            "that the commit is being performed on.", (1, 4))
404
        self.add_hook('post_commit',
405
            "Called after a commit is performed on a tree. The hook is "
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
406
            "called with a breezy.mutabletree.PostCommitHookParams object. "
5870.1.31 by Jelmer Vernooij
Move smart_add into a helper.
407
            "The mutable tree the commit was performed on is available via "
408
            "the mutable_tree attribute of that object.", (2, 0))
6434.2.1 by Jelmer Vernooij
Add pre_transform/post_transform hooks.
409
        self.add_hook('pre_transform',
410
            "Called before a tree transform on this tree. The hook is called "
6434.2.2 by Jelmer Vernooij
Add hooks for tree transforms.
411
            "with the tree that is being transformed and the transform.",
412
            (2, 5))
6435.1.1 by Jelmer Vernooij
Add post_build_tree hook.
413
        self.add_hook('post_build_tree',
414
            "Called after a completely new tree is built. The hook is "
415
            "called with the tree as its only argument.", (2, 5))
6434.2.1 by Jelmer Vernooij
Add pre_transform/post_transform hooks.
416
        self.add_hook('post_transform',
417
            "Called after a tree transform has been performed on a tree. "
6434.2.2 by Jelmer Vernooij
Add hooks for tree transforms.
418
            "The hook is called with the tree that is being transformed and "
419
            "the transform.",
6434.2.1 by Jelmer Vernooij
Add pre_transform/post_transform hooks.
420
            (2, 5))
5870.1.31 by Jelmer Vernooij
Move smart_add into a helper.
421
422
# install the default hooks into the MutableTree class.
423
MutableTree.hooks = MutableTreeHooks()
424
425
426
class PostCommitHookParams(object):
427
    """Parameters for the post_commit hook.
428
429
    To access the parameters, use the following attributes:
430
431
    * mutable_tree - the MutableTree object
432
    """
433
434
    def __init__(self, mutable_tree):
435
        """Create the parameters for the post_commit hook."""
436
        self.mutable_tree = mutable_tree