~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/conflicts.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-12-03 08:31:44 UTC
  • mfrom: (4597.14.11 638451-malformed)
  • Revision ID: pqm@pqm.ubuntu.com-20101203083144-b2qfwgifwp1wq6zv
(vila) Implement resolve --take-this and --take-other for text conflicts.
 (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
626
626
    def associated_filenames(self):
627
627
        return [self.path + suffix for suffix in CONFLICT_SUFFIXES]
628
628
 
 
629
    def _resolve(self, tt, winner_suffix):
 
630
        """Resolve the conflict by copying one of .THIS or .OTHER into file.
 
631
 
 
632
        :param tt: The TreeTransform where the conflict is resolved.
 
633
        :param winner_suffix: Either 'THIS' or 'OTHER'
 
634
 
 
635
        The resolution is symmetric, when taking THIS, item.THIS is renamed
 
636
        into item and vice-versa. This takes one of the files as a whole
 
637
        ignoring every difference that could have been merged cleanly.
 
638
        """
 
639
        # To avoid useless copies, we switch item and item.winner_suffix, only
 
640
        # item will exist after the conflict has been resolved anyway.
 
641
        item_tid = tt.trans_id_file_id(self.file_id)
 
642
        item_parent_tid = tt.get_tree_parent(item_tid)
 
643
        winner_path = self.path + '.' + winner_suffix
 
644
        winner_tid = tt.trans_id_tree_path(winner_path)
 
645
        winner_parent_tid = tt.get_tree_parent(winner_tid)
 
646
        # Switch the paths to preserve the content
 
647
        tt.adjust_path(self.path, winner_parent_tid, winner_tid)
 
648
        tt.adjust_path(winner_path, item_parent_tid, item_tid)
 
649
        # Associate the file_id to the right content
 
650
        tt.unversion_file(item_tid)
 
651
        tt.version_file(self.file_id, winner_tid)
 
652
        tt.apply()
 
653
 
 
654
    def action_take_this(self, tree):
 
655
        self._resolve_with_cleanups(tree, 'THIS')
 
656
 
 
657
    def action_take_other(self, tree):
 
658
        self._resolve_with_cleanups(tree, 'OTHER')
 
659
 
629
660
 
630
661
class HandledConflict(Conflict):
631
662
    """A path problem that has been provisionally resolved.