58
61
trees or versioned trees.
64
def has_versioned_directories(self):
65
"""Whether this tree can contain explicitly versioned directories.
67
This defaults to True, but some implementations may want to override
61
72
def changes_from(self, other, want_unchanged=False, specific_files=None,
62
73
extra_trees=None, require_versioned=False, include_root=False,
63
74
want_unversioned=False):
185
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)
187
208
def list_files(self, include_root=False, from_dir=None, recursive=True):
188
209
"""List all files in this tree.
524
542
return find_ids_across_trees(paths, [self] + list(trees), require_versioned)
526
544
def iter_children(self, file_id):
527
entry = self.iter_entries_by_dir([file_id]).next()[1]
528
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)
531
552
def lock_read(self):
532
553
"""Lock this tree for multiple read only operations.
534
555
:return: A bzrlib.lock.LogicalLockResult.
623
644
prefs = self.iter_search_rules([path], filter_pref_names).next()
624
645
stk = filters._get_filter_stack_for(prefs)
625
646
if 'filters' in debug.debug_flags:
626
trace.note("*** %s content-filter: %s => %r" % (path,prefs,stk))
647
trace.note(gettext("*** {0} content-filter: {1} => {2!r}").format(path,prefs,stk))
629
650
def _content_filter_stack_provider(self):
784
@deprecated_method(deprecated_in((2, 5, 0)))
763
785
def _get_inventory(self):
764
786
return self._inventory
766
788
inventory = property(_get_inventory,
767
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
770
810
def path2id(self, path):
771
811
"""Return the id for path in this tree."""
772
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)
774
823
def id2path(self, file_id):
775
824
"""Return the path for a file id.
777
826
:raises NoSuchId:
779
return self.inventory.id2path(file_id)
828
inventory, file_id = self._unpack_file_id(file_id)
829
return inventory.id2path(file_id)
781
831
def has_id(self, file_id):
782
return self.inventory.has_id(file_id)
832
inventory, file_id = self._unpack_file_id(file_id)
833
return inventory.has_id(file_id)
784
835
def has_or_had_id(self, file_id):
785
return self.inventory.has_id(file_id)
836
inventory, file_id = self._unpack_file_id(file_id)
837
return inventory.has_id(file_id)
787
839
def all_file_ids(self):
788
return set(self.inventory)
841
[entry.file_id for path, entry in self.iter_entries_by_dir()])
790
843
@deprecated_method(deprecated_in((2, 4, 0)))
791
844
def __iter__(self):
792
return iter(self.inventory)
845
return iter(self.all_file_ids())
794
847
def filter_unversioned_files(self, paths):
795
848
"""Filter out paths that are versioned.
799
852
# NB: we specifically *don't* call self.has_filename, because for
800
853
# WorkingTrees that can indicate files that exist on disk but that
801
854
# are not versioned.
802
pred = self.inventory.has_filename
803
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))
806
858
def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
815
867
down to specific_file_ids that have been requested. This has no
816
868
impact if specific_file_ids is None.
818
return self.inventory.iter_entries_by_dir(
819
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()
889
@deprecated_method(deprecated_in((2, 5, 0)))
821
890
def get_file_by_path(self, path):
822
return self.get_file(self._inventory.path2id(path), path)
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():
825
900
def find_ids_across_trees(filenames, trees, require_versioned=True):
980
1055
if (self.source.get_symlink_target(file_id) !=
981
1056
self.target.get_symlink_target(file_id)):
982
1057
changed_content = True
983
# XXX: Yes, the indentation below is wrong. But fixing it broke
984
# test_merge.TestMergerEntriesLCAOnDisk.
985
# test_nested_tree_subtree_renamed_and_modified. We'll wait for
986
# the fix from bzr.dev -- vila 2009026
987
elif source_kind == 'tree-reference':
988
if (self.source.get_reference_revision(file_id, source_path)
989
!= 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)):
990
1061
changed_content = True
991
1062
parent = (source_parent, target_parent)
992
1063
name = (source_name, target_name)