~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

[merge] bzr.dev 2294

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
from bzrlib import (
23
23
    osutils,
 
24
    registry,
24
25
    )
25
26
from bzrlib.branch import Branch
26
27
from bzrlib.conflicts import ConflictList, Conflict
87
88
 
88
89
class Merger(object):
89
90
    def __init__(self, this_branch, other_tree=None, base_tree=None,
90
 
                 this_tree=None, pb=DummyProgress()):
 
91
                 this_tree=None, pb=DummyProgress(), change_reporter=None):
91
92
        object.__init__(self)
92
93
        assert this_tree is not None, "this_tree is required"
93
94
        self.this_branch = this_branch
105
106
        self.reprocess = False
106
107
        self._pb = pb
107
108
        self.pp = None
 
109
        self.change_reporter = change_reporter
108
110
 
109
111
    def revision_tree(self, revision_id):
110
112
        return self.this_branch.repository.revision_tree(revision_id)
273
275
        if self.other_tree is not None:
274
276
            self.other_tree.lock_read()
275
277
        try:
276
 
            merge = self.merge_type(pb=self._pb, **kwargs)
 
278
            merge = self.merge_type(pb=self._pb,
 
279
                                    change_reporter=self.change_reporter,
 
280
                                    **kwargs)
277
281
        finally:
278
282
            if self.other_tree is not None:
279
283
                self.other_tree.unlock()
367
371
 
368
372
    def __init__(self, working_tree, this_tree, base_tree, other_tree, 
369
373
                 interesting_ids=None, reprocess=False, show_base=False,
370
 
                 pb=DummyProgress(), pp=None):
 
374
                 pb=DummyProgress(), pp=None, change_reporter=None):
371
375
        """Initialize the merger object and perform the merge."""
372
376
        object.__init__(self)
373
377
        self.this_tree = working_tree
379
383
        self.show_base = show_base
380
384
        self.pb = pb
381
385
        self.pp = pp
 
386
        self.change_reporter = change_reporter
382
387
        if self.pp is None:
383
388
            self.pp = ProgressPhase("Merge phase", 3, self.pb)
384
389
 
407
412
                fs_conflicts = resolve_conflicts(self.tt, child_pb)
408
413
            finally:
409
414
                child_pb.finished()
 
415
            if change_reporter is not None:
 
416
                from bzrlib import delta
 
417
                delta.report_changes(self.tt._iter_changes(), change_reporter)
410
418
            self.cook_conflicts(fs_conflicts)
411
419
            for conflict in self.cooked_conflicts:
412
420
                warning(conflict)
830
838
 
831
839
    def __init__(self, working_tree, this_tree, base_tree, other_tree, 
832
840
                 interesting_ids=None, pb=DummyProgress(), pp=None,
833
 
                 reprocess=False):
 
841
                 reprocess=False, change_reporter=None):
834
842
        self.this_revision_tree = self._get_revision_tree(this_tree)
835
843
        self.other_revision_tree = self._get_revision_tree(other_tree)
836
844
        super(WeaveMerger, self).__init__(working_tree, this_tree, 
837
845
                                          base_tree, other_tree, 
838
846
                                          interesting_ids=interesting_ids, 
839
 
                                          pb=pb, pp=pp, reprocess=reprocess)
 
847
                                          pb=pb, pp=pp, reprocess=reprocess,
 
848
                                          change_reporter=change_reporter)
840
849
 
841
850
    def _get_revision_tree(self, tree):
842
851
        """Return a revision tree related to this tree.
943
952
                other_rev_id=None,
944
953
                interesting_files=None,
945
954
                this_tree=None,
946
 
                pb=DummyProgress()):
 
955
                pb=DummyProgress(),
 
956
                change_reporter=None):
947
957
    """Primary interface for merging. 
948
958
 
949
959
        typical use is probably 
957
967
             stacklevel=2)
958
968
        this_tree = this_branch.bzrdir.open_workingtree()
959
969
    merger = Merger(this_branch, other_tree, base_tree, this_tree=this_tree,
960
 
                    pb=pb)
 
970
                    pb=pb, change_reporter=change_reporter)
961
971
    merger.backup_files = backup_files
962
972
    merger.merge_type = merge_type
963
973
    merger.interesting_ids = interesting_ids
972
982
    merger.other_basis = other_rev_id
973
983
    return merger.do_merge()
974
984
 
975
 
 
976
 
merge_types = {     "merge3": (Merge3Merger, "Native diff3-style merge"), 
977
 
                     "diff3": (Diff3Merger,  "Merge using external diff3"),
978
 
                     'weave': (WeaveMerger, "Weave-based merge")
979
 
              }
980
 
 
981
 
 
982
 
def merge_type_help():
983
 
    templ = '%s%%7s: %%s' % (' '*12)
984
 
    lines = [templ % (f[0], f[1][1]) for f in merge_types.iteritems()]
985
 
    return '\n'.join(lines)
 
985
def get_merge_type_registry():
 
986
    """Merge type registry is in bzrlib.option to avoid circular imports.
 
987
 
 
988
    This method provides a sanctioned way to retrieve it.
 
989
    """
 
990
    from bzrlib import option
 
991
    return option._merge_type_registry