~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

[merge] land Robert's branch-formats branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from bzrlib.branch import Branch
28
28
from bzrlib.delta import compare_trees
29
29
from bzrlib.errors import (BzrCommandError,
 
30
                           BzrError,
 
31
                           NoCommonAncestor,
 
32
                           NoCommits,
 
33
                           NoSuchRevision,
30
34
                           NotBranchError,
 
35
                           NotVersionedError,
31
36
                           UnrelatedBranches,
32
 
                           NoCommonAncestor,
33
 
                           NoCommits,
34
37
                           WorkingTreeNotRevision,
35
 
                           NotVersionedError,
36
 
                           BzrError)
 
38
                           )
37
39
from bzrlib.fetch import greedy_fetch, fetch
38
40
import bzrlib.osutils
39
41
from bzrlib.osutils import rename, pathjoin
40
 
from bzrlib.revision import common_ancestor, MultipleRevisionSources
41
 
from bzrlib.revision import is_ancestor, NULL_REVISION
 
42
from bzrlib.revision import common_ancestor, is_ancestor, NULL_REVISION
42
43
from bzrlib.trace import mutter, warning, note
 
44
from bzrlib.workingtree import WorkingTree
43
45
 
44
46
# TODO: Report back as changes are merged in
45
47
 
274
276
                show_base=False, 
275
277
                reprocess=False, 
276
278
                other_rev_id=None,
277
 
                interesting_files=None):
 
279
                interesting_files=None,
 
280
                this_tree=None):
278
281
    """Primary interface for merging. 
279
282
 
280
283
        typical use is probably 
281
284
        'merge_inner(branch, branch.get_revision_tree(other_revision),
282
285
                     branch.get_revision_tree(base_revision))'
283
286
        """
284
 
    merger = Merger(this_branch, other_tree, base_tree)
 
287
    if this_tree is None:
 
288
        this_tree = this_branch.working_tree()
 
289
    merger = Merger(this_branch, other_tree, base_tree, this_tree=this_tree)
285
290
    merger.backup_files = backup_files
286
291
    merger.merge_type = merge_type
287
292
    merger.interesting_ids = interesting_ids
300
305
 
301
306
 
302
307
class Merger(object):
303
 
    def __init__(self, this_branch, other_tree=None, base_tree=None):
 
308
    def __init__(self, this_branch, other_tree=None, base_tree=None, this_tree=None):
304
309
        object.__init__(self)
 
310
        assert this_tree is not None, "this_tree is required"
305
311
        self.this_branch = this_branch
306
312
        self.this_basis = this_branch.last_revision()
307
313
        self.this_rev_id = None
308
 
        self.this_tree = this_branch.working_tree()
 
314
        self.this_tree = this_tree
309
315
        self.this_revision_tree = None
310
316
        self.this_basis_tree = None
311
317
        self.other_tree = other_tree
380
386
                raise BzrCommandError("Working tree has uncommitted changes.")
381
387
 
382
388
    def compare_basis(self):
383
 
        changes = compare_trees(self.this_branch.working_tree(), 
 
389
        changes = compare_trees(self.this_tree, 
384
390
                                self.this_branch.basis_tree(), False)
385
391
        if not changes.has_changed():
386
392
            self.this_rev_id = self.this_basis
418
424
        ancestry = self.this_branch.repository.get_ancestry(self.this_basis)
419
425
        if self.other_rev_id in ancestry:
420
426
            return
421
 
        self.this_branch.working_tree().add_pending_merge(self.other_rev_id)
 
427
        self.this_tree.add_pending_merge(self.other_rev_id)
422
428
 
423
429
    def set_other(self, other_revision):
424
430
        other_branch, self.other_tree = _get_tree(other_revision, 
486
492
                path = path[2:]
487
493
            adjust_ids.append((path, id))
488
494
        if len(adjust_ids) > 0:
489
 
            self.this_branch.working_tree().set_inventory(self.regen_inventory(adjust_ids))
 
495
            self.this_tree.set_inventory(self.regen_inventory(adjust_ids))
490
496
        conflicts = self.conflict_handler.conflicts
491
497
        self.conflict_handler.finalize()
492
498
        return conflicts
493
499
 
494
500
    def regen_inventory(self, new_entries):
495
 
        old_entries = self.this_branch.working_tree().read_working_inventory()
 
501
        old_entries = self.this_tree.read_working_inventory()
496
502
        new_inventory = {}
497
503
        by_path = {}
498
504
        new_entries_map = {}