~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: Martin Pool
  • Date: 2006-03-10 06:29:53 UTC
  • mfrom: (1608 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1611.
  • Revision ID: mbp@sourcefrog.net-20060310062953-bc1c7ade75c89a7a
[merge] bzr.dev; pycurl not updated for readv yet

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
337
348
        else:
338
349
            all_ids = set(base_tree)
339
350
            all_ids.update(other_tree)
 
351
        working_tree.lock_write()
340
352
        self.tt = TreeTransform(working_tree, self.pb)
341
353
        try:
342
 
            for num, file_id in enumerate(all_ids):
343
 
                self.pb.update('Preparing file merge', num+1, len(all_ids))
344
 
                self.merge_names(file_id)
345
 
                file_status = self.merge_contents(file_id)
346
 
                self.merge_executable(file_id, file_status)
347
 
            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()
348
364
                
349
 
            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()
350
371
            self.cook_conflicts(fs_conflicts)
351
372
            for line in conflicts_strings(self.cooked_conflicts):
352
373
                warning(line)
353
 
            self.tt.apply()
 
374
            self.pp.next_phase()
 
375
            results = self.tt.apply()
 
376
            self.write_modified(results)
354
377
        finally:
355
378
            try:
356
379
                self.tt.finalize()
357
380
            except:
358
381
                pass
359
 
       
 
382
            working_tree.unlock()
 
383
            self.pb.clear()
 
384
 
 
385
    def write_modified(self, results):
 
386
        modified_hashes = {}
 
387
        for path in results.modified_paths:
 
388
            file_id = self.this_tree.path2id(self.this_tree.relpath(path))
 
389
            if file_id is None:
 
390
                continue
 
391
            hash = self.this_tree.get_file_sha1(file_id)
 
392
            if hash is None:
 
393
                continue
 
394
            modified_hashes[file_id] = hash
 
395
        self.this_tree.set_merge_modified(modified_hashes)
 
396
 
360
397
    @staticmethod
361
398
    def parent(entry, file_id):
362
399
        """Determine the parent for a file_id (used as a key method)"""
713
750
    supports_show_base = False
714
751
 
715
752
    def __init__(self, working_tree, this_tree, base_tree, other_tree, 
716
 
                 interesting_ids=None, pb=DummyProgress()):
 
753
                 interesting_ids=None, pb=DummyProgress(), pp=None):
717
754
        self.this_revision_tree = self._get_revision_tree(this_tree)
718
755
        self.other_revision_tree = self._get_revision_tree(other_tree)
719
756
        super(WeaveMerger, self).__init__(working_tree, this_tree, 
720
757
                                          base_tree, other_tree, 
721
758
                                          interesting_ids=interesting_ids, 
722
 
                                          pb=pb)
 
759
                                          pb=pb, pp=pp)
723
760
 
724
761
    def _get_revision_tree(self, tree):
725
762
        """Return a revision tree releated to this tree.
749
786
        this_revision_id = self.this_revision_tree.inventory[file_id].revision
750
787
        other_revision_id = \
751
788
            self.other_revision_tree.inventory[file_id].revision
752
 
        this_i = weave.lookup(this_revision_id)
753
 
        other_i = weave.lookup(other_revision_id)
754
 
        plan =  weave.plan_merge(this_i, other_i)
 
789
        plan =  weave.plan_merge(this_revision_id, other_revision_id)
755
790
        return weave.weave_merge(plan, '<<<<<<< TREE\n', 
756
791
                                       '>>>>>>> MERGE-SOURCE\n')
757
792
 
835
870
    merger.backup_files = backup_files
836
871
    merger.merge_type = merge_type
837
872
    merger.interesting_ids = interesting_ids
 
873
    merger.ignore_zero = ignore_zero
838
874
    if interesting_files:
839
875
        assert not interesting_ids, ('Only supply interesting_ids'
840
876
                                     ' or interesting_files')