~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tree.py

(vila) Do not show exception to user on pointless commit error. (Jonathan
 Riddell)

Show diffs side-by-side

added added

removed removed

Lines of Context:
127
127
    def has_id(self, file_id):
128
128
        raise NotImplementedError(self.has_id)
129
129
 
130
 
    @deprecated_method(deprecated_in((2, 4, 0)))
131
130
    def __contains__(self, file_id):
132
131
        return self.has_id(file_id)
133
132
 
175
174
             g
176
175
 
177
176
        The yield order (ignoring root) would be::
178
 
 
179
177
          a, f, a/b, a/d, a/b/c, a/d/e, f/g
180
178
 
181
179
        :param yield_parents: If True, yield the parents from the root leading
291
289
 
292
290
        :param file_id: The file_id of the file.
293
291
        :param path: The path of the file.
294
 
 
295
292
        If both file_id and path are supplied, an implementation may use
296
293
        either one.
297
294
        """
298
295
        return osutils.split_lines(self.get_file_text(file_id, path))
299
296
 
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.
302
299
 
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
307
303
        """
308
304
        raise NotImplementedError(self.get_file_sha1)
309
305
 
801
797
        return self.get_file(self._inventory.path2id(path), path)
802
798
 
803
799
 
 
800
######################################################################
 
801
# diff
 
802
 
 
803
# TODO: Merge these two functions into a single one that can operate
 
804
# on either a whole tree or a set of files.
 
805
 
 
806
# TODO: Return the diff in order by filename, not by category or in
 
807
# random order.  Can probably be done by lock-stepping through the
 
808
# filenames from both trees.
 
809
 
 
810
 
 
811
def file_status(filename, old_tree, new_tree):
 
812
    """Return single-letter status, old and new names for a file.
 
813
 
 
814
    The complexity here is in deciding how to represent renames;
 
815
    many complex cases are possible.
 
816
    """
 
817
    old_inv = old_tree.inventory
 
818
    new_inv = new_tree.inventory
 
819
    new_id = new_inv.path2id(filename)
 
820
    old_id = old_inv.path2id(filename)
 
821
 
 
822
    if not new_id and not old_id:
 
823
        # easy: doesn't exist in either; not versioned at all
 
824
        if new_tree.is_ignored(filename):
 
825
            return 'I', None, None
 
826
        else:
 
827
            return '?', None, None
 
828
    elif new_id:
 
829
        # There is now a file of this name, great.
 
830
        pass
 
831
    else:
 
832
        # There is no longer a file of this name, but we can describe
 
833
        # what happened to the file that used to have
 
834
        # this name.  There are two possibilities: either it was
 
835
        # deleted entirely, or renamed.
 
836
        if new_inv.has_id(old_id):
 
837
            return 'X', old_inv.id2path(old_id), new_inv.id2path(old_id)
 
838
        else:
 
839
            return 'D', old_inv.id2path(old_id), None
 
840
 
 
841
    # if the file_id is new in this revision, it is added
 
842
    if new_id and not old_inv.has_id(new_id):
 
843
        return 'A'
 
844
 
 
845
    # if there used to be a file of this name, but that ID has now
 
846
    # disappeared, it is deleted
 
847
    if old_id and not new_inv.has_id(old_id):
 
848
        return 'D'
 
849
 
 
850
    return 'wtf?'
 
851
 
 
852
 
804
853
def find_ids_across_trees(filenames, trees, require_versioned=True):
805
854
    """Find the ids corresponding to specified filenames.
806
855
 
811
860
        None)
812
861
    :param trees: The trees to find file_ids within
813
862
    :param require_versioned: if true, all specified filenames must occur in
814
 
        at least one tree.
 
863
    at least one tree.
815
864
    :return: a set of file ids for the specified filenames and their children.
816
865
    """
817
866
    if not filenames: