~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/mutabletree.py

  • Committer: Jelmer Vernooij
  • Date: 2011-04-15 11:26:00 UTC
  • mfrom: (5757.7.7 knitpackrepo-6)
  • mto: This revision was merged to the branch mainline in revision 5801.
  • Revision ID: jelmer@samba.org-20110415112600-vrv2431lh3gi6wx2
MergeĀ knitpackrepo-6.

Show diffs side-by-side

added added

removed removed

Lines of Context:
160
160
        if sub_tree_id == self.get_root_id():
161
161
            raise errors.BadReferenceTarget(self, sub_tree,
162
162
                                     'Trees have the same root id.')
163
 
        if sub_tree_id in self.inventory:
 
163
        if sub_tree_id in self:
164
164
            raise errors.BadReferenceTarget(self, sub_tree,
165
165
                                            'Root id already present in tree')
166
166
        self._add([sub_tree_path], [sub_tree_id], ['tree-reference'])
175
175
        """
176
176
        raise NotImplementedError(self._add)
177
177
 
178
 
    @needs_tree_write_lock
179
178
    def apply_inventory_delta(self, changes):
180
179
        """Apply changes to the inventory as an atomic operation.
181
180
 
184
183
        :return None:
185
184
        :seealso Inventory.apply_delta: For details on the changes parameter.
186
185
        """
187
 
        self.flush()
188
 
        inv = self.inventory
189
 
        inv.apply_delta(changes)
190
 
        self._write_inventory(inv)
 
186
        raise NotImplementedError(self.apply_inventory_delta)
191
187
 
192
188
    @needs_write_lock
193
189
    def commit(self, message=None, revprops=None, *args,
345
341
        :return: None
346
342
        """
347
343
 
348
 
    def _fix_case_of_inventory_path(self, path):
349
 
        """If our tree isn't case sensitive, return the canonical path"""
350
 
        if not self.case_sensitive:
351
 
            path = self.get_canonical_inventory_path(path)
352
 
        return path
353
 
 
354
344
    @needs_write_lock
355
345
    def put_file_bytes_non_atomic(self, file_id, bytes):
356
346
        """Update the content of a file in the tree.
380
370
        """
381
371
        raise NotImplementedError(self.set_parent_trees)
382
372
 
 
373
    def smart_add(self, file_list, recurse=True, action=None, save=True):
 
374
        """Version file_list, optionally recursing into directories.
 
375
 
 
376
        This is designed more towards DWIM for humans than API clarity.
 
377
        For the specific behaviour see the help for cmd_add().
 
378
 
 
379
        :param file_list: List of zero or more paths.  *NB: these are 
 
380
            interpreted relative to the process cwd, not relative to the 
 
381
            tree.*  (Add and most other tree methods use tree-relative
 
382
            paths.)
 
383
        :param action: A reporter to be called with the inventory, parent_ie,
 
384
            path and kind of the path being added. It may return a file_id if
 
385
            a specific one should be used.
 
386
        :param save: Save the inventory after completing the adds. If False
 
387
            this provides dry-run functionality by doing the add and not saving
 
388
            the inventory.
 
389
        :return: A tuple - files_added, ignored_files. files_added is the count
 
390
            of added files, and ignored_files is a dict mapping files that were
 
391
            ignored to the rule that caused them to be ignored.
 
392
        """
 
393
        raise NotImplementedError(self.smart_add)
 
394
 
 
395
    def update_basis_by_delta(self, new_revid, delta):
 
396
        """Update the parents of this tree after a commit.
 
397
 
 
398
        This gives the tree one parent, with revision id new_revid. The
 
399
        inventory delta is applied to the current basis tree to generate the
 
400
        inventory for the parent new_revid, and all other parent trees are
 
401
        discarded.
 
402
 
 
403
        All the changes in the delta should be changes synchronising the basis
 
404
        tree with some or all of the working tree, with a change to a directory
 
405
        requiring that its contents have been recursively included. That is,
 
406
        this is not a general purpose tree modification routine, but a helper
 
407
        for commit which is not required to handle situations that do not arise
 
408
        outside of commit.
 
409
 
 
410
        See the inventory developers documentation for the theory behind
 
411
        inventory deltas.
 
412
 
 
413
        :param new_revid: The new revision id for the trees parent.
 
414
        :param delta: An inventory delta (see apply_inventory_delta) describing
 
415
            the changes from the current left most parent revision to new_revid.
 
416
        """
 
417
        raise NotImplementedError(self.update_basis_by_delta)
 
418
 
 
419
 
 
420
class MutableInventoryTree(MutableTree,tree.InventoryTree):
 
421
 
 
422
    @needs_tree_write_lock
 
423
    def apply_inventory_delta(self, changes):
 
424
        """Apply changes to the inventory as an atomic operation.
 
425
 
 
426
        :param changes: An inventory delta to apply to the working tree's
 
427
            inventory.
 
428
        :return None:
 
429
        :seealso Inventory.apply_delta: For details on the changes parameter.
 
430
        """
 
431
        self.flush()
 
432
        inv = self.inventory
 
433
        inv.apply_delta(changes)
 
434
        self._write_inventory(inv)
 
435
 
 
436
    def _fix_case_of_inventory_path(self, path):
 
437
        """If our tree isn't case sensitive, return the canonical path"""
 
438
        if not self.case_sensitive:
 
439
            path = self.get_canonical_inventory_path(path)
 
440
        return path
 
441
 
383
442
    @needs_tree_write_lock
384
443
    def smart_add(self, file_list, recurse=True, action=None, save=True):
385
444
        """Version file_list, optionally recursing into directories.
642
701
        self.set_parent_trees([(new_revid, rev_tree)])
643
702
 
644
703
 
 
704
 
 
705
 
645
706
class MutableTreeHooks(hooks.Hooks):
646
707
    """A dictionary mapping a hook name to a list of callables for mutabletree
647
708
    hooks.