81
81
resolve_action_registry.register(
82
82
'done', 'done', 'Marks the conflict as resolved' )
83
83
resolve_action_registry.register(
84
'take-this', 'take_this',
84
'keep-mine', 'keep_mine',
85
85
'Resolve the conflict preserving the version in the working tree' )
86
86
resolve_action_registry.register(
87
'take-other', 'take_other',
87
'take-theirs', 'take_theirs',
88
88
'Resolve the conflict taking the merged version into account' )
89
89
resolve_action_registry.default_key = 'done'
408
408
:param tree: The tree passed as a parameter to the method.
410
meth = getattr(self, 'action_%s' % action, None)
410
meth = getattr(self, action, None)
412
412
raise NotImplementedError(self.__class__.__name__ + '.' + action)
415
def associated_filenames(self):
416
"""The names of the files generated to help resolve the conflict."""
417
raise NotImplementedError(self.associated_filenames)
419
415
def cleanup(self, tree):
420
for fname in self.associated_filenames():
422
osutils.delete_any(tree.abspath(fname))
424
if e.errno != errno.ENOENT:
416
raise NotImplementedError(self.cleanup)
427
def action_done(self, tree):
418
def done(self, tree):
428
419
"""Mark the conflict as solved once it has been handled."""
429
420
# This method does nothing but simplifies the design of upper levels.
432
def action_take_this(self, tree):
433
raise NotImplementedError(self.action_take_this)
435
def action_take_other(self, tree):
436
raise NotImplementedError(self.action_take_other)
438
def _resolve_with_cleanups(self, tree, *args, **kwargs):
439
tt = transform.TreeTransform(tree)
440
op = cleanup.OperationWithCleanups(self._resolve)
441
op.add_cleanup(tt.finalize)
442
op.run_simple(tt, *args, **kwargs)
423
def keep_mine(self, tree):
424
raise NotImplementedError(self.keep_mine)
426
def take_theirs(self, tree):
427
raise NotImplementedError(self.take_theirs)
445
430
class PathConflict(Conflict):
461
446
s.add('conflict_path', self.conflict_path)
464
def associated_filenames(self):
449
def cleanup(self, tree):
465
450
# No additional files have been generated here
468
def _resolve(self, tt, file_id, path, winner):
469
"""Resolve the conflict.
471
:param tt: The TreeTransform where the conflict is resolved.
472
:param file_id: The retained file id.
473
:param path: The retained path.
474
:param winner: 'this' or 'other' indicates which side is the winner.
476
path_to_create = None
478
if self.path == '<deleted>':
479
return # Nothing to do
480
if self.conflict_path == '<deleted>':
481
path_to_create = self.path
482
revid = tt._tree.get_parent_ids()[0]
483
elif winner == 'other':
484
if self.conflict_path == '<deleted>':
485
return # Nothing to do
486
if self.path == '<deleted>':
487
path_to_create = self.conflict_path
488
# FIXME: If there are more than two parents we may need to
489
# iterate. Taking the last parent is the safer bet in the mean
490
# time. -- vila 20100309
491
revid = tt._tree.get_parent_ids()[-1]
494
raise AssertionError('bad winner: %r' % (winner,))
495
if path_to_create is not None:
496
tid = tt.trans_id_tree_path(path_to_create)
497
transform.create_from_tree(
498
tt, tt.trans_id_tree_path(path_to_create),
499
self._revision_tree(tt._tree, revid), file_id)
500
tt.version_file(file_id, tid)
502
# Adjust the path for the retained file id
503
tid = tt.trans_id_file_id(file_id)
504
parent_tid = tt.get_tree_parent(tid)
505
tt.adjust_path(path, parent_tid, tid)
508
def _revision_tree(self, tree, revid):
509
return tree.branch.repository.revision_tree(revid)
511
def _infer_file_id(self, tree):
512
# Prior to bug #531967, file_id wasn't always set, there may still be
513
# conflict files in the wild so we need to cope with them
514
# Establish which path we should use to find back the file-id
516
for p in (self.path, self.conflict_path):
518
# special hard-coded path
521
possible_paths.append(p)
522
# Search the file-id in the parents with any path available
524
for revid in tree.get_parent_ids():
525
revtree = self._revision_tree(tree, revid)
526
for p in possible_paths:
527
file_id = revtree.path2id(p)
528
if file_id is not None:
529
return revtree, file_id
532
def action_take_this(self, tree):
533
if self.file_id is not None:
534
self._resolve_with_cleanups(tree, self.file_id, self.path,
537
# Prior to bug #531967 we need to find back the file_id and restore
538
# the content from there
539
revtree, file_id = self._infer_file_id(tree)
540
tree.revert([revtree.id2path(file_id)],
541
old_tree=revtree, backups=False)
543
def action_take_other(self, tree):
544
if self.file_id is not None:
545
self._resolve_with_cleanups(tree, self.file_id,
549
# Prior to bug #531967 we need to find back the file_id and restore
550
# the content from there
551
revtree, file_id = self._infer_file_id(tree)
552
tree.revert([revtree.id2path(file_id)],
553
old_tree=revtree, backups=False)
453
def keep_mine(self, tree):
454
tree.rename_one(self.conflict_path, self.path)
456
def take_theirs(self, tree):
457
# just acccept bzr proposal
556
461
class ContentsConflict(PathConflict):
557
"""The files are of different types (or both binary), or not present"""
462
"""The files are of different types, or not present"""
563
468
format = 'Contents conflict in %(path)s'
565
def associated_filenames(self):
566
return [self.path + suffix for suffix in ('.BASE', '.OTHER')]
568
def _resolve(self, tt, suffix_to_remove):
569
"""Resolve the conflict.
571
:param tt: The TreeTransform where the conflict is resolved.
572
:param suffix_to_remove: Either 'THIS' or 'OTHER'
574
The resolution is symmetric, when taking THIS, OTHER is deleted and
575
item.THIS is renamed into item and vice-versa.
578
# Delete 'item.THIS' or 'item.OTHER' depending on
581
tt.trans_id_tree_path(self.path + '.' + suffix_to_remove))
582
except errors.NoSuchFile:
583
# There are valid cases where 'item.suffix_to_remove' either
584
# never existed or was already deleted (including the case
585
# where the user deleted it)
587
# Rename 'item.suffix_to_remove' (note that if
588
# 'item.suffix_to_remove' has been deleted, this is a no-op)
589
this_tid = tt.trans_id_file_id(self.file_id)
590
parent_tid = tt.get_tree_parent(this_tid)
591
tt.adjust_path(self.path, parent_tid, this_tid)
594
def action_take_this(self, tree):
595
self._resolve_with_cleanups(tree, 'OTHER')
597
def action_take_other(self, tree):
598
self._resolve_with_cleanups(tree, 'THIS')
470
def cleanup(self, tree):
471
for suffix in ('.BASE', '.OTHER'):
473
osutils.delete_any(tree.abspath(self.path + suffix))
475
if e.errno != errno.ENOENT:
478
# FIXME: I smell something weird here and it seems we should be able to be
479
# more coherent with some other conflict ? bzr *did* a choice there but
480
# neither keep_mine nor take_theirs reflect that... -- vila 091224
481
def keep_mine(self, tree):
482
tree.remove([self.path + '.OTHER'], force=True, keep_files=False)
484
def take_theirs(self, tree):
485
tree.remove([self.path], force=True, keep_files=False)
601
489
# FIXME: TextConflict is about a single file-id, there never is a conflict_path
707
600
typestring = 'parent loop'
709
format = 'Conflict moving %(path)s into %(conflict_path)s. %(action)s.'
602
format = 'Conflict moving %(conflict_path)s into %(path)s. %(action)s.'
711
def action_take_this(self, tree):
604
def keep_mine(self, tree):
712
605
# just acccept bzr proposal
715
def action_take_other(self, tree):
608
def take_theirs(self, tree):
716
609
# FIXME: We shouldn't have to manipulate so many paths here (and there
717
610
# is probably a bug or two...)
718
611
base_path = osutils.basename(self.path)
802
695
format = "Conflict: %(path)s is not a directory, but has files in it."\
805
# FIXME: .OTHER should be used instead of .new when the conflict is created
807
def action_take_this(self, tree):
698
def keep_mine(self, tree):
808
699
# FIXME: we should preserve that path when the conflict is generated !
809
700
if self.path.endswith('.new'):
810
701
conflict_path = self.path[:-(len('.new'))]
811
702
tree.remove([self.path], force=True, keep_files=False)
812
703
tree.add(conflict_path)
814
raise NotImplementedError(self.action_take_this)
705
raise NotImplementedError(self.keep_mine)
816
def action_take_other(self, tree):
707
def take_theirs(self, tree):
817
708
# FIXME: we should preserve that path when the conflict is generated !
818
709
if self.path.endswith('.new'):
819
710
conflict_path = self.path[:-(len('.new'))]
820
711
tree.remove([conflict_path], force=True, keep_files=False)
821
712
tree.rename_one(self.path, conflict_path)
823
raise NotImplementedError(self.action_take_other)
714
raise NotImplementedError(self.take_theirs)