356
358
raise NotImplementedError(self.get_file_size)
358
def get_file_by_path(self, path):
359
raise NotImplementedError(self.get_file_by_path)
361
360
def is_executable(self, file_id, path=None):
362
361
"""Check if a file is executable.
775
774
inventory = property(_get_inventory,
776
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
779
790
def path2id(self, path):
780
791
"""Return the id for path in this tree."""
781
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)
783
802
def id2path(self, file_id):
784
803
"""Return the path for a file id.
786
805
:raises NoSuchId:
788
return self.inventory.id2path(file_id)
807
inventory, file_id = self._unpack_file_id(file_id)
808
return inventory.id2path(file_id)
790
810
def has_id(self, file_id):
791
return self.inventory.has_id(file_id)
811
inventory, file_id = self._unpack_file_id(file_id)
812
return inventory.has_id(file_id)
793
814
def has_or_had_id(self, file_id):
794
return self.inventory.has_id(file_id)
815
inventory, file_id = self._unpack_file_id(file_id)
816
return inventory.has_id(file_id)
796
818
def all_file_ids(self):
797
return set(self.inventory)
820
[entry.file_id for path, entry in self.iter_entries_by_dir()])
799
822
@deprecated_method(deprecated_in((2, 4, 0)))
800
823
def __iter__(self):
801
return iter(self.inventory)
824
return iter(self.all_file_ids())
803
826
def filter_unversioned_files(self, paths):
804
827
"""Filter out paths that are versioned.
808
831
# NB: we specifically *don't* call self.has_filename, because for
809
832
# WorkingTrees that can indicate files that exist on disk but that
810
833
# are not versioned.
811
pred = self.inventory.has_filename
812
return set((p for p in paths if not pred(p)))
834
return set((p for p in paths if self.path2id(p) is None))
815
837
def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
824
846
down to specific_file_ids that have been requested. This has no
825
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)
827
859
return self.inventory.iter_entries_by_dir(
828
specific_file_ids=specific_file_ids, yield_parents=yield_parents)
860
specific_file_ids=inventory_file_ids, yield_parents=yield_parents)
862
@deprecated_method(deprecated_in((2, 5, 0)))
830
863
def get_file_by_path(self, path):
831
return self.get_file(self._inventory.path2id(path), path)
864
return self.get_file(self.path2id(path), path)
834
867
def find_ids_across_trees(filenames, trees, require_versioned=True):