/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: Daniel Watkins
  • Date: 2007-11-06 09:33:05 UTC
  • mfrom: (2967 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2993.
  • Revision ID: d.m.watkins@warwick.ac.uk-20071106093305-zfef3c0jbcvunnuz
Merged bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    bzrdir,
30
30
    )
31
31
from bzrlib.osutils import dirname
 
32
from bzrlib.revisiontree import RevisionTree
32
33
from bzrlib.trace import mutter, warning
33
34
""")
34
35
 
108
109
            ids = [None] * len(files)
109
110
        else:
110
111
            assert(len(ids) == len(files))
111
 
            ids = [osutils.safe_file_id(file_id) for file_id in ids]
112
 
 
113
112
        if kinds is None:
114
113
            kinds = [None] * len(files)
115
114
        else:
159
158
    def apply_inventory_delta(self, changes):
160
159
        """Apply changes to the inventory as an atomic operation.
161
160
 
162
 
        The argument is a set of changes to apply.  It must describe a
163
 
        valid result, but the order is not important.  Specifically,
164
 
        intermediate stages *may* be invalid, such as when two files
165
 
        swap names.
166
 
 
167
 
        The changes should be structured as a list of tuples, of the form
168
 
        (old_path, new_path, file_id, new_entry).  For creation, old_path
169
 
        must be None.  For deletion, new_path and new_entry must be None.
170
 
        file_id is always non-None.  For renames and other mutations, all
171
 
        values must be non-None.
172
 
 
173
 
        If the new_entry is a directory, its children should be an empty
174
 
        dict.  Children are handled by apply_inventory_delta itself.
175
 
 
176
 
        :param changes: A list of tuples for the change to apply:
177
 
            [(old_path, new_path, file_id, new_inventory_entry), ...]
 
161
        :param changes: An inventory delta to apply to the working tree's
 
162
            inventory.
 
163
        :return None:
 
164
        :seealso Inventory.apply_delta: For details on the changes parameter.
178
165
        """
179
166
        self.flush()
180
167
        inv = self.inventory
181
 
        children = {}
182
 
        for old_path, file_id in sorted(((op, f) for op, np, f, e in changes
183
 
                                        if op is not None), reverse=True):
184
 
            if file_id not in inv:
185
 
                continue
186
 
            children[file_id] = getattr(inv[file_id], 'children', {})
187
 
            inv.remove_recursive_id(file_id)
188
 
        for new_path, new_entry in sorted((np, e) for op, np, f, e in
189
 
                                          changes if np is not None):
190
 
            if getattr(new_entry, 'children', None) is not None:
191
 
                new_entry.children = children.get(new_entry.file_id, {})
192
 
            inv.add(new_entry)
 
168
        inv.apply_delta(changes)
193
169
        self._write_inventory(inv)
194
170
 
195
171
    @needs_write_lock
453
429
                self.read_working_inventory()
454
430
        return added, ignored
455
431
 
 
432
    def update_basis_by_delta(self, new_revid, delta):
 
433
        """Update the parents of this tree after a commit.
 
434
 
 
435
        This gives the tree one parent, with revision id new_revid. The
 
436
        inventory delta is applied to the current basis tree to generate the
 
437
        inventory for the parent new_revid, and all other parent trees are
 
438
        discarded.
 
439
 
 
440
        All the changes in the delta should be changes synchronising the basis
 
441
        tree with some or all of the working tree, with a change to a directory
 
442
        requiring that its contents have been recursively included. That is,
 
443
        this is not a general purpose tree modification routine, but a helper
 
444
        for commit which is not required to handle situations that do not arise
 
445
        outside of commit.
 
446
 
 
447
        :param new_revid: The new revision id for the trees parent.
 
448
        :param delta: An inventory delta (see apply_inventory_delta) describing
 
449
            the changes from the current left most parent revision to new_revid.
 
450
        """
 
451
        # if the tree is updated by a pull to the branch, as happens in
 
452
        # WorkingTree2, when there was no separation between branch and tree,
 
453
        # then just clear merges, efficiency is not a concern for now as this
 
454
        # is legacy environments only, and they are slow regardless.
 
455
        if self.last_revision() == new_revid:
 
456
            self.set_parent_ids([new_revid])
 
457
            return
 
458
        # generic implementation based on Inventory manipulation. See
 
459
        # WorkingTree classes for optimised versions for specific format trees.
 
460
        basis = self.basis_tree()
 
461
        basis.lock_read()
 
462
        inventory = basis.inventory
 
463
        basis.unlock()
 
464
        inventory.apply_delta(delta)
 
465
        rev_tree = RevisionTree(self.branch.repository, inventory, new_revid)
 
466
        self.set_parent_trees([(new_revid, rev_tree)])
 
467
 
456
468
 
457
469
class _FastPath(object):
458
470
    """A path object with fast accessors for things like basename."""