~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Andrew Bennetts
  • Date: 2009-06-09 03:14:05 UTC
  • mfrom: (4416 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4420.
  • Revision ID: andrew.bennetts@canonical.com-20090609031405-wak9yogzzpx9o172
Merge bzr.dev, resolving NEWS conflict.

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:
731
735
        return old_disk_path, new_disk_path
732
736
 
733
737
    def finish(self):
734
 
        osutils.rmtree(self._root)
 
738
        try:
 
739
            osutils.rmtree(self._root)
 
740
        except OSError, e:
 
741
            if e.errno != errno.ENOENT:
 
742
                mutter("The temporary directory \"%s\" was not "
 
743
                        "cleanly removed: %s." % (self._root, e))
735
744
 
736
745
    def diff(self, file_id, old_path, new_path, old_kind, new_kind):
737
746
        if (old_kind, new_kind) != ('file', 'file'):
882
891
                self.to_file.write("=== modified %s '%s'%s\n" % (kind[0],
883
892
                                   newpath_encoded, prop_str))
884
893
            if changed_content:
885
 
                self.diff(file_id, oldpath, newpath)
 
894
                self._diff(file_id, oldpath, newpath, kind[0], kind[1])
886
895
                has_changes = 1
887
896
            if renamed:
888
897
                has_changes = 1
903
912
            new_kind = self.new_tree.kind(file_id)
904
913
        except (errors.NoSuchId, errors.NoSuchFile):
905
914
            new_kind = None
906
 
 
 
915
        self._diff(file_id, old_path, new_path, old_kind, new_kind)
 
916
 
 
917
 
 
918
    def _diff(self, file_id, old_path, new_path, old_kind, new_kind):
907
919
        result = DiffPath._diff_many(self.differs, file_id, old_path,
908
920
                                       new_path, old_kind, new_kind)
909
921
        if result is DiffPath.CANNOT_DIFF: