~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: Andrew Bennetts
  • Date: 2008-03-17 17:16:11 UTC
  • mfrom: (3290 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3756.
  • Revision ID: andrew.bennetts@canonical.com-20080317171611-o9wdrnf0m7qwo198
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
116
116
 
117
117
    def _get_base_is_other_ancestor(self):
118
118
        if self._base_is_other_ancestor is None:
119
 
            self.base_is_other_ancestor = self.revision_graph.is_ancestor(
 
119
            if self.other_basis is None:
 
120
                return True
 
121
            self._base_is_other_ancestor = self.revision_graph.is_ancestor(
120
122
                self.base_rev_id, self.other_basis)
121
123
        return self._base_is_other_ancestor
122
124
 
162
164
        return merger, verified
163
165
 
164
166
    @staticmethod
165
 
    def from_revision_ids(pb, this, other, base=None, other_branch=None,
 
167
    def from_revision_ids(pb, tree, other, base=None, other_branch=None,
166
168
                          base_branch=None, revision_graph=None):
167
169
        """Return a Merger for revision-ids.
168
170
 
171
173
        :param base: The revision-id to use as BASE.  If not specified, will
172
174
            be auto-selected.
173
175
        :param other_branch: A branch containing the other revision-id.  If
174
 
            not supplied, this.branch is used.
 
176
            not supplied, tree.branch is used.
175
177
        :param base_branch: A branch containing the base revision-id.  If
176
 
            not supplied, other_branch or this.branch will be used.
 
178
            not supplied, other_branch or tree.branch will be used.
 
179
        :param revision_graph: If you have a revision_graph precomputed, pass
 
180
            it in, otherwise it will be created for you.
177
181
        :param pb: A progress indicator
178
182
        """
179
 
        merger = Merger(this.branch, this_tree=this, pb=pb,
 
183
        merger = Merger(tree.branch, this_tree=tree, pb=pb,
180
184
                        revision_graph=revision_graph)
181
185
        if other_branch is None:
182
 
            other_branch = this.branch
 
186
            other_branch = tree.branch
183
187
        merger.set_other_revision(other, other_branch)
184
188
        if base is None:
185
189
            merger.find_base()
399
403
        if (not getattr(self.merge_type, 'supports_reverse_cherrypick', True)
400
404
            and not self.base_is_other_ancestor):
401
405
            raise errors.CannotReverseCherrypick()
402
 
        if self.merge_type.history_based:
 
406
        if self.merge_type.supports_cherrypick:
403
407
            kwargs['cherrypick'] = (not self.base_is_ancestor or
404
408
                                    not self.base_is_other_ancestor)
405
409
        return self.merge_type(pb=self._pb,
407
411
                               **kwargs)
408
412
 
409
413
    def do_merge(self):
410
 
        merge = self.make_merger()
411
414
        self.this_tree.lock_tree_write()
412
415
        if self.base_tree is not None:
413
416
            self.base_tree.lock_read()
414
417
        if self.other_tree is not None:
415
418
            self.other_tree.lock_read()
416
419
        try:
 
420
            merge = self.make_merger()
417
421
            merge.do_merge()
418
422
            if self.recurse == 'down':
419
423
                for path, file_id in self.this_tree.iter_references():
430
434
                    base_revision = self.base_tree.get_reference_revision(file_id)
431
435
                    sub_merge.base_tree = \
432
436
                        sub_tree.branch.repository.revision_tree(base_revision)
 
437
                    sub_merge.base_rev_id = base_revision
433
438
                    sub_merge.do_merge()
434
439
 
435
440
        finally:
453
458
    supports_reprocess = True
454
459
    supports_show_base = True
455
460
    history_based = False
 
461
    supports_cherrypick = True
456
462
    supports_reverse_cherrypick = True
457
463
    winner_idx = {"this": 2, "other": 1, "conflict": 1}
458
464
 
459
465
    def __init__(self, working_tree, this_tree, base_tree, other_tree, 
460
466
                 interesting_ids=None, reprocess=False, show_base=False,
461
467
                 pb=DummyProgress(), pp=None, change_reporter=None,
462
 
                 interesting_files=None, do_merge=True):
 
468
                 interesting_files=None, do_merge=True,
 
469
                 cherrypick=False):
463
470
        """Initialize the merger object and perform the merge.
464
471
 
465
472
        :param working_tree: The working tree to apply the merge to
497
504
        self.pb = pb
498
505
        self.pp = pp
499
506
        self.change_reporter = change_reporter
 
507
        self.cherrypick = cherrypick
500
508
        if self.pp is None:
501
509
            self.pp = ProgressPhase("Merge phase", 3, self.pb)
502
510
        if do_merge:
865
873
            base_lines = []
866
874
        other_lines = self.get_lines(self.other_tree, file_id)
867
875
        this_lines = self.get_lines(self.this_tree, file_id)
868
 
        m3 = Merge3(base_lines, this_lines, other_lines)
 
876
        m3 = Merge3(base_lines, this_lines, other_lines,
 
877
                    is_cherrypick=self.cherrypick)
869
878
        start_marker = "!START OF MERGE CONFLICT!" + "I HOPE THIS IS UNIQUE"
870
879
        if self.show_base is True:
871
880
            base_marker = '|' * 7
1040
1049
    supports_reverse_cherrypick = False
1041
1050
    history_based = True
1042
1051
 
1043
 
    def __init__(self, working_tree, this_tree, base_tree, other_tree, 
1044
 
                 interesting_ids=None, pb=DummyProgress(), pp=None,
1045
 
                 reprocess=False, change_reporter=None,
1046
 
                 interesting_files=None, cherrypick=False, do_merge=True):
1047
 
        self.cherrypick = cherrypick
1048
 
        super(WeaveMerger, self).__init__(working_tree, this_tree, 
1049
 
                                          base_tree, other_tree, 
1050
 
                                          interesting_files=interesting_files,
1051
 
                                          interesting_ids=interesting_ids, 
1052
 
                                          pb=pb, pp=pp, reprocess=reprocess,
1053
 
                                          change_reporter=change_reporter,
1054
 
                                          do_merge=do_merge)
1055
 
 
1056
1052
    def _merged_lines(self, file_id):
1057
1053
        """Generate the merged lines.
1058
1054
        There is no distinction between lines that are meant to contain <<<<<<<
1195
1191
    merger.reprocess = reprocess
1196
1192
    merger.other_rev_id = other_rev_id
1197
1193
    merger.other_basis = other_rev_id
 
1194
    get_revision_id = getattr(base_tree, 'get_revision_id', None)
 
1195
    if get_revision_id is None:
 
1196
        get_revision_id = base_tree.last_revision
 
1197
    merger.set_base_revision(get_revision_id(), this_branch)
1198
1198
    return merger.do_merge()
1199
1199
 
1200
1200
def get_merge_type_registry():