23
23
import bzrlib.osutils
24
24
import bzrlib.revision
25
25
from bzrlib.merge_core import merge_flex, ApplyMerge3, BackupBeforeChange
26
from bzrlib.merge_core import WeaveMerge
26
27
from bzrlib.changeset import generate_changeset, ExceptionConflictHandler
27
28
from bzrlib.changeset import Inventory, Diff3Merge, ReplaceContents
28
29
from bzrlib.branch import Branch
29
30
from bzrlib.errors import BzrCommandError, UnrelatedBranches, NoCommonAncestor
30
from bzrlib.errors import NoCommits
31
from bzrlib.errors import NoCommits, WorkingTreeNotRevision
31
32
from bzrlib.delta import compare_trees
32
33
from bzrlib.trace import mutter, warning, note
33
34
from bzrlib.fetch import greedy_fetch, fetch
319
321
self.show_base = False
320
322
self.conflict_handler = MergeConflictHandler(self.this_tree, base_tree,
325
def revision_tree(self, revision_id):
326
return self.this_branch.revision_tree(revision_id)
328
def ensure_revision_trees(self):
329
if self.this_revision_tree is None:
330
if self.this_rev_id is None:
332
if self.this_rev_id is None:
333
raise WorkingTreeNotRevision(self.this_tree)
334
self.this_revision_tree = self.this_branch.revision_tree(
337
if self.other_rev_id is None:
338
other_basis_tree = self.revision_tree(self.other_basis)
339
changes = compare_trees(self.other_tree, other_basis_tree)
340
if changes.has_changed():
341
raise WorkingTreeNotRevision(self.this_tree)
342
other_rev_id = other_basis
343
self.other_tree = other_basis_tree
346
def file_revisions(self, file_id):
347
self.ensure_revision_trees()
348
def get_id(tree, file_id):
349
revision_id = tree.inventory[file_id].revision
350
assert revision_id is not None
352
trees = (self.this_revision_tree, self.other_tree)
353
return [get_id(tree, file_id) for tree in trees]
323
356
def merge_factory(self, file_id, base, other):
324
if self.show_base is True:
325
contents_change = self.merge_type(file_id, base, other,
357
if self.merge_type.history_based:
358
t_revid, o_revid = self.file_revisions(file_id)
359
weave = self.this_revision_tree.get_weave(file_id)
360
contents_change = self.merge_type(weave, t_revid, o_revid)
328
contents_change = self.merge_type(file_id, base, other)
362
if self.show_base is True:
363
contents_change = self.merge_type(file_id, base, other,
366
contents_change = self.merge_type(file_id, base, other)
329
367
if self.backup_files:
330
368
contents_change = BackupBeforeChange(contents_change)
331
369
return contents_change
500
538
return new_inventory_list
502
540
merge_types = { "merge3": (ApplyMerge3, "Native diff3-style merge"),
503
"diff3": (Diff3Merge, "Merge using external diff3")
541
"diff3": (Diff3Merge, "Merge using external diff3"),
542
'weave': (WeaveMerge, "Weave-based merge")