/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 breezy/diff.py

  • Committer: Jelmer Vernooij
  • Date: 2020-03-22 20:02:36 UTC
  • mto: (7490.7.7 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200322200236-fsbl91ktcn6fcbdd
Fix tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
import contextlib
 
17
from __future__ import absolute_import
 
18
 
18
19
import difflib
19
20
import os
20
21
import re
28
29
import tempfile
29
30
 
30
31
from breezy import (
 
32
    cleanup,
31
33
    controldir,
32
34
    osutils,
33
35
    textfile,
45
47
from .registry import (
46
48
    Registry,
47
49
    )
 
50
from .sixish import text_type
48
51
from .trace import mutter, note, warning
49
52
from .tree import FileTimestampUnavailable
50
53
 
516
519
        context = DEFAULT_CONTEXT_AMOUNT
517
520
    if format_cls is None:
518
521
        format_cls = DiffTree
519
 
    with contextlib.ExitStack() as exit_stack:
 
522
    with cleanup.ExitStack() as exit_stack:
520
523
        exit_stack.enter_context(old_tree.lock_read())
521
524
        if extra_trees is not None:
522
525
            for tree in extra_trees:
731
734
            new_date = self.EPOCH_DATE
732
735
        else:
733
736
            return self.CANNOT_DIFF
734
 
        from_label = '%s%s\t%s' % (
735
 
            self.old_label, old_path or new_path, old_date)
736
 
        to_label = '%s%s\t%s' % (
737
 
            self.new_label, new_path or old_path, new_date)
 
737
        from_label = '%s%s\t%s' % (self.old_label, old_path,
 
738
                                   old_date)
 
739
        to_label = '%s%s\t%s' % (self.new_label, new_path,
 
740
                                 new_date)
738
741
        return self.diff_text(old_path, new_path, from_label, to_label)
739
742
 
740
743
    def diff_text(self, from_path, to_path, from_label, to_label):
762
765
        except errors.BinaryFile:
763
766
            self.to_file.write(
764
767
                ("Binary files %s%s and %s%s differ\n" %
765
 
                 (self.old_label, from_path or to_path,
766
 
                  self.new_label, to_path or from_path)
767
 
                 ).encode(self.path_encoding, 'replace'))
 
768
                 (self.old_label, from_path, self.new_label, to_path)).encode(self.path_encoding, 'replace'))
768
769
        return self.CHANGED
769
770
 
770
771
 
801
802
        if sys.platform == 'win32':  # Popen doesn't accept unicode on win32
802
803
            command_encoded = []
803
804
            for c in command:
804
 
                if isinstance(c, str):
 
805
                if isinstance(c, text_type):
805
806
                    command_encoded.append(c.encode('mbcs'))
806
807
                else:
807
808
                    command_encoded.append(c)
1054
1055
                    'supported on this filesystem.' % (change.path[0],))
1055
1056
                continue
1056
1057
            oldpath, newpath = change.path
1057
 
            oldpath_encoded = get_encoded_path(oldpath)
1058
 
            newpath_encoded = get_encoded_path(newpath)
 
1058
            oldpath_encoded = get_encoded_path(change.path[0])
 
1059
            newpath_encoded = get_encoded_path(change.path[1])
1059
1060
            old_present = (change.kind[0] is not None and change.versioned[0])
1060
1061
            new_present = (change.kind[1] is not None and change.versioned[1])
1061
1062
            executable = change.executable
1075
1076
            if (old_present, new_present) == (True, False):
1076
1077
                self.to_file.write(b"=== removed %s '%s'\n" %
1077
1078
                                   (kind[0].encode('ascii'), oldpath_encoded))
 
1079
                newpath = oldpath
1078
1080
            elif (old_present, new_present) == (False, True):
1079
1081
                self.to_file.write(b"=== added %s '%s'\n" %
1080
1082
                                   (kind[1].encode('ascii'), newpath_encoded))
 
1083
                oldpath = newpath
1081
1084
            elif renamed:
1082
1085
                self.to_file.write(b"=== renamed %s '%s' => '%s'%s\n" %
1083
1086
                                   (kind[0].encode('ascii'), oldpath_encoded, newpath_encoded, prop_str))