/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: Vincent Ladeuil
  • Date: 2010-04-23 08:51:52 UTC
  • mfrom: (5131.2.6 support_OO_flag)
  • mto: This revision was merged to the branch mainline in revision 5179.
  • Revision ID: v.ladeuil+lp@free.fr-20100423085152-uoewc1vnkwqhw0pj
Manually assign docstrings to command objects, so that they work with python -OO

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