~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/changeset/apply_changeset.py

  • Committer: Aaron Bentley
  • Date: 2006-05-19 14:13:36 UTC
  • mto: This revision was merged to the branch mainline in revision 1738.
  • Revision ID: abentley@panoramicfeedback.com-20060519141336-06c4a95798363efc
Moved stuff around

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
This contains functionality for installing changesets into repositories
3
3
"""
4
4
 
5
 
from bzrlib.errors import RevisionAlreadyPresent
6
 
from bzrlib.tree import EmptyTree
7
5
import bzrlib.ui
 
6
from bzrlib.progress import ProgressPhase
 
7
from bzrlib.merge import Merger
 
8
from bzrlib.repository import install_revision
8
9
 
9
10
 
10
11
def install_changeset(repository, changeset_reader):
24
25
        pb.finished()
25
26
 
26
27
 
27
 
def install_revision(repository, rev, cset_tree):
28
 
    present_parents = []
29
 
    parent_trees = {}
30
 
    for p_id in rev.parent_ids:
31
 
        if repository.has_revision(p_id):
32
 
            present_parents.append(p_id)
33
 
            parent_trees[p_id] = repository.revision_tree(p_id)
34
 
        else:
35
 
            parent_trees[p_id] = EmptyTree()
36
 
 
37
 
    inv = cset_tree.inventory
38
 
    
39
 
    # Add the texts that are not already present
40
 
    for path, ie in inv.iter_entries():
41
 
        w = repository.weave_store.get_weave_or_empty(ie.file_id,
42
 
                repository.get_transaction())
43
 
        if ie.revision not in w:
44
 
            text_parents = []
45
 
            for revision, tree in parent_trees.iteritems():
46
 
                if ie.file_id not in tree:
47
 
                    continue
48
 
                parent_id = tree.inventory[ie.file_id].revision
49
 
                if parent_id in text_parents:
50
 
                    continue
51
 
                text_parents.append(parent_id)
52
 
                    
53
 
            vfile = repository.weave_store.get_weave_or_empty(ie.file_id, 
54
 
                repository.get_transaction())
55
 
            lines = cset_tree.get_file(ie.file_id).readlines()
56
 
            vfile.add_lines(rev.revision_id, text_parents, lines)
 
28
def merge_changeset(reader, tree, check_clean, merge_type, 
 
29
                    reprocess, show_base):
 
30
    """Merge a changeset's revision into the current tree."""
 
31
    pb = bzrlib.ui.ui_factory.nested_progress_bar()
57
32
    try:
58
 
        # install the inventory
59
 
        repository.add_inventory(rev.revision_id, inv, present_parents)
60
 
    except RevisionAlreadyPresent:
61
 
        pass
62
 
    repository.add_revision(rev.revision_id, rev, inv)
 
33
        pp = ProgressPhase("Merge phase", 6, pb)
 
34
        pp.next_phase()
 
35
        install_changeset(tree.branch.repository, reader)
 
36
        merger = Merger(tree.branch, this_tree=tree, pb=pb)
 
37
        merger.pp = pp
 
38
        merger.pp.next_phase()
 
39
        merger.check_basis(check_clean, require_commits=False)
 
40
        merger.other_rev_id = reader.info.target
 
41
        merger.other_tree = merger.revision_tree(reader.info.target)
 
42
        merger.other_basis = reader.info.target
 
43
        merger.pp.next_phase()
 
44
        merger.find_base()
 
45
        if merger.base_rev_id == merger.other_rev_id:
 
46
            note("Nothing to do.")
 
47
            return 0
 
48
        merger.merge_type = merge_type
 
49
        merger.show_base = show_base
 
50
        merger.reprocess = reprocess
 
51
        conflicts = merger.do_merge()
 
52
        merger.set_pending()
 
53
    finally:
 
54
        pb.clear()
 
55
    return conflicts