~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: Alexander Belchenko
  • Date: 2008-02-06 15:33:12 UTC
  • mto: This revision was merged to the branch mainline in revision 3231.
  • Revision ID: bialix@ukr.net-20080206153312-qycs7u05d7fjtwqq
Ian's review

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
 
            if self.other_basis is None:
120
 
                return True
121
 
            self._base_is_other_ancestor = self.revision_graph.is_ancestor(
 
119
            self.base_is_other_ancestor = self.revision_graph.is_ancestor(
122
120
                self.base_rev_id, self.other_basis)
123
121
        return self._base_is_other_ancestor
124
122
 
164
162
        return merger, verified
165
163
 
166
164
    @staticmethod
167
 
    def from_revision_ids(pb, tree, other, base=None, other_branch=None,
 
165
    def from_revision_ids(pb, this, other, base=None, other_branch=None,
168
166
                          base_branch=None, revision_graph=None):
169
167
        """Return a Merger for revision-ids.
170
168
 
173
171
        :param base: The revision-id to use as BASE.  If not specified, will
174
172
            be auto-selected.
175
173
        :param other_branch: A branch containing the other revision-id.  If
176
 
            not supplied, tree.branch is used.
 
174
            not supplied, this.branch is used.
177
175
        :param base_branch: A branch containing the base revision-id.  If
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.
 
176
            not supplied, other_branch or this.branch will be used.
181
177
        :param pb: A progress indicator
182
178
        """
183
 
        merger = Merger(tree.branch, this_tree=tree, pb=pb,
 
179
        merger = Merger(this.branch, this_tree=this, pb=pb,
184
180
                        revision_graph=revision_graph)
185
181
        if other_branch is None:
186
 
            other_branch = tree.branch
 
182
            other_branch = this.branch
187
183
        merger.set_other_revision(other, other_branch)
188
184
        if base is None:
189
185
            merger.find_base()
403
399
        if (not getattr(self.merge_type, 'supports_reverse_cherrypick', True)
404
400
            and not self.base_is_other_ancestor):
405
401
            raise errors.CannotReverseCherrypick()
406
 
        if self.merge_type.supports_cherrypick:
 
402
        if self.merge_type.history_based:
407
403
            kwargs['cherrypick'] = (not self.base_is_ancestor or
408
404
                                    not self.base_is_other_ancestor)
409
405
        return self.merge_type(pb=self._pb,
411
407
                               **kwargs)
412
408
 
413
409
    def do_merge(self):
 
410
        merge = self.make_merger()
414
411
        self.this_tree.lock_tree_write()
415
412
        if self.base_tree is not None:
416
413
            self.base_tree.lock_read()
417
414
        if self.other_tree is not None:
418
415
            self.other_tree.lock_read()
419
416
        try:
420
 
            merge = self.make_merger()
421
417
            merge.do_merge()
422
418
            if self.recurse == 'down':
423
419
                for path, file_id in self.this_tree.iter_references():
434
430
                    base_revision = self.base_tree.get_reference_revision(file_id)
435
431
                    sub_merge.base_tree = \
436
432
                        sub_tree.branch.repository.revision_tree(base_revision)
437
 
                    sub_merge.base_rev_id = base_revision
438
433
                    sub_merge.do_merge()
439
434
 
440
435
        finally:
458
453
    supports_reprocess = True
459
454
    supports_show_base = True
460
455
    history_based = False
461
 
    supports_cherrypick = True
462
456
    supports_reverse_cherrypick = True
463
457
    winner_idx = {"this": 2, "other": 1, "conflict": 1}
464
458
 
465
459
    def __init__(self, working_tree, this_tree, base_tree, other_tree, 
466
460
                 interesting_ids=None, reprocess=False, show_base=False,
467
461
                 pb=DummyProgress(), pp=None, change_reporter=None,
468
 
                 interesting_files=None, do_merge=True,
469
 
                 cherrypick=False):
 
462
                 interesting_files=None, do_merge=True):
470
463
        """Initialize the merger object and perform the merge.
471
464
 
472
465
        :param working_tree: The working tree to apply the merge to
504
497
        self.pb = pb
505
498
        self.pp = pp
506
499
        self.change_reporter = change_reporter
507
 
        self.cherrypick = cherrypick
508
500
        if self.pp is None:
509
501
            self.pp = ProgressPhase("Merge phase", 3, self.pb)
510
502
        if do_merge:
573
565
        if self.change_reporter is not None:
574
566
            from bzrlib import delta
575
567
            delta.report_changes(
576
 
                self.tt.iter_changes(), self.change_reporter)
 
568
                self.tt._iter_changes(), self.change_reporter)
577
569
        self.cook_conflicts(fs_conflicts)
578
570
        for conflict in self.cooked_conflicts:
579
571
            warning(conflict)
588
580
        executable3 is a tuple of execute-bit values for base, other and this.
589
581
        """
590
582
        result = []
591
 
        iterator = self.other_tree.iter_changes(self.base_tree,
 
583
        iterator = self.other_tree._iter_changes(self.base_tree,
592
584
                include_unchanged=True, specific_files=self.interesting_files,
593
585
                extra_trees=[self.this_tree])
594
586
        for (file_id, paths, changed, versioned, parents, names, kind,
873
865
            base_lines = []
874
866
        other_lines = self.get_lines(self.other_tree, file_id)
875
867
        this_lines = self.get_lines(self.this_tree, file_id)
876
 
        m3 = Merge3(base_lines, this_lines, other_lines,
877
 
                    is_cherrypick=self.cherrypick)
 
868
        m3 = Merge3(base_lines, this_lines, other_lines)
878
869
        start_marker = "!START OF MERGE CONFLICT!" + "I HOPE THIS IS UNIQUE"
879
870
        if self.show_base is True:
880
871
            base_marker = '|' * 7
1049
1040
    supports_reverse_cherrypick = False
1050
1041
    history_based = True
1051
1042
 
 
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_ids=interesting_ids, 
 
1051
                                          pb=pb, pp=pp, reprocess=reprocess,
 
1052
                                          change_reporter=change_reporter,
 
1053
                                          do_merge=do_merge)
 
1054
 
1052
1055
    def _merged_lines(self, file_id):
1053
1056
        """Generate the merged lines.
1054
1057
        There is no distinction between lines that are meant to contain <<<<<<<
1191
1194
    merger.reprocess = reprocess
1192
1195
    merger.other_rev_id = other_rev_id
1193
1196
    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
1197
    return merger.do_merge()
1199
1198
 
1200
1199
def get_merge_type_registry():
1290
1289
            for b_index in range(last_j, j):
1291
1290
                if b_index in new_b:
1292
1291
                    if b_index in killed_a:
1293
 
                        yield 'conflicted-b', self.lines_b[b_index]
 
1292
                        yield 'conflicted-b', self.lines_b[a_index]
1294
1293
                    else:
1295
1294
                        yield 'new-b', self.lines_b[b_index]
1296
1295
                else: