/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-07-28 02:47:10 UTC
  • mfrom: (7519.1.1 merge-3.1)
  • Revision ID: breezy.the.bot@gmail.com-20200728024710-a2ylds219f1lsl62
Merge lp:brz/3.1.

Merged from https://code.launchpad.net/~jelmer/brz/merge-3.1/+merge/388173

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