196
196
raise NotImplementedError(self.iter_entries_by_dir)
198
def iter_child_entries(self, file_id, path=None):
199
"""Iterate over the children of a directory or tree reference.
201
:param file_id: File id of the directory/tree-reference
202
:param path: Optional path of the directory
203
:raise NoSuchId: When the file_id does not exist
204
:return: Iterator over entries in the directory
206
raise NotImplementedError(self.iter_child_entries)
198
208
def list_files(self, include_root=False, from_dir=None, recursive=True):
199
209
"""List all files in this tree.
532
542
return find_ids_across_trees(paths, [self] + list(trees), require_versioned)
534
544
def iter_children(self, file_id):
535
entry = self.iter_entries_by_dir([file_id]).next()[1]
536
for child in getattr(entry, 'children', {}).itervalues():
545
"""Iterate over the file ids of the children of an entry.
547
:param file_id: File id of the entry
548
:return: Iterator over child file ids.
550
raise NotImplementedError(self.iter_children)
539
552
def lock_read(self):
540
553
"""Lock this tree for multiple read only operations.
542
555
:return: A bzrlib.lock.LogicalLockResult.
784
@deprecated_method(deprecated_in((2, 5, 0)))
771
785
def _get_inventory(self):
772
786
return self._inventory
774
788
inventory = property(_get_inventory,
775
789
doc="Inventory of this Tree")
791
def _get_root_inventory(self):
792
return self._inventory
794
root_inventory = property(_get_root_inventory,
795
doc="Root inventory of this tree")
797
def _unpack_file_id(self, file_id):
798
"""Find the inventory and inventory file id for a tree file id.
800
:param file_id: The tree file id, as bytestring or tuple
801
:return: Inventory and inventory file id
803
if isinstance(file_id, tuple):
804
if len(file_id) != 1:
805
raise ValueError("nested trees not yet supported: %r" % file_id)
807
return self.root_inventory, file_id
778
810
def path2id(self, path):
779
811
"""Return the id for path in this tree."""
780
return self._inventory.path2id(path)
812
return self._path2inv_file_id(path)[1]
814
def _path2inv_file_id(self, path):
815
"""Lookup a inventory and inventory file id by path.
817
:param path: Path to look up
818
:return: tuple with inventory and inventory file id
820
# FIXME: Support nested trees
821
return self.root_inventory, self.root_inventory.path2id(path)
782
823
def id2path(self, file_id):
783
824
"""Return the path for a file id.
785
826
:raises NoSuchId:
787
return self.inventory.id2path(file_id)
828
inventory, file_id = self._unpack_file_id(file_id)
829
return inventory.id2path(file_id)
789
831
def has_id(self, file_id):
790
return self.inventory.has_id(file_id)
832
inventory, file_id = self._unpack_file_id(file_id)
833
return inventory.has_id(file_id)
792
835
def has_or_had_id(self, file_id):
793
return self.inventory.has_id(file_id)
836
inventory, file_id = self._unpack_file_id(file_id)
837
return inventory.has_id(file_id)
795
839
def all_file_ids(self):
796
return set(self.inventory)
841
[entry.file_id for path, entry in self.iter_entries_by_dir()])
798
843
@deprecated_method(deprecated_in((2, 4, 0)))
799
844
def __iter__(self):
800
return iter(self.inventory)
845
return iter(self.all_file_ids())
802
847
def filter_unversioned_files(self, paths):
803
848
"""Filter out paths that are versioned.
807
852
# NB: we specifically *don't* call self.has_filename, because for
808
853
# WorkingTrees that can indicate files that exist on disk but that
809
854
# are not versioned.
810
pred = self.inventory.has_filename
811
return set((p for p in paths if not pred(p)))
855
return set((p for p in paths if self.path2id(p) is None))
814
858
def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
823
867
down to specific_file_ids that have been requested. This has no
824
868
impact if specific_file_ids is None.
826
return self.inventory.iter_entries_by_dir(
827
specific_file_ids=specific_file_ids, yield_parents=yield_parents)
870
if specific_file_ids is None:
871
inventory_file_ids = None
873
inventory_file_ids = []
874
for tree_file_id in specific_file_ids:
875
inventory, inv_file_id = self._unpack_file_id(tree_file_id)
876
if not inventory is self.root_inventory: # for now
877
raise AssertionError("%r != %r" % (
878
inventory, self.root_inventory))
879
inventory_file_ids.append(inv_file_id)
880
# FIXME: Handle nested trees
881
return self.root_inventory.iter_entries_by_dir(
882
specific_file_ids=inventory_file_ids, yield_parents=yield_parents)
885
def iter_child_entries(self, file_id, path=None):
886
inv, inv_file_id = self._unpack_file_id(file_id)
887
return inv[inv_file_id].children.itervalues()
829
889
@deprecated_method(deprecated_in((2, 5, 0)))
830
890
def get_file_by_path(self, path):
831
891
return self.get_file(self.path2id(path), path)
893
def iter_children(self, file_id, path=None):
894
"""See Tree.iter_children."""
895
entry = self.iter_entries_by_dir([file_id]).next()[1]
896
for child in getattr(entry, 'children', {}).itervalues():
834
900
def find_ids_across_trees(filenames, trees, require_versioned=True):
835
901
"""Find the ids corresponding to specified filenames.
989
1055
if (self.source.get_symlink_target(file_id) !=
990
1056
self.target.get_symlink_target(file_id)):
991
1057
changed_content = True
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)):
1058
elif source_kind == 'tree-reference':
1059
if (self.source.get_reference_revision(file_id, source_path)
1060
!= self.target.get_reference_revision(file_id, target_path)):
999
1061
changed_content = True
1000
1062
parent = (source_parent, target_parent)
1001
1063
name = (source_name, target_name)