~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Ian Clatworthy
  • Date: 2009-05-28 13:46:52 UTC
  • mfrom: (4377.3.4 faster-diff)
  • mto: This revision was merged to the branch mainline in revision 4390.
  • Revision ID: ian.clatworthy@canonical.com-20090528134652-g1j4m0rr1g1hdcpe
(igc) faster diff on large trees (Ian Clatworthy)

Show diffs side-by-side

added added

removed removed

Lines of Context:
620
620
            return self.CANNOT_DIFF
621
621
        from_label = '%s%s\t%s' % (self.old_label, old_path, old_date)
622
622
        to_label = '%s%s\t%s' % (self.new_label, new_path, new_date)
623
 
        return self.diff_text(from_file_id, to_file_id, from_label, to_label)
 
623
        return self.diff_text(from_file_id, to_file_id, from_label, to_label,
 
624
            old_path, new_path)
624
625
 
625
 
    def diff_text(self, from_file_id, to_file_id, from_label, to_label):
 
626
    def diff_text(self, from_file_id, to_file_id, from_label, to_label,
 
627
        from_path=None, to_path=None):
626
628
        """Diff the content of given files in two trees
627
629
 
628
630
        :param from_file_id: The id of the file in the from tree.  If None,
630
632
        :param to_file_id: The id of the file in the to tree.  This may refer
631
633
            to a different file from from_file_id.  If None,
632
634
            the file is not present in the to tree.
 
635
        :param from_path: The path in the from tree or None if unknown.
 
636
        :param to_path: The path in the to tree or None if unknown.
633
637
        """
634
 
        def _get_text(tree, file_id):
 
638
        def _get_text(tree, file_id, path):
635
639
            if file_id is not None:
636
 
                return tree.get_file(file_id).readlines()
 
640
                return tree.get_file(file_id, path).readlines()
637
641
            else:
638
642
                return []
639
643
        try:
640
 
            from_text = _get_text(self.old_tree, from_file_id)
641
 
            to_text = _get_text(self.new_tree, to_file_id)
 
644
            from_text = _get_text(self.old_tree, from_file_id, from_path)
 
645
            to_text = _get_text(self.new_tree, to_file_id, to_path)
642
646
            self.text_differ(from_label, from_text, to_label, to_text,
643
647
                             self.to_file)
644
648
        except errors.BinaryFile:
882
886
                self.to_file.write("=== modified %s '%s'%s\n" % (kind[0],
883
887
                                   newpath_encoded, prop_str))
884
888
            if changed_content:
885
 
                self.diff(file_id, oldpath, newpath)
 
889
                self._diff(file_id, oldpath, newpath, kind[0], kind[1])
886
890
                has_changes = 1
887
891
            if renamed:
888
892
                has_changes = 1
903
907
            new_kind = self.new_tree.kind(file_id)
904
908
        except (errors.NoSuchId, errors.NoSuchFile):
905
909
            new_kind = None
906
 
 
 
910
        self._diff(file_id, old_path, new_path, old_kind, new_kind)
 
911
 
 
912
 
 
913
    def _diff(self, file_id, old_path, new_path, old_kind, new_kind):
907
914
        result = DiffPath._diff_many(self.differs, file_id, old_path,
908
915
                                       new_path, old_kind, new_kind)
909
916
        if result is DiffPath.CANNOT_DIFF: