~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Martin Pool
  • Date: 2010-09-13 09:00:03 UTC
  • mto: This revision was merged to the branch mainline in revision 5422.
  • Revision ID: mbp@sourcefrog.net-20100913090003-5mvnc50tdwppqxtl
Add passing test for multi-line comment

Show diffs side-by-side

added added

removed removed

Lines of Context:
99
99
    if sequence_matcher is None:
100
100
        sequence_matcher = patiencediff.PatienceSequenceMatcher
101
101
    ud = patiencediff.unified_diff(oldlines, newlines,
102
 
                      fromfile=old_filename.encode(path_encoding),
103
 
                      tofile=new_filename.encode(path_encoding),
 
102
                      fromfile=old_filename.encode(path_encoding, 'replace'),
 
103
                      tofile=new_filename.encode(path_encoding, 'replace'),
104
104
                      sequencematcher=sequence_matcher)
105
105
 
106
106
    ud = list(ud)
420
420
 
421
421
    # Get the specific files (all files is None, no files is [])
422
422
    if make_paths_wt_relative and working_tree is not None:
423
 
        try:
424
 
            from bzrlib.builtins import safe_relpath_files
425
 
            other_paths = safe_relpath_files(working_tree, other_paths,
 
423
        other_paths = working_tree.safe_relpath_files(
 
424
            other_paths,
426
425
            apply_view=apply_view)
427
 
        except errors.FileInWrongBranch:
428
 
            raise errors.BzrCommandError("Files are in different branches")
429
426
    specific_files.extend(other_paths)
430
427
    if len(specific_files) == 0:
431
428
        specific_files = None
706
703
        """
707
704
        def _get_text(tree, file_id, path):
708
705
            if file_id is not None:
709
 
                return tree.get_file(file_id, path).readlines()
 
706
                return tree.get_file_lines(file_id, path)
710
707
            else:
711
708
                return []
712
709
        try:
713
710
            from_text = _get_text(self.old_tree, from_file_id, from_path)
714
711
            to_text = _get_text(self.new_tree, to_file_id, to_path)
715
712
            self.text_differ(from_label, from_text, to_label, to_text,
716
 
                             self.to_file)
 
713
                             self.to_file, path_encoding=self.path_encoding)
717
714
        except errors.BinaryFile:
718
715
            self.to_file.write(
719
716
                  ("Binary files %s and %s differ\n" %
720
 
                  (from_label, to_label)).encode(self.path_encoding))
 
717
                  (from_label, to_label)).encode(self.path_encoding,'replace'))
721
718
        return self.CHANGED
722
719
 
723
720
 
739
736
                     path_encoding)
740
737
 
741
738
    @classmethod
742
 
    def make_from_diff_tree(klass, command_string):
 
739
    def make_from_diff_tree(klass, command_string, external_diff_options=None):
743
740
        def from_diff_tree(diff_tree):
744
 
            return klass.from_string(command_string, diff_tree.old_tree,
 
741
            full_command_string = [command_string]
 
742
            if external_diff_options is not None:
 
743
                full_command_string += ' ' + external_diff_options
 
744
            return klass.from_string(full_command_string, diff_tree.old_tree,
745
745
                                     diff_tree.new_tree, diff_tree.to_file)
746
746
        return from_diff_tree
747
747
 
915
915
        :param using: Commandline to use to invoke an external diff tool
916
916
        """
917
917
        if using is not None:
918
 
            extra_factories = [DiffFromTool.make_from_diff_tree(using)]
 
918
            extra_factories = [DiffFromTool.make_from_diff_tree(using, external_diff_options)]
919
919
        else:
920
920
            extra_factories = []
921
921
        if external_diff_options:
922
922
            opts = external_diff_options.split()
923
 
            def diff_file(olab, olines, nlab, nlines, to_file):
 
923
            def diff_file(olab, olines, nlab, nlines, to_file, path_encoding=None):
 
924
                """:param path_encoding: not used but required
 
925
                        to match the signature of internal_diff.
 
926
                """
924
927
                external_diff(olab, olines, nlab, nlines, to_file, opts)
925
928
        else:
926
929
            diff_file = internal_diff