~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

Move working tree initialisation out from  Branch.initialize, deprecated Branch.initialize to Branch.create.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
from bzrlib.fetch import greedy_fetch, fetch
40
40
from bzrlib.revision import is_ancestor, NULL_REVISION
41
41
from bzrlib.osutils import rename, pathjoin
42
 
from bzrlib.revision import common_ancestor, MultipleRevisionSources
 
42
from bzrlib.revision import common_ancestor
43
43
from bzrlib.errors import NoSuchRevision
 
44
from bzrlib.workingtree import WorkingTree
44
45
 
45
46
# TODO: Report back as changes are merged in
46
47
 
307
308
    clients might prefer to call merge_inner(), which has less magic behavior.
308
309
    """
309
310
    if this_dir is None:
310
 
        this_dir = u'.'
311
 
    this_branch = Branch.open_containing(this_dir)[0]
 
311
        this_dir = '.'
 
312
    this_tree = WorkingTree.open_containing(this_dir)[0]
312
313
    if show_base and not merge_type is ApplyMerge3:
313
314
        raise BzrCommandError("Show-base is not supported for this merge"
314
315
                              " type. %s" % merge_type)
317
318
                              " type. %s" % merge_type)
318
319
    if reprocess and show_base:
319
320
        raise BzrCommandError("Cannot reprocess and show base.")
320
 
    merger = Merger(this_branch)
 
321
    merger = Merger(this_tree.branch, this_tree=this_tree)
321
322
    merger.check_basis(check_clean)
322
323
    merger.set_other(other_revision)
323
324
    merger.set_base(base_revision)
344
345
                show_base=False, 
345
346
                reprocess=False, 
346
347
                other_rev_id=None,
347
 
                interesting_files=None):
 
348
                interesting_files=None,
 
349
                this_tree=None):
348
350
    """Primary interface for merging. 
349
351
 
350
352
        typical use is probably 
351
353
        'merge_inner(branch, branch.get_revision_tree(other_revision),
352
354
                     branch.get_revision_tree(base_revision))'
353
355
        """
354
 
    merger = Merger(this_branch, other_tree, base_tree)
 
356
    if this_tree is None:
 
357
        this_tree = this_branch.working_tree()
 
358
    merger = Merger(this_branch, other_tree, base_tree, this_tree=this_tree)
355
359
    merger.backup_files = backup_files
356
360
    merger.merge_type = merge_type
357
361
    merger.interesting_ids = interesting_ids
370
374
 
371
375
 
372
376
class Merger(object):
373
 
    def __init__(self, this_branch, other_tree=None, base_tree=None):
 
377
    def __init__(self, this_branch, other_tree=None, base_tree=None, this_tree=None):
374
378
        object.__init__(self)
 
379
        assert this_tree is not None, "this_tree is required"
375
380
        self.this_branch = this_branch
376
381
        self.this_basis = this_branch.last_revision()
377
382
        self.this_rev_id = None
378
 
        self.this_tree = this_branch.working_tree()
 
383
        self.this_tree = this_tree
379
384
        self.this_revision_tree = None
380
385
        self.this_basis_tree = None
381
386
        self.other_tree = other_tree
453
458
                raise BzrCommandError("Working tree has uncommitted changes.")
454
459
 
455
460
    def compare_basis(self):
456
 
        changes = compare_trees(self.this_branch.working_tree(), 
 
461
        changes = compare_trees(self.this_tree, 
457
462
                                self.this_branch.basis_tree(), False)
458
463
        if not changes.has_changed():
459
464
            self.this_rev_id = self.this_basis
491
496
            return
492
497
        if self.other_rev_id in self.this_branch.get_ancestry(self.this_basis):
493
498
            return
494
 
        self.this_branch.working_tree().add_pending_merge(self.other_rev_id)
 
499
        self.this_tree.add_pending_merge(self.other_rev_id)
495
500
 
496
501
    def set_other(self, other_revision):
497
502
        other_branch, self.other_tree = get_tree(other_revision, 
558
563
                path = path[2:]
559
564
            adjust_ids.append((path, id))
560
565
        if len(adjust_ids) > 0:
561
 
            self.this_branch.working_tree().set_inventory(self.regen_inventory(adjust_ids))
 
566
            self.this_tree.set_inventory(self.regen_inventory(adjust_ids))
562
567
        conflicts = self.conflict_handler.conflicts
563
568
        self.conflict_handler.finalize()
564
569
        return conflicts
565
570
 
566
571
    def regen_inventory(self, new_entries):
567
 
        old_entries = self.this_branch.working_tree().read_working_inventory()
 
572
        old_entries = self.this_tree.read_working_inventory()
568
573
        new_inventory = {}
569
574
        by_path = {}
570
575
        new_entries_map = {}