~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Vincent Ladeuil
  • Date: 2009-05-05 15:31:34 UTC
  • mto: (4343.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4344.
  • Revision ID: v.ladeuil+lp@free.fr-20090505153134-q4bp4is9gywsmzrv
Clean up test for log formats.

* bzrlib/tests/blackbox/test_logformats.py:
Update tests to actual style.

Show diffs side-by-side

added added

removed removed

Lines of Context:
171
171
 
172
172
        if not diff_opts:
173
173
            diff_opts = []
174
 
        if sys.platform == 'win32':
175
 
            # Popen doesn't do the proper encoding for external commands
176
 
            # Since we are dealing with an ANSI api, use mbcs encoding
177
 
            old_filename = old_filename.encode('mbcs')
178
 
            new_filename = new_filename.encode('mbcs')
179
174
        diffcmd = ['diff',
180
175
                   '--label', old_filename,
181
176
                   old_abspath,
625
620
            return self.CANNOT_DIFF
626
621
        from_label = '%s%s\t%s' % (self.old_label, old_path, old_date)
627
622
        to_label = '%s%s\t%s' % (self.new_label, new_path, new_date)
628
 
        return self.diff_text(from_file_id, to_file_id, from_label, to_label,
629
 
            old_path, new_path)
 
623
        return self.diff_text(from_file_id, to_file_id, from_label, to_label)
630
624
 
631
 
    def diff_text(self, from_file_id, to_file_id, from_label, to_label,
632
 
        from_path=None, to_path=None):
 
625
    def diff_text(self, from_file_id, to_file_id, from_label, to_label):
633
626
        """Diff the content of given files in two trees
634
627
 
635
628
        :param from_file_id: The id of the file in the from tree.  If None,
637
630
        :param to_file_id: The id of the file in the to tree.  This may refer
638
631
            to a different file from from_file_id.  If None,
639
632
            the file is not present in the to tree.
640
 
        :param from_path: The path in the from tree or None if unknown.
641
 
        :param to_path: The path in the to tree or None if unknown.
642
633
        """
643
 
        def _get_text(tree, file_id, path):
 
634
        def _get_text(tree, file_id):
644
635
            if file_id is not None:
645
 
                return tree.get_file(file_id, path).readlines()
 
636
                return tree.get_file(file_id).readlines()
646
637
            else:
647
638
                return []
648
639
        try:
649
 
            from_text = _get_text(self.old_tree, from_file_id, from_path)
650
 
            to_text = _get_text(self.new_tree, to_file_id, to_path)
 
640
            from_text = _get_text(self.old_tree, from_file_id)
 
641
            to_text = _get_text(self.new_tree, to_file_id)
651
642
            self.text_differ(from_label, from_text, to_label, to_text,
652
643
                             self.to_file)
653
644
        except errors.BinaryFile:
740
731
        return old_disk_path, new_disk_path
741
732
 
742
733
    def finish(self):
743
 
        try:
744
 
            osutils.rmtree(self._root)
745
 
        except OSError, e:
746
 
            if e.errno != errno.ENOENT:
747
 
                mutter("The temporary directory \"%s\" was not "
748
 
                        "cleanly removed: %s." % (self._root, e))
 
734
        osutils.rmtree(self._root)
749
735
 
750
736
    def diff(self, file_id, old_path, new_path, old_kind, new_kind):
751
737
        if (old_kind, new_kind) != ('file', 'file'):
896
882
                self.to_file.write("=== modified %s '%s'%s\n" % (kind[0],
897
883
                                   newpath_encoded, prop_str))
898
884
            if changed_content:
899
 
                self._diff(file_id, oldpath, newpath, kind[0], kind[1])
 
885
                self.diff(file_id, oldpath, newpath)
900
886
                has_changes = 1
901
887
            if renamed:
902
888
                has_changes = 1
917
903
            new_kind = self.new_tree.kind(file_id)
918
904
        except (errors.NoSuchId, errors.NoSuchFile):
919
905
            new_kind = None
920
 
        self._diff(file_id, old_path, new_path, old_kind, new_kind)
921
 
 
922
 
 
923
 
    def _diff(self, file_id, old_path, new_path, old_kind, new_kind):
 
906
 
924
907
        result = DiffPath._diff_many(self.differs, file_id, old_path,
925
908
                                       new_path, old_kind, new_kind)
926
909
        if result is DiffPath.CANNOT_DIFF: