19
19
from .lazy_import import lazy_import
20
20
lazy_import(globals(), """
21
23
from breezy import (
22
24
branch as _mod_branch,
24
26
conflicts as _mod_conflicts,
27
28
graph as _mod_graph,
31
31
revision as _mod_revision,
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)
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)
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)
266
267
class Merger(object):
1080
1081
self.working_tree.set_merge_modified(modified_hashes)
1083
def parent(entry, file_id):
1084
1085
"""Determine the parent for a file_id (used as a key method)"""
1085
1086
if entry is None:
1087
1088
return entry.parent_id
1090
def name(entry, file_id):
1091
1092
"""Determine the name for a file_id (used as a key method)"""
1092
1093
if entry is None:
1094
1095
return entry.name
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)."""
1100
return tree.get_file_sha1(path, file_id)
1101
return tree.get_file_sha1(path)
1101
1102
except errors.NoSuchFile:
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)."""
1108
if tree.kind(path, file_id) != "file":
1109
if tree.kind(path) != "file":
1110
1111
except errors.NoSuchFile:
1112
1113
return tree.is_executable(path)
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)."""
1118
return tree.kind(path, file_id)
1119
return tree.kind(path)
1119
1120
except errors.NoSuchFile:
1401
1402
return 'not_applicable', None
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:
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"
1704
1705
requires_file_merge_plan = False
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)
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")