~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bundle/apply_bundle.py

Fix BzrDir.create_workingtree for NULL_REVISION

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""\
 
2
This contains functionality for installing bundles into repositories
 
3
"""
 
4
 
 
5
import bzrlib.ui
 
6
from bzrlib.progress import ProgressPhase
 
7
from bzrlib.merge import Merger
 
8
from bzrlib.repository import install_revision
 
9
from bzrlib.trace import note
 
10
 
 
11
 
 
12
def install_bundle(repository, bundle_reader):
 
13
    pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
14
    repository.lock_write()
 
15
    try:
 
16
        real_revisions = bundle_reader.real_revisions
 
17
        for i, revision in enumerate(reversed(real_revisions)):
 
18
            pb.update("Install revisions",i, len(real_revisions))
 
19
            if repository.has_revision(revision.revision_id):
 
20
                continue
 
21
            cset_tree = bundle_reader.revision_tree(repository,
 
22
                                                       revision.revision_id)
 
23
            install_revision(repository, revision, cset_tree)
 
24
    finally:
 
25
        repository.unlock()
 
26
        pb.finished()
 
27
 
 
28
 
 
29
def merge_bundle(reader, tree, check_clean, merge_type, 
 
30
                    reprocess, show_base):
 
31
    """Merge a revision bundle into the current tree."""
 
32
    pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
33
    try:
 
34
        pp = ProgressPhase("Merge phase", 6, pb)
 
35
        pp.next_phase()
 
36
        install_bundle(tree.branch.repository, reader)
 
37
        merger = Merger(tree.branch, this_tree=tree, pb=pb)
 
38
        merger.pp = pp
 
39
        merger.pp.next_phase()
 
40
        merger.check_basis(check_clean, require_commits=False)
 
41
        merger.other_rev_id = reader.target
 
42
        merger.other_tree = merger.revision_tree(reader.target)
 
43
        merger.other_basis = reader.target
 
44
        merger.pp.next_phase()
 
45
        merger.find_base()
 
46
        if merger.base_rev_id == merger.other_rev_id:
 
47
            note("Nothing to do.")
 
48
            return 0
 
49
        merger.merge_type = merge_type
 
50
        merger.show_base = show_base
 
51
        merger.reprocess = reprocess
 
52
        conflicts = merger.do_merge()
 
53
        merger.set_pending()
 
54
    finally:
 
55
        pb.clear()
 
56
    return conflicts