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
778
790
def path2id(self, path):
779
791
"""Return the id for path in this tree."""
780
return self.inventory.path2id(path)
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)
782
802
def id2path(self, file_id):
783
803
"""Return the path for a file id.
785
805
:raises NoSuchId:
787
return self.inventory.id2path(file_id)
807
inventory, file_id = self._unpack_file_id(file_id)
808
return inventory.id2path(file_id)
789
810
def has_id(self, file_id):
790
return self.inventory.has_id(file_id)
811
inventory, file_id = self._unpack_file_id(file_id)
812
return inventory.has_id(file_id)
792
814
def has_or_had_id(self, file_id):
793
return self.inventory.has_id(file_id)
815
inventory, file_id = self._unpack_file_id(file_id)
816
return inventory.has_id(file_id)
795
818
def all_file_ids(self):
823
846
down to specific_file_ids that have been requested. This has no
824
847
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)
826
859
return self.inventory.iter_entries_by_dir(
827
specific_file_ids=specific_file_ids, yield_parents=yield_parents)
860
specific_file_ids=inventory_file_ids, yield_parents=yield_parents)
829
862
@deprecated_method(deprecated_in((2, 5, 0)))
830
863
def get_file_by_path(self, path):