~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

MergeĀ mainline.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
from bzrlib.merge3 import Merge3
38
38
import bzrlib.osutils
39
39
from bzrlib.osutils import rename, pathjoin
 
40
from progress import DummyProgress
40
41
from bzrlib.revision import common_ancestor, is_ancestor, NULL_REVISION
41
42
from bzrlib.symbol_versioning import *
42
43
from bzrlib.trace import mutter, warning, note
79
80
 
80
81
 
81
82
class Merger(object):
82
 
    def __init__(self, this_branch, other_tree=None, base_tree=None, this_tree=None):
 
83
    def __init__(self, this_branch, other_tree=None, base_tree=None, 
 
84
                 this_tree=None, pb=DummyProgress()):
83
85
        object.__init__(self)
84
86
        assert this_tree is not None, "this_tree is required"
85
87
        self.this_branch = this_branch
95
97
        self.interesting_ids = None
96
98
        self.show_base = False
97
99
        self.reprocess = False
 
100
        self._pb = pb 
98
101
 
99
102
    def revision_tree(self, revision_id):
100
103
        return self.this_branch.repository.revision_tree(revision_id)
202
205
            try:
203
206
                self.base_rev_id = common_ancestor(self.this_basis, 
204
207
                                                   self.other_basis, 
205
 
                                                   self.this_branch.repository)
 
208
                                                   self.this_branch.repository,
 
209
                                                   self._pb)
206
210
            except NoCommonAncestor:
207
211
                raise UnrelatedBranches()
208
212
            self.base_tree = _get_revid_tree(self.this_branch, self.base_rev_id,
236
240
        elif self.show_base:
237
241
            raise BzrError("Showing base is not supported for this"
238
242
                                  " merge type. %s" % self.merge_type)
239
 
        merge = self.merge_type(**kwargs)
 
243
        merge = self.merge_type(pb=self._pb, **kwargs)
240
244
        if len(merge.cooked_conflicts) == 0:
241
245
            if not self.ignore_zero:
242
246
                note("All changes applied successfully.")
314
318
    history_based = False
315
319
 
316
320
    def __init__(self, working_tree, this_tree, base_tree, other_tree, 
317
 
                 reprocess=False, show_base=False):
 
321
                 reprocess=False, show_base=False, pb=DummyProgress()):
318
322
        """Initialize the merger object and perform the merge."""
319
323
        object.__init__(self)
320
324
        self.this_tree = working_tree
324
328
        self.cooked_conflicts = []
325
329
        self.reprocess = reprocess
326
330
        self.show_base = show_base
 
331
        self.pb = pb
327
332
 
328
333
        all_ids = set(base_tree)
329
334
        all_ids.update(other_tree)
330
 
        self.tt = TreeTransform(working_tree)
 
335
        self.tt = TreeTransform(working_tree, self.pb)
331
336
        try:
332
 
            for file_id in all_ids:
 
337
            for num, file_id in enumerate(all_ids):
 
338
                self.pb.update('Preparing file merge', num+1, len(all_ids))
333
339
                self.merge_names(file_id)
334
340
                file_status = self.merge_contents(file_id)
335
341
                self.merge_executable(file_id, file_status)
 
342
            self.pb.clear()
336
343
                
337
 
            fs_conflicts = resolve_conflicts(self.tt)
 
344
            fs_conflicts = resolve_conflicts(self.tt, self.pb)
338
345
            self.cook_conflicts(fs_conflicts)
339
346
            for line in conflicts_strings(self.cooked_conflicts):
340
347
                warning(line)
700
707
    supports_reprocess = False
701
708
    supports_show_base = False
702
709
 
703
 
    def __init__(self, working_tree, this_tree, base_tree, other_tree):
 
710
    def __init__(self, working_tree, this_tree, base_tree, other_tree, 
 
711
                 pb=DummyProgress()):
704
712
        self.this_revision_tree = self._get_revision_tree(this_tree)
705
713
        self.other_revision_tree = self._get_revision_tree(other_tree)
706
714
        super(WeaveMerger, self).__init__(working_tree, this_tree, 
707
 
                                          base_tree, other_tree)
 
715
                                          base_tree, other_tree, pb=pb)
708
716
 
709
717
    def _get_revision_tree(self, tree):
710
718
        """Return a revision tree releated to this tree.
800
808
                reprocess=False, 
801
809
                other_rev_id=None,
802
810
                interesting_files=None,
803
 
                this_tree=None):
 
811
                this_tree=None,
 
812
                pb=DummyProgress()):
804
813
    """Primary interface for merging. 
805
814
 
806
815
        typical use is probably 
813
822
             DeprecationWarning,
814
823
             stacklevel=2)
815
824
        this_tree = this_branch.bzrdir.open_workingtree()
816
 
    merger = Merger(this_branch, other_tree, base_tree, this_tree=this_tree)
 
825
    merger = Merger(this_branch, other_tree, base_tree, this_tree=this_tree, 
 
826
                    pb=pb)
817
827
    merger.backup_files = backup_files
818
828
    merger.merge_type = merge_type
819
829
    merger.interesting_ids = interesting_ids