/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: Andrew Bennetts
  • Date: 2011-05-19 09:32:38 UTC
  • mto: This revision was merged to the branch mainline in revision 5896.
  • Revision ID: andrew.bennetts@canonical.com-20110519093238-nwmz5fkehlu37hag
Move docstring formatting fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd.
 
1
# Copyright (C) 2005-2011 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
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
468
463
    """Show in text form the changes from one tree to another.
469
464
 
470
465
    :param to_file: The output stream.
471
 
    :param specific_files:Include only changes to these files - None for all
 
466
    :param specific_files: Include only changes to these files - None for all
472
467
        changes.
473
468
    :param external_diff_options: If set, use an external GNU diff and pass 
474
469
        these options.
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
 
904
902
        """Factory for producing a DiffTree.
905
903
 
906
904
        Designed to accept options used by show_diff_trees.
 
905
 
907
906
        :param old_tree: The tree to show as old in the comparison
908
907
        :param new_tree: The tree to show as new in the comparison
909
908
        :param to_file: File to write comparisons to
915
914
        :param using: Commandline to use to invoke an external diff tool
916
915
        """
917
916
        if using is not None:
918
 
            extra_factories = [DiffFromTool.make_from_diff_tree(using)]
 
917
            extra_factories = [DiffFromTool.make_from_diff_tree(using, external_diff_options)]
919
918
        else:
920
919
            extra_factories = []
921
920
        if external_diff_options:
922
921
            opts = external_diff_options.split()
923
 
            def diff_file(olab, olines, nlab, nlines, to_file):
 
922
            def diff_file(olab, olines, nlab, nlines, to_file, path_encoding=None):
 
923
                """:param path_encoding: not used but required
 
924
                        to match the signature of internal_diff.
 
925
                """
924
926
                external_diff(olab, olines, nlab, nlines, to_file, opts)
925
927
        else:
926
928
            diff_file = internal_diff