/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/merge.py

  • Committer: Jelmer Vernooij
  • Date: 2019-05-29 03:28:14 UTC
  • mfrom: (7303 work)
  • mto: This revision was merged to the branch mainline in revision 7305.
  • Revision ID: jelmer@jelmer.uk-20190529032814-fzqbrgf9647u9ptq
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
from .lazy_import import lazy_import
20
20
lazy_import(globals(), """
 
21
import patiencediff
 
22
 
21
23
from breezy import (
22
24
    branch as _mod_branch,
23
25
    cleanup,
24
26
    conflicts as _mod_conflicts,
25
27
    debug,
26
 
    generate_ids,
27
28
    graph as _mod_graph,
28
29
    merge3,
29
30
    osutils,
30
 
    patiencediff,
31
31
    revision as _mod_revision,
32
32
    textfile,
33
33
    trace,
38
38
    workingtree,
39
39
    )
40
40
from breezy.bzr import (
 
41
    generate_ids,
41
42
    versionedfile,
42
43
    )
43
44
from breezy.i18n import gettext
250
251
    @decorators.cachedproperty
251
252
    def base_lines(self):
252
253
        """The lines of the 'base' version of the file."""
253
 
        return self._merger.get_lines(self._merger.base_tree, self.base_path, self.file_id)
 
254
        return self._merger.get_lines(self._merger.base_tree, self.base_path)
254
255
 
255
256
    @decorators.cachedproperty
256
257
    def this_lines(self):
257
258
        """The lines of the 'this' version of the file."""
258
 
        return self._merger.get_lines(self._merger.this_tree, self.this_path, self.file_id)
 
259
        return self._merger.get_lines(self._merger.this_tree, self.this_path)
259
260
 
260
261
    @decorators.cachedproperty
261
262
    def other_lines(self):
262
263
        """The lines of the 'other' version of the file."""
263
 
        return self._merger.get_lines(self._merger.other_tree, self.other_path, self.file_id)
 
264
        return self._merger.get_lines(self._merger.other_tree, self.other_path)
264
265
 
265
266
 
266
267
class Merger(object):
1080
1081
        self.working_tree.set_merge_modified(modified_hashes)
1081
1082
 
1082
1083
    @staticmethod
1083
 
    def parent(entry, file_id):
 
1084
    def parent(entry):
1084
1085
        """Determine the parent for a file_id (used as a key method)"""
1085
1086
        if entry is None:
1086
1087
            return None
1087
1088
        return entry.parent_id
1088
1089
 
1089
1090
    @staticmethod
1090
 
    def name(entry, file_id):
 
1091
    def name(entry):
1091
1092
        """Determine the name for a file_id (used as a key method)"""
1092
1093
        if entry is None:
1093
1094
            return None
1094
1095
        return entry.name
1095
1096
 
1096
1097
    @staticmethod
1097
 
    def contents_sha1(tree, path, file_id=None):
 
1098
    def contents_sha1(tree, path):
1098
1099
        """Determine the sha1 of the file contents (used as a key method)."""
1099
1100
        try:
1100
 
            return tree.get_file_sha1(path, file_id)
 
1101
            return tree.get_file_sha1(path)
1101
1102
        except errors.NoSuchFile:
1102
1103
            return None
1103
1104
 
1104
1105
    @staticmethod
1105
 
    def executable(tree, path, file_id=None):
 
1106
    def executable(tree, path):
1106
1107
        """Determine the executability of a file-id (used as a key method)."""
1107
1108
        try:
1108
 
            if tree.kind(path, file_id) != "file":
 
1109
            if tree.kind(path) != "file":
1109
1110
                return False
1110
1111
        except errors.NoSuchFile:
1111
1112
            return None
1112
1113
        return tree.is_executable(path)
1113
1114
 
1114
1115
    @staticmethod
1115
 
    def kind(tree, path, file_id=None):
 
1116
    def kind(tree, path):
1116
1117
        """Determine the kind of a file-id (used as a key method)."""
1117
1118
        try:
1118
 
            return tree.kind(path, file_id)
 
1119
            return tree.kind(path)
1119
1120
        except errors.NoSuchFile:
1120
1121
            return None
1121
1122
 
1400
1401
        else:
1401
1402
            return 'not_applicable', None
1402
1403
 
1403
 
    def get_lines(self, tree, path, file_id=None):
 
1404
    def get_lines(self, tree, path):
1404
1405
        """Return the lines in a file, or an empty list."""
1405
1406
        if path is None:
1406
1407
            return []
1418
1419
        # it's possible that we got here with base as a different type.
1419
1420
        # if so, we just want two-way text conflicts.
1420
1421
        base_path, other_path, this_path = paths
1421
 
        base_lines = self.get_lines(self.base_tree, base_path, file_id)
1422
 
        other_lines = self.get_lines(self.other_tree, other_path, file_id)
1423
 
        this_lines = self.get_lines(self.this_tree, this_path, file_id)
 
1422
        base_lines = self.get_lines(self.base_tree, base_path)
 
1423
        other_lines = self.get_lines(self.other_tree, other_path)
 
1424
        this_lines = self.get_lines(self.this_tree, this_path)
1424
1425
        m3 = merge3.Merge3(base_lines, this_lines, other_lines,
1425
1426
                           is_cherrypick=self.cherrypick)
1426
1427
        start_marker = b"!START OF MERGE CONFLICT!" + b"I HOPE THIS IS UNIQUE"
1703
1704
 
1704
1705
    requires_file_merge_plan = False
1705
1706
 
1706
 
    def dump_file(self, temp_dir, name, tree, path, file_id=None):
 
1707
    def dump_file(self, temp_dir, name, tree, path):
1707
1708
        out_path = osutils.pathjoin(temp_dir, name)
1708
1709
        with open(out_path, "wb") as out_file:
1709
1710
            in_file = tree.get_file(path)
1722
1723
        try:
1723
1724
            new_file = osutils.pathjoin(temp_dir, "new")
1724
1725
            this = self.dump_file(
1725
 
                temp_dir, "this", self.this_tree, this_path, file_id)
 
1726
                temp_dir, "this", self.this_tree, this_path)
1726
1727
            base = self.dump_file(
1727
 
                temp_dir, "base", self.base_tree, base_path, file_id)
 
1728
                temp_dir, "base", self.base_tree, base_path)
1728
1729
            other = self.dump_file(
1729
 
                temp_dir, "other", self.other_tree, other_path, file_id)
 
1730
                temp_dir, "other", self.other_tree, other_path)
1730
1731
            status = breezy.patch.diff3(new_file, this, base, other)
1731
1732
            if status not in (0, 1):
1732
1733
                raise errors.BzrError("Unhandled diff3 exit code")