~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bundle/apply_bundle.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-06-03 20:18:35 UTC
  • mfrom: (1185.82.137 w-changeset)
  • Revision ID: pqm@pqm.ubuntu.com-20060603201835-1c9a1725641ccd24
Implement bundles

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
 
 
10
 
 
11
def install_bundle(repository, bundle_reader):
 
12
    pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
13
    repository.lock_write()
 
14
    try:
 
15
        real_revisions = bundle_reader.info.real_revisions
 
16
        for i, revision in enumerate(reversed(real_revisions)):
 
17
            pb.update("Install revisions",i, len(real_revisions))
 
18
            if repository.has_revision(revision.revision_id):
 
19
                continue
 
20
            cset_tree = bundle_reader.revision_tree(repository,
 
21
                                                       revision.revision_id)
 
22
            install_revision(repository, revision, cset_tree)
 
23
    finally:
 
24
        repository.unlock()
 
25
        pb.finished()
 
26
 
 
27
 
 
28
def merge_bundle(reader, tree, check_clean, merge_type, 
 
29
                    reprocess, show_base):
 
30
    """Merge a revision bundle into the current tree."""
 
31
    pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
32
    try:
 
33
        pp = ProgressPhase("Merge phase", 6, pb)
 
34
        pp.next_phase()
 
35
        install_bundle(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