~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

Merged latest from bzr.dev

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
from progress import DummyProgress, ProgressPhase
41
41
from bzrlib.revision import common_ancestor, is_ancestor, NULL_REVISION
42
42
from bzrlib.symbol_versioning import *
43
43
from bzrlib.trace import mutter, warning, note
44
44
from bzrlib.transform import (TreeTransform, resolve_conflicts, cook_conflicts,
45
45
                              conflicts_strings, FinalPaths, create_by_entry,
46
46
                              unique_add)
 
47
import bzrlib.ui
47
48
 
48
49
# TODO: Report back as changes are merged in
49
50
 
98
99
        self.show_base = False
99
100
        self.reprocess = False
100
101
        self._pb = pb 
 
102
        self.pp = None
 
103
 
101
104
 
102
105
    def revision_tree(self, revision_id):
103
106
        return self.this_branch.repository.revision_tree(revision_id)
203
206
        mutter("doing merge() with no base_revision specified")
204
207
        if base_revision == [None, None]:
205
208
            try:
206
 
                self.base_rev_id = common_ancestor(self.this_basis, 
207
 
                                                   self.other_basis, 
208
 
                                                   self.this_branch.repository,
209
 
                                                   self._pb)
 
209
                pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
210
                try:
 
211
                    this_repo = self.this_branch.repository
 
212
                    self.base_rev_id = common_ancestor(self.this_basis, 
 
213
                                                       self.other_basis, 
 
214
                                                       this_repo, pb)
 
215
                finally:
 
216
                    pb.finished()
210
217
            except NoCommonAncestor:
211
218
                raise UnrelatedBranches()
212
219
            self.base_tree = _get_revid_tree(self.this_branch, self.base_rev_id,
228
235
    def do_merge(self):
229
236
        kwargs = {'working_tree':self.this_tree, 'this_tree': self.this_tree, 
230
237
                  'other_tree': self.other_tree, 
231
 
                  'interesting_ids': self.interesting_ids}
 
238
                  'interesting_ids': self.interesting_ids,
 
239
                  'pp': self.pp}
232
240
        if self.merge_type.requires_base:
233
241
            kwargs['base_tree'] = self.base_tree
234
242
        if self.merge_type.supports_reprocess:
320
328
 
321
329
    def __init__(self, working_tree, this_tree, base_tree, other_tree, 
322
330
                 interesting_ids=None, reprocess=False, show_base=False,
323
 
                 pb=DummyProgress()):
 
331
                 pb=DummyProgress(), pp=None):
324
332
        """Initialize the merger object and perform the merge."""
325
333
        object.__init__(self)
326
334
        self.this_tree = working_tree
331
339
        self.reprocess = reprocess
332
340
        self.show_base = show_base
333
341
        self.pb = pb
 
342
        self.pp = pp
 
343
        if self.pp is None:
 
344
            self.pp = ProgressPhase("Merge phase", 3, self.pb)
334
345
 
335
346
        if interesting_ids is not None:
336
347
            all_ids = interesting_ids
340
351
        working_tree.lock_write()
341
352
        self.tt = TreeTransform(working_tree, self.pb)
342
353
        try:
343
 
            for num, file_id in enumerate(all_ids):
344
 
                self.pb.update('Preparing file merge', num+1, len(all_ids))
345
 
                self.merge_names(file_id)
346
 
                file_status = self.merge_contents(file_id)
347
 
                self.merge_executable(file_id, file_status)
348
 
            self.pb.clear()
 
354
            self.pp.next_phase()
 
355
            child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
356
            try:
 
357
                for num, file_id in enumerate(all_ids):
 
358
                    child_pb.update('Preparing file merge', num, len(all_ids))
 
359
                    self.merge_names(file_id)
 
360
                    file_status = self.merge_contents(file_id)
 
361
                    self.merge_executable(file_id, file_status)
 
362
            finally:
 
363
                child_pb.finished()
349
364
                
350
 
            fs_conflicts = resolve_conflicts(self.tt, self.pb)
 
365
            self.pp.next_phase()
 
366
            child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
367
            try:
 
368
                fs_conflicts = resolve_conflicts(self.tt, child_pb)
 
369
            finally:
 
370
                child_pb.finished()
351
371
            self.cook_conflicts(fs_conflicts)
352
372
            for line in conflicts_strings(self.cooked_conflicts):
353
373
                warning(line)
 
374
            self.pp.next_phase()
354
375
            results = self.tt.apply()
355
376
            self.write_modified(results)
356
377
        finally:
359
380
            except:
360
381
                pass
361
382
            working_tree.unlock()
 
383
            self.pb.clear()
362
384
 
363
385
    def write_modified(self, results):
364
386
        modified_hashes = {}
728
750
    supports_show_base = False
729
751
 
730
752
    def __init__(self, working_tree, this_tree, base_tree, other_tree, 
731
 
                 interesting_ids=None, pb=DummyProgress()):
 
753
                 interesting_ids=None, pb=DummyProgress(), pp=None):
732
754
        self.this_revision_tree = self._get_revision_tree(this_tree)
733
755
        self.other_revision_tree = self._get_revision_tree(other_tree)
734
756
        super(WeaveMerger, self).__init__(working_tree, this_tree, 
735
757
                                          base_tree, other_tree, 
736
758
                                          interesting_ids=interesting_ids, 
737
 
                                          pb=pb)
 
759
                                          pb=pb, pp=pp)
738
760
 
739
761
    def _get_revision_tree(self, tree):
740
762
        """Return a revision tree releated to this tree.