~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

Added progress bars to tree-changing operations

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