64
63
A mutable tree always has an associated Branch and ControlDir object - the
65
64
branch and bzrdir attributes.
67
67
def __init__(self, *args, **kw):
68
68
super(MutableTree, self).__init__(*args, **kw)
69
69
# Is this tree on a case-insensitive or case-preserving file-system?
89
89
Note that the command line normally calls smart_add instead,
90
90
which can automatically recurse.
92
This adds the files to the inventory, so that they will be
92
This adds the files to the tree, so that they will be
93
93
recorded by the next commit.
95
95
:param files: List of paths to add, relative to the base of the tree.
157
157
def commit(self, message=None, revprops=None, *args, **kwargs):
158
158
# avoid circular imports
159
159
from breezy import commit
160
possible_master_transports=[]
160
possible_master_transports = []
161
161
with self.lock_write():
162
162
revprops = commit.Commit.update_revprops(
165
kwargs.pop('authors', None),
166
kwargs.get('local', False),
167
possible_master_transports)
165
kwargs.pop('authors', None),
166
kwargs.get('local', False),
167
possible_master_transports)
168
168
# args for wt.commit start at message from the Commit.commit method,
169
169
args = (message, ) + args
170
170
for hook in MutableTree.hooks['start_commit']:
172
172
committed_id = commit.Commit().commit(working_tree=self,
174
possible_master_transports=possible_master_transports,
174
possible_master_transports=possible_master_transports,
176
176
post_hook_params = PostCommitHookParams(self)
177
177
for hook in MutableTree.hooks['post_commit']:
178
178
hook(post_hook_params)
290
290
raise NotImplementedError(self.mkdir)
292
def _observed_sha1(self, file_id, path, sha_and_stat):
292
def _observed_sha1(self, path, sha_and_stat):
293
293
"""Tell the tree we have observed a paths sha1.
295
295
The intent of this function is to allow trees that have a hashcache to
300
300
The default implementation does nothing.
302
:param file_id: The file id
303
302
:param path: The file path
304
303
:param sha_and_stat: The sha 1 and stat result observed.
308
def put_file_bytes_non_atomic(self, path, bytes, file_id=None):
307
def put_file_bytes_non_atomic(self, path, bytes):
309
308
"""Update the content of a file in the tree.
311
310
Note that the file is written in-place rather than being
339
338
This is designed more towards DWIM for humans than API clarity.
340
339
For the specific behaviour see the help for cmd_add().
342
:param file_list: List of zero or more paths. *NB: these are
343
interpreted relative to the process cwd, not relative to the
341
:param file_list: List of zero or more paths. *NB: these are
342
interpreted relative to the process cwd, not relative to the
344
343
tree.* (Add and most other tree methods use tree-relative
346
:param action: A reporter to be called with the inventory, parent_ie,
345
:param action: A reporter to be called with the working tree, parent_ie,
347
346
path and kind of the path being added. It may return a file_id if
348
347
a specific one should be used.
349
:param save: Save the inventory after completing the adds. If False
348
:param save: Save the changes after completing the adds. If False
350
349
this provides dry-run functionality by doing the add and not saving
352
351
:return: A tuple - files_added, ignored_files. files_added is the count
353
352
of added files, and ignored_files is a dict mapping files that were
354
353
ignored to the rule that caused them to be ignored.
400
399
hooks.Hooks.__init__(self, "breezy.mutabletree", "MutableTree.hooks")
401
400
self.add_hook('start_commit',
402
"Called before a commit is performed on a tree. The start commit "
403
"hook is able to change the tree before the commit takes place. "
404
"start_commit is called with the breezy.mutabletree.MutableTree "
405
"that the commit is being performed on.", (1, 4))
401
"Called before a commit is performed on a tree. The start commit "
402
"hook is able to change the tree before the commit takes place. "
403
"start_commit is called with the breezy.mutabletree.MutableTree "
404
"that the commit is being performed on.", (1, 4))
406
405
self.add_hook('post_commit',
407
"Called after a commit is performed on a tree. The hook is "
408
"called with a breezy.mutabletree.PostCommitHookParams object. "
409
"The mutable tree the commit was performed on is available via "
410
"the mutable_tree attribute of that object.", (2, 0))
406
"Called after a commit is performed on a tree. The hook is "
407
"called with a breezy.mutabletree.PostCommitHookParams object. "
408
"The mutable tree the commit was performed on is available via "
409
"the mutable_tree attribute of that object.", (2, 0))
411
410
self.add_hook('pre_transform',
412
"Called before a tree transform on this tree. The hook is called "
413
"with the tree that is being transformed and the transform.",
411
"Called before a tree transform on this tree. The hook is called "
412
"with the tree that is being transformed and the transform.",
415
414
self.add_hook('post_build_tree',
416
"Called after a completely new tree is built. The hook is "
417
"called with the tree as its only argument.", (2, 5))
415
"Called after a completely new tree is built. The hook is "
416
"called with the tree as its only argument.", (2, 5))
418
417
self.add_hook('post_transform',
419
"Called after a tree transform has been performed on a tree. "
420
"The hook is called with the tree that is being transformed and "
418
"Called after a tree transform has been performed on a tree. "
419
"The hook is called with the tree that is being transformed and "
424
424
# install the default hooks into the MutableTree class.
425
425
MutableTree.hooks = MutableTreeHooks()