/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: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

Show diffs side-by-side

added added

removed removed

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