127
123
def has_id(self, file_id):
128
124
raise NotImplementedError(self.has_id)
130
@deprecated_method(deprecated_in((2, 4, 0)))
131
126
def __contains__(self, file_id):
132
127
return self.has_id(file_id)
141
"""Yield all file ids in this tree."""
142
raise NotImplementedError(self.__iter__)
145
144
def all_file_ids(self):
146
145
"""Iterate through all file ids, including ids for missing files."""
147
raise NotImplementedError(self.all_file_ids)
146
return set(self.inventory)
149
148
def id2path(self, file_id):
150
149
"""Return the path for a file id.
177
176
The yield order (ignoring root) would be::
179
177
a, f, a/b, a/d, a/b/c, a/d/e, f/g
181
179
:param yield_parents: If True, yield the parents from the root leading
292
290
:param file_id: The file_id of the file.
293
291
:param path: The path of the file.
295
292
If both file_id and path are supplied, an implementation may use
298
295
return osutils.split_lines(self.get_file_text(file_id, path))
300
def get_file_sha1(self, file_id, path=None, stat_value=None):
297
def get_file_sha1(self, file_id, path=None):
301
298
"""Return the SHA1 file for a file.
303
300
:param file_id: The handle for this file.
304
301
:param path: The path that this file can be found at.
305
302
These must point to the same object.
306
:param stat_value: Optional stat value for the object
308
304
raise NotImplementedError(self.get_file_sha1)
363
359
cur_file = (self.get_file_text(file_id),)
364
360
yield identifier, cur_file
366
def get_symlink_target(self, file_id, path=None):
362
def get_symlink_target(self, file_id):
367
363
"""Get the target for a given file_id.
369
365
It is assumed that the caller already knows that file_id is referencing
371
367
:param file_id: Handle for the symlink entry.
372
:param path: The path of the file.
373
If both file_id and path are supplied, an implementation may use
375
368
:return: The path the symlink points to.
377
370
raise NotImplementedError(self.get_symlink_target)
379
373
def get_root_id(self):
380
374
"""Return the file_id for the root of this tree."""
381
375
raise NotImplementedError(self.get_root_id)
763
757
def has_or_had_id(self, file_id):
764
758
return self.inventory.has_id(file_id)
766
def all_file_ids(self):
767
return set(self.inventory)
769
@deprecated_method(deprecated_in((2, 4, 0)))
770
760
def __iter__(self):
771
761
return iter(self.inventory)
801
791
return self.get_file(self._inventory.path2id(path), path)
794
######################################################################
797
# TODO: Merge these two functions into a single one that can operate
798
# on either a whole tree or a set of files.
800
# TODO: Return the diff in order by filename, not by category or in
801
# random order. Can probably be done by lock-stepping through the
802
# filenames from both trees.
805
def file_status(filename, old_tree, new_tree):
806
"""Return single-letter status, old and new names for a file.
808
The complexity here is in deciding how to represent renames;
809
many complex cases are possible.
811
old_inv = old_tree.inventory
812
new_inv = new_tree.inventory
813
new_id = new_inv.path2id(filename)
814
old_id = old_inv.path2id(filename)
816
if not new_id and not old_id:
817
# easy: doesn't exist in either; not versioned at all
818
if new_tree.is_ignored(filename):
819
return 'I', None, None
821
return '?', None, None
823
# There is now a file of this name, great.
826
# There is no longer a file of this name, but we can describe
827
# what happened to the file that used to have
828
# this name. There are two possibilities: either it was
829
# deleted entirely, or renamed.
830
if new_inv.has_id(old_id):
831
return 'X', old_inv.id2path(old_id), new_inv.id2path(old_id)
833
return 'D', old_inv.id2path(old_id), None
835
# if the file_id is new in this revision, it is added
836
if new_id and not old_inv.has_id(new_id):
839
# if there used to be a file of this name, but that ID has now
840
# disappeared, it is deleted
841
if old_id and not new_inv.has_id(old_id):
804
847
def find_ids_across_trees(filenames, trees, require_versioned=True):
805
848
"""Find the ids corresponding to specified filenames.
897
def is_compatible(kls, source, target):
898
# The default implementation is naive and uses the public API, so
899
# it works for all trees.
902
939
def _changes_from_entries(self, source_entry, target_entry,
903
940
source_path=None, target_path=None):
904
941
"""Generate a iter_changes tuple between source_entry and target_entry.