774
774
inventory = property(_get_inventory,
775
775
doc="Inventory of this Tree")
777
def _unpack_file_id(self, file_id):
778
"""Find the inventory and inventory file id for a tree file id.
780
:param file_id: The tree file id, as bytestring or tuple
781
:return: Inventory and inventory file id
783
if isinstance(file_id, tuple):
784
if len(file_id) != 1:
785
raise ValueError("nested trees not yet supported: %r" % file_id)
787
return self.inventory, file_id
790
778
def path2id(self, path):
791
779
"""Return the id for path in this tree."""
792
return self._path2inv_file_id(path)[1]
794
def _path2inv_file_id(self, path):
795
"""Lookup a inventory and inventory file id by path.
797
:param path: Path to look up
798
:return: tuple with inventory and inventory file id
800
return self.inventory, self.inventory.path2id(path)
780
return self._inventory.path2id(path)
802
782
def id2path(self, file_id):
803
783
"""Return the path for a file id.
805
785
:raises NoSuchId:
807
inventory, file_id = self._unpack_file_id(file_id)
808
return inventory.id2path(file_id)
787
return self.inventory.id2path(file_id)
810
789
def has_id(self, file_id):
811
inventory, file_id = self._unpack_file_id(file_id)
812
return inventory.has_id(file_id)
790
return self.inventory.has_id(file_id)
814
792
def has_or_had_id(self, file_id):
815
inventory, file_id = self._unpack_file_id(file_id)
816
return inventory.has_id(file_id)
793
return self.inventory.has_id(file_id)
818
795
def all_file_ids(self):
820
[entry.file_id for path, entry in self.iter_entries_by_dir()])
796
return set(self.inventory)
822
798
@deprecated_method(deprecated_in((2, 4, 0)))
823
799
def __iter__(self):
824
return iter(self.all_file_ids())
800
return iter(self.inventory)
826
802
def filter_unversioned_files(self, paths):
827
803
"""Filter out paths that are versioned.
831
807
# NB: we specifically *don't* call self.has_filename, because for
832
808
# WorkingTrees that can indicate files that exist on disk but that
833
809
# are not versioned.
834
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)))
837
814
def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
846
823
down to specific_file_ids that have been requested. This has no
847
824
impact if specific_file_ids is None.
849
if specific_file_ids is None:
850
inventory_file_ids = None
852
inventory_file_ids = []
853
for tree_file_id in specific_file_ids:
854
inventory, inv_file_id = self._unpack_file_id(tree_file_id)
855
if not inventory is self.inventory: # for now
856
raise AssertionError("%r != %r" % (
857
inventory, self.inventory))
858
inventory_file_ids.append(inv_file_id)
859
826
return self.inventory.iter_entries_by_dir(
860
specific_file_ids=inventory_file_ids, yield_parents=yield_parents)
827
specific_file_ids=specific_file_ids, yield_parents=yield_parents)
862
829
@deprecated_method(deprecated_in((2, 5, 0)))
863
830
def get_file_by_path(self, path):