~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Martin von Gagern
  • Date: 2010-04-20 08:47:38 UTC
  • mfrom: (5167 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5195.
  • Revision ID: martin.vgagern@gmx.net-20100420084738-ygymnqmdllzrhpfn
merge trunk

Show diffs side-by-side

added added

removed removed

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