436
436
def action_take_other(self, tree):
437
437
raise NotImplementedError(self.action_take_other)
439
def _resolve_with_cleanups(self, tree, *args, **kwargs):
440
tt = transform.TreeTransform(tree)
441
op = cleanup.OperationWithCleanups(self._resolve)
442
op.add_cleanup(tt.finalize)
443
op.run_simple(tt, *args, **kwargs)
440
446
class PathConflict(Conflict):
441
447
"""A conflict was encountered merging file paths"""
460
466
# No additional files have been generated here
469
def _resolve(self, tt, file_id, path, winner):
470
"""Resolve the conflict.
472
:param tt: The TreeTransform where the conflict is resolved.
473
:param file_id: The retained file id.
474
:param path: The retained path.
475
:param winner: 'this' or 'other' indicates which side is the winner.
477
path_to_create = None
479
if self.path == '<deleted>':
480
return # Nothing to do
481
if self.conflict_path == '<deleted>':
482
path_to_create = self.path
483
revid = tt._tree.get_parent_ids()[0]
484
elif winner == 'other':
485
if self.conflict_path == '<deleted>':
486
return # Nothing to do
487
if self.path == '<deleted>':
488
path_to_create = self.conflict_path
489
# FIXME: If there are more than two parents we may need to
490
# iterate. Taking the last parent is the safer bet in the mean
491
# time. -- vila 20100309
492
revid = tt._tree.get_parent_ids()[-1]
495
raise AssertionError('bad winner: %r' % (winner,))
496
if path_to_create is not None:
497
tid = tt.trans_id_tree_path(path_to_create)
498
transform.create_from_tree(
499
tt, tt.trans_id_tree_path(path_to_create),
500
self._revision_tree(tt._tree, revid), file_id)
501
tt.version_file(file_id, tid)
503
# Adjust the path for the retained file id
504
tid = tt.trans_id_file_id(file_id)
505
parent_tid = tt.get_tree_parent(tid)
506
tt.adjust_path(path, parent_tid, tid)
509
def _revision_tree(self, tree, revid):
510
return tree.branch.repository.revision_tree(revid)
512
def _infer_file_id(self, tree):
513
# Prior to bug #531967, file_id wasn't always set, there may still be
514
# conflict files in the wild so we need to cope with them
515
# Establish which path we should use to find back the file-id
517
for p in (self.path, self.conflict_path):
519
# special hard-coded path
522
possible_paths.append(p)
523
# Search the file-id in the parents with any path available
525
for revid in tree.get_parent_ids():
526
revtree = self._revision_tree(tree, revid)
527
for p in possible_paths:
528
file_id = revtree.path2id(p)
529
if file_id is not None:
530
return revtree, file_id
463
533
def action_take_this(self, tree):
464
tree.rename_one(self.conflict_path, self.path)
534
if self.file_id is not None:
535
self._resolve_with_cleanups(tree, self.file_id, self.path,
538
# Prior to bug #531967 we need to find back the file_id and restore
539
# the content from there
540
revtree, file_id = self._infer_file_id(tree)
541
tree.revert([revtree.id2path(file_id)],
542
old_tree=revtree, backups=False)
466
544
def action_take_other(self, tree):
467
# just acccept bzr proposal
545
if self.file_id is not None:
546
self._resolve_with_cleanups(tree, self.file_id,
550
# Prior to bug #531967 we need to find back the file_id and restore
551
# the content from there
552
revtree, file_id = self._infer_file_id(tree)
553
tree.revert([revtree.id2path(file_id)],
554
old_tree=revtree, backups=False)
471
557
class ContentsConflict(PathConflict):
506
592
tt.adjust_path(self.path, parent_tid, this_tid)
509
def _take_it_with_cleanups(self, tree, suffix_to_remove):
510
tt = transform.TreeTransform(tree)
511
op = cleanup.OperationWithCleanups(self._take_it)
512
op.add_cleanup(tt.finalize)
513
op.run_simple(tt, suffix_to_remove)
515
595
def action_take_this(self, tree):
516
self._take_it_with_cleanups(tree, 'OTHER')
596
self._resolve_with_cleanups(tree, 'OTHER')
518
598
def action_take_other(self, tree):
519
self._take_it_with_cleanups(tree, 'THIS')
599
self._resolve_with_cleanups(tree, 'THIS')
522
602
# FIXME: TextConflict is about a single file-id, there never is a conflict_path