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