~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Martin Pool
  • Date: 2010-04-21 11:27:04 UTC
  • mto: This revision was merged to the branch mainline in revision 5189.
  • Revision ID: mbp@canonical.com-20100421112704-zijso22b6pdevrxy
Simplify various code to use user_url

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
 
797
798
                target.close()
798
799
        finally:
799
800
            source.close()
 
801
        if not allow_write:
 
802
            osutils.make_readonly(full_path)
800
803
        try:
801
804
            mtime = tree.get_file_mtime(file_id)
802
805
        except errors.FileTimestampUnavailable:
803
 
            pass
804
 
        else:
805
 
            os.utime(full_path, (mtime, mtime))
806
 
        if not allow_write:
807
 
            osutils.make_readonly(full_path)
 
806
            mtime = 0
 
807
        os.utime(full_path, (mtime, mtime))
808
808
        return full_path
809
809
 
810
810
    def _prepare_files(self, file_id, old_path, new_path, force_temp=False,
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, external_diff_options)]
 
918
            extra_factories = [DiffFromTool.make_from_diff_tree(using)]
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, path_encoding=None):
924
 
                """:param path_encoding: not used but required
925
 
                        to match the signature of internal_diff.
926
 
                """
 
923
            def diff_file(olab, olines, nlab, nlines, to_file):
927
924
                external_diff(olab, olines, nlab, nlines, to_file, opts)
928
925
        else:
929
926
            diff_file = internal_diff