/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: John Arbash Meinel
  • Date: 2009-08-26 16:03:59 UTC
  • mto: (4634.6.7 2.0)
  • mto: This revision was merged to the branch mainline in revision 4660.
  • Revision ID: john@arbash-meinel.com-20090826160359-ge4mai928bi3a5g2
Fix bug #419241. If a graph had a mainline ghost
we could get a segfault during KnownGraph.merge_sort().

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')
174
179
        diffcmd = ['diff',
175
180
                   '--label', old_filename,
176
181
                   old_abspath,
620
625
            return self.CANNOT_DIFF
621
626
        from_label = '%s%s\t%s' % (self.old_label, old_path, old_date)
622
627
        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)
 
628
        return self.diff_text(from_file_id, to_file_id, from_label, to_label,
 
629
            old_path, new_path)
624
630
 
625
 
    def diff_text(self, from_file_id, to_file_id, from_label, to_label):
 
631
    def diff_text(self, from_file_id, to_file_id, from_label, to_label,
 
632
        from_path=None, to_path=None):
626
633
        """Diff the content of given files in two trees
627
634
 
628
635
        :param from_file_id: The id of the file in the from tree.  If None,
630
637
        :param to_file_id: The id of the file in the to tree.  This may refer
631
638
            to a different file from from_file_id.  If None,
632
639
            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.
633
642
        """
634
 
        def _get_text(tree, file_id):
 
643
        def _get_text(tree, file_id, path):
635
644
            if file_id is not None:
636
 
                return tree.get_file(file_id).readlines()
 
645
                return tree.get_file(file_id, path).readlines()
637
646
            else:
638
647
                return []
639
648
        try:
640
 
            from_text = _get_text(self.old_tree, from_file_id)
641
 
            to_text = _get_text(self.new_tree, to_file_id)
 
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)
642
651
            self.text_differ(from_label, from_text, to_label, to_text,
643
652
                             self.to_file)
644
653
        except errors.BinaryFile:
731
740
        return old_disk_path, new_disk_path
732
741
 
733
742
    def finish(self):
734
 
        osutils.rmtree(self._root)
 
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))
735
749
 
736
750
    def diff(self, file_id, old_path, new_path, old_kind, new_kind):
737
751
        if (old_kind, new_kind) != ('file', 'file'):
882
896
                self.to_file.write("=== modified %s '%s'%s\n" % (kind[0],
883
897
                                   newpath_encoded, prop_str))
884
898
            if changed_content:
885
 
                self.diff(file_id, oldpath, newpath)
 
899
                self._diff(file_id, oldpath, newpath, kind[0], kind[1])
886
900
                has_changes = 1
887
901
            if renamed:
888
902
                has_changes = 1
903
917
            new_kind = self.new_tree.kind(file_id)
904
918
        except (errors.NoSuchId, errors.NoSuchFile):
905
919
            new_kind = None
906
 
 
 
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):
907
924
        result = DiffPath._diff_many(self.differs, file_id, old_path,
908
925
                                       new_path, old_kind, new_kind)
909
926
        if result is DiffPath.CANNOT_DIFF: