~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tree.py

  • Committer: Jelmer Vernooij
  • Date: 2012-02-23 16:48:41 UTC
  • mto: (6437.41.3 rmbranch-active)
  • mto: This revision was merged to the branch mainline in revision 6481.
  • Revision ID: jelmer@samba.org-20120223164841-eyy9xljbpblkchba
Support colocated branches in 'bzr rmbranch'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
532
532
        return find_ids_across_trees(paths, [self] + list(trees), require_versioned)
533
533
 
534
534
    def iter_children(self, file_id):
535
 
        """Iterate over the file ids of the children of an entry.
536
 
 
537
 
        :param file_id: File id of the entry
538
 
        :return: Iterator over child file ids.
539
 
        """
540
 
        raise NotImplementedError(self.iter_children)
 
535
        entry = self.iter_entries_by_dir([file_id]).next()[1]
 
536
        for child in getattr(entry, 'children', {}).itervalues():
 
537
            yield child.file_id
541
538
 
542
539
    def lock_read(self):
543
540
        """Lock this tree for multiple read only operations.
544
 
 
 
541
        
545
542
        :return: A bzrlib.lock.LogicalLockResult.
546
543
        """
547
544
        pass
771
768
            yield cur_path
772
769
        # all done.
773
770
 
774
 
    @deprecated_method(deprecated_in((2, 5, 0)))
775
771
    def _get_inventory(self):
776
772
        return self._inventory
777
773
 
778
774
    inventory = property(_get_inventory,
779
775
                         doc="Inventory of this Tree")
780
776
 
781
 
    def _get_root_inventory(self):
782
 
        return self._inventory
783
 
 
784
 
    root_inventory = property(_get_root_inventory,
785
 
        doc="Root inventory of this tree")
786
 
 
787
 
    def _unpack_file_id(self, file_id):
788
 
        """Find the inventory and inventory file id for a tree file id.
789
 
 
790
 
        :param file_id: The tree file id, as bytestring or tuple
791
 
        :return: Inventory and inventory file id
792
 
        """
793
 
        if isinstance(file_id, tuple):
794
 
            if len(file_id) != 1:
795
 
                raise ValueError("nested trees not yet supported: %r" % file_id)
796
 
            file_id = file_id[0]
797
 
        return self.root_inventory, file_id
798
 
 
799
777
    @needs_read_lock
800
778
    def path2id(self, path):
801
779
        """Return the id for path in this tree."""
802
 
        return self._path2inv_file_id(path)[1]
803
 
 
804
 
    def _path2inv_file_id(self, path):
805
 
        """Lookup a inventory and inventory file id by path.
806
 
 
807
 
        :param path: Path to look up
808
 
        :return: tuple with inventory and inventory file id
809
 
        """
810
 
        # FIXME: Support nested trees
811
 
        return self.root_inventory, self.root_inventory.path2id(path)
 
780
        return self._inventory.path2id(path)
812
781
 
813
782
    def id2path(self, file_id):
814
783
        """Return the path for a file id.
815
784
 
816
785
        :raises NoSuchId:
817
786
        """
818
 
        inventory, file_id = self._unpack_file_id(file_id)
819
 
        return inventory.id2path(file_id)
 
787
        return self.inventory.id2path(file_id)
820
788
 
821
789
    def has_id(self, file_id):
822
 
        inventory, file_id = self._unpack_file_id(file_id)
823
 
        return inventory.has_id(file_id)
 
790
        return self.inventory.has_id(file_id)
824
791
 
825
792
    def has_or_had_id(self, file_id):
826
 
        inventory, file_id = self._unpack_file_id(file_id)
827
 
        return inventory.has_id(file_id)
 
793
        return self.inventory.has_id(file_id)
828
794
 
829
795
    def all_file_ids(self):
830
 
        return set(
831
 
            [entry.file_id for path, entry in self.iter_entries_by_dir()])
 
796
        return set(self.inventory)
832
797
 
833
798
    @deprecated_method(deprecated_in((2, 4, 0)))
834
799
    def __iter__(self):
835
 
        return iter(self.all_file_ids())
 
800
        return iter(self.inventory)
836
801
 
837
802
    def filter_unversioned_files(self, paths):
838
803
        """Filter out paths that are versioned.
842
807
        # NB: we specifically *don't* call self.has_filename, because for
843
808
        # WorkingTrees that can indicate files that exist on disk but that
844
809
        # are not versioned.
845
 
        return set((p for p in paths if self.path2id(p) is None))
 
810
        pred = self.inventory.has_filename
 
811
        return set((p for p in paths if not pred(p)))
846
812
 
847
813
    @needs_read_lock
848
814
    def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
857
823
            down to specific_file_ids that have been requested. This has no
858
824
            impact if specific_file_ids is None.
859
825
        """
860
 
        if specific_file_ids is None:
861
 
            inventory_file_ids = None
862
 
        else:
863
 
            inventory_file_ids = []
864
 
            for tree_file_id in specific_file_ids:
865
 
                inventory, inv_file_id = self._unpack_file_id(tree_file_id)
866
 
                if not inventory is self.root_inventory: # for now
867
 
                    raise AssertionError("%r != %r" % (
868
 
                        inventory, self.root_inventory))
869
 
                inventory_file_ids.append(inv_file_id)
870
 
        # FIXME: Handle nested trees
871
 
        return self.root_inventory.iter_entries_by_dir(
872
 
            specific_file_ids=inventory_file_ids, yield_parents=yield_parents)
 
826
        return self.inventory.iter_entries_by_dir(
 
827
            specific_file_ids=specific_file_ids, yield_parents=yield_parents)
873
828
 
874
829
    @deprecated_method(deprecated_in((2, 5, 0)))
875
830
    def get_file_by_path(self, path):
876
831
        return self.get_file(self.path2id(path), path)
877
832
 
878
 
    def iter_children(self, file_id, path=None):
879
 
        """See Tree.iter_children."""
880
 
        entry = self.iter_entries_by_dir([file_id]).next()[1]
881
 
        for child in getattr(entry, 'children', {}).itervalues():
882
 
            yield child.file_id
883
 
 
884
833
 
885
834
def find_ids_across_trees(filenames, trees, require_versioned=True):
886
835
    """Find the ids corresponding to specified filenames.
1040
989
            if (self.source.get_symlink_target(file_id) !=
1041
990
                self.target.get_symlink_target(file_id)):
1042
991
                changed_content = True
1043
 
        elif source_kind == 'tree-reference':
1044
 
            if (self.source.get_reference_revision(file_id, source_path)
1045
 
                != self.target.get_reference_revision(file_id, target_path)):
 
992
            # XXX: Yes, the indentation below is wrong. But fixing it broke
 
993
            # test_merge.TestMergerEntriesLCAOnDisk.
 
994
            # test_nested_tree_subtree_renamed_and_modified. We'll wait for
 
995
            # the fix from bzr.dev -- vila 2009026
 
996
            elif source_kind == 'tree-reference':
 
997
                if (self.source.get_reference_revision(file_id, source_path)
 
998
                    != self.target.get_reference_revision(file_id, target_path)):
1046
999
                    changed_content = True
1047
1000
        parent = (source_parent, target_parent)
1048
1001
        name = (source_name, target_name)
1263
1216
        :param file_id: The file_id to lookup.
1264
1217
        """
1265
1218
        try:
1266
 
            inventory = tree.root_inventory
 
1219
            inventory = tree.inventory
1267
1220
        except NotImplementedError:
1268
1221
            # No inventory available.
1269
1222
            try:
1344
1297
                        if old_entry is None:
1345
1298
                            # Reusing a discarded change.
1346
1299
                            old_entry = self._get_entry(self.source, file_id)
1347
 
                        for child in self.source.iter_children(file_id):
1348
 
                            precise_file_ids.add(child)
 
1300
                        for child in old_entry.children.values():
 
1301
                            precise_file_ids.add(child.file_id)
1349
1302
                    changed_file_ids.add(result[0])
1350
1303
                    yield result
1351
1304
 
1494
1447
            return (None, None)
1495
1448
        else:
1496
1449
            self._out_of_order_processed.add(file_id)
1497
 
            cur_ie = other_tree.root_inventory[file_id]
 
1450
            cur_ie = other_tree.inventory[file_id]
1498
1451
            return (cur_path, cur_ie)
1499
1452
 
1500
1453
    def iter_all(self):