~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-04-05 14:47:26 UTC
  • mfrom: (5752.2.11 2.4-windows-lfstat)
  • Revision ID: pqm@pqm.ubuntu.com-20110405144726-zi3lj2kwvjml4kx5
(jameinel) Add osutils.lstat/fstat so that even on Windows lstat(fname) ==
 fstat(open(fname).fileno()) (John A Meinel)

Show diffs side-by-side

added added

removed removed

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