/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 breezy/mutabletree.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
from .sixish import (
33
33
    text_type,
 
34
    viewvalues,
34
35
    )
35
36
 
36
37
 
63
64
    A mutable tree always has an associated Branch and ControlDir object - the
64
65
    branch and bzrdir attributes.
65
66
    """
66
 
 
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.
91
91
 
92
 
        This adds the files to the tree, so that they will be
 
92
        This adds the files to the inventory, so that they will be
93
93
        recorded by the next commit.
94
94
 
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(
163
 
                revprops,
164
 
                self.branch,
165
 
                kwargs.pop('authors', None),
166
 
                kwargs.get('local', False),
167
 
                possible_master_transports)
 
163
                    revprops,
 
164
                    self.branch,
 
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']:
171
171
                hook(self)
172
172
            committed_id = commit.Commit().commit(working_tree=self,
173
 
                                                  revprops=revprops,
174
 
                                                  possible_master_transports=possible_master_transports,
175
 
                                                  *args, **kwargs)
 
173
                revprops=revprops,
 
174
                possible_master_transports=possible_master_transports,
 
175
                *args, **kwargs)
176
176
            post_hook_params = PostCommitHookParams(self)
177
177
            for hook in MutableTree.hooks['post_commit']:
178
178
                hook(post_hook_params)
197
197
            if _from_tree is None:
198
198
                _from_tree = self.basis_tree()
199
199
            changes = self.iter_changes(_from_tree)
200
 
            if self.supports_symlinks():
201
 
                # Fast path for has_changes.
202
 
                try:
 
200
            try:
 
201
                change = next(changes)
 
202
                # Exclude root (talk about black magic... --vila 20090629)
 
203
                if change[4] == (None, None):
203
204
                    change = next(changes)
204
 
                    # Exclude root (talk about black magic... --vila 20090629)
205
 
                    if change.parent_id == (None, None):
206
 
                        change = next(changes)
207
 
                    return True
208
 
                except StopIteration:
209
 
                    # No changes
210
 
                    return False
211
 
            else:
212
 
                # Slow path for has_changes.
213
 
                # Handle platforms that do not support symlinks in the
214
 
                # conditional below. This is slower than the try/except
215
 
                # approach below that but we don't have a choice as we
216
 
                # need to be sure that all symlinks are removed from the
217
 
                # entire changeset. This is because in platforms that
218
 
                # do not support symlinks, they show up as None in the
219
 
                # working copy as compared to the repository.
220
 
                # Also, exclude root as mention in the above fast path.
221
 
                changes = filter(
222
 
                    lambda c: c[6][0] != 'symlink' and c[4] != (None, None),
223
 
                    changes)
224
 
                try:
225
 
                    next(iter(changes))
226
 
                except StopIteration:
227
 
                    return False
228
205
                return True
 
206
            except StopIteration:
 
207
                # No changes
 
208
                return False
229
209
 
230
210
    def check_changed_or_out_of_date(self, strict, opt_name,
231
211
                                     more_error, more_warning):
309
289
        """
310
290
        raise NotImplementedError(self.mkdir)
311
291
 
312
 
    def _observed_sha1(self, path, sha_and_stat):
 
292
    def _observed_sha1(self, file_id, path, sha_and_stat):
313
293
        """Tell the tree we have observed a paths sha1.
314
294
 
315
295
        The intent of this function is to allow trees that have a hashcache to
319
299
 
320
300
        The default implementation does nothing.
321
301
 
 
302
        :param file_id: The file id
322
303
        :param path: The file path
323
304
        :param sha_and_stat: The sha 1 and stat result observed.
324
305
        :return: None
325
306
        """
326
307
 
327
 
    def put_file_bytes_non_atomic(self, path, bytes):
 
308
    def put_file_bytes_non_atomic(self, path, bytes, file_id=None):
328
309
        """Update the content of a file in the tree.
329
310
 
330
311
        Note that the file is written in-place rather than being
358
339
        This is designed more towards DWIM for humans than API clarity.
359
340
        For the specific behaviour see the help for cmd_add().
360
341
 
361
 
        :param file_list: List of zero or more paths.  *NB: these are
362
 
            interpreted relative to the process cwd, not relative to the
 
342
        :param file_list: List of zero or more paths.  *NB: these are 
 
343
            interpreted relative to the process cwd, not relative to the 
363
344
            tree.*  (Add and most other tree methods use tree-relative
364
345
            paths.)
365
 
        :param action: A reporter to be called with the working tree, parent_ie,
 
346
        :param action: A reporter to be called with the inventory, parent_ie,
366
347
            path and kind of the path being added. It may return a file_id if
367
348
            a specific one should be used.
368
 
        :param save: Save the changes after completing the adds. If False
 
349
        :param save: Save the inventory after completing the adds. If False
369
350
            this provides dry-run functionality by doing the add and not saving
370
 
            the changes.
 
351
            the inventory.
371
352
        :return: A tuple - files_added, ignored_files. files_added is the count
372
353
            of added files, and ignored_files is a dict mapping files that were
373
354
            ignored to the rule that caused them to be ignored.
406
387
        """
407
388
        raise NotImplementedError(self.copy_one)
408
389
 
409
 
    def get_transform(self, pb=None):
410
 
        """Return a transform object for use with this tree."""
411
 
        raise NotImplementedError(self.get_transform)
412
 
 
413
390
 
414
391
class MutableTreeHooks(hooks.Hooks):
415
392
    """A dictionary mapping a hook name to a list of callables for mutabletree
422
399
        """
423
400
        hooks.Hooks.__init__(self, "breezy.mutabletree", "MutableTree.hooks")
424
401
        self.add_hook('start_commit',
425
 
                      "Called before a commit is performed on a tree. The start commit "
426
 
                      "hook is able to change the tree before the commit takes place. "
427
 
                      "start_commit is called with the breezy.mutabletree.MutableTree "
428
 
                      "that the commit is being performed on.", (1, 4))
 
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))
429
406
        self.add_hook('post_commit',
430
 
                      "Called after a commit is performed on a tree. The hook is "
431
 
                      "called with a breezy.mutabletree.PostCommitHookParams object. "
432
 
                      "The mutable tree the commit was performed on is available via "
433
 
                      "the mutable_tree attribute of that object.", (2, 0))
 
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))
434
411
        self.add_hook('pre_transform',
435
 
                      "Called before a tree transform on this tree. The hook is called "
436
 
                      "with the tree that is being transformed and the transform.",
437
 
                      (2, 5))
 
412
            "Called before a tree transform on this tree. The hook is called "
 
413
            "with the tree that is being transformed and the transform.",
 
414
            (2, 5))
438
415
        self.add_hook('post_build_tree',
439
 
                      "Called after a completely new tree is built. The hook is "
440
 
                      "called with the tree as its only argument.", (2, 5))
 
416
            "Called after a completely new tree is built. The hook is "
 
417
            "called with the tree as its only argument.", (2, 5))
441
418
        self.add_hook('post_transform',
442
 
                      "Called after a tree transform has been performed on a tree. "
443
 
                      "The hook is called with the tree that is being transformed and "
444
 
                      "the transform.",
445
 
                      (2, 5))
446
 
 
 
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 "
 
421
            "the transform.",
 
422
            (2, 5))
447
423
 
448
424
# install the default hooks into the MutableTree class.
449
425
MutableTree.hooks = MutableTreeHooks()