~bzr-pqm/bzr/bzr.dev

2052.3.1 by John Arbash Meinel
Add tests to cleanup the copyright of all source files
1
# Copyright (C) 2006 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
0.5.17 by John Arbash Meinel
adding apply-changset, plus more meta information.
16
"""\
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
17
This contains functionality for installing bundles into repositories
0.5.17 by John Arbash Meinel
adding apply-changset, plus more meta information.
18
"""
19
1185.82.78 by Aaron Bentley
Cleanups
20
import bzrlib.ui
1185.82.84 by Aaron Bentley
Moved stuff around
21
from bzrlib.progress import ProgressPhase
22
from bzrlib.merge import Merger
23
from bzrlib.repository import install_revision
1185.82.141 by Aaron Bentley
Ensure bzr works when you merge an already-merged bundle
24
from bzrlib.trace import note
1185.82.81 by Aaron Bentley
Remove unused functionality
25
0.5.67 by John Arbash Meinel
Working on apply_changeset
26
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
27
def install_bundle(repository, bundle_reader):
2520.4.6 by Aaron Bentley
Get installation started
28
    custom_install = getattr(bundle_reader, 'install', None)
29
    if custom_install is not None:
30
        return custom_install(repository)
1185.82.63 by Aaron Bentley
Added install revision progress bar
31
    pb = bzrlib.ui.ui_factory.nested_progress_bar()
1185.82.64 by Aaron Bentley
Lock repository while installing revisions
32
    repository.lock_write()
1185.82.63 by Aaron Bentley
Added install revision progress bar
33
    try:
1793.2.2 by Aaron Bentley
Move BundleReader into v07 serializer
34
        real_revisions = bundle_reader.real_revisions
1185.82.63 by Aaron Bentley
Added install revision progress bar
35
        for i, revision in enumerate(reversed(real_revisions)):
36
            pb.update("Install revisions",i, len(real_revisions))
37
            if repository.has_revision(revision.revision_id):
38
                continue
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
39
            cset_tree = bundle_reader.revision_tree(repository,
1185.82.63 by Aaron Bentley
Added install revision progress bar
40
                                                       revision.revision_id)
41
            install_revision(repository, revision, cset_tree)
42
    finally:
1185.82.64 by Aaron Bentley
Lock repository while installing revisions
43
        repository.unlock()
1185.82.63 by Aaron Bentley
Added install revision progress bar
44
        pb.finished()
1185.82.40 by Aaron Bentley
Started work on testing install_revisions/handling empty changesets
45
1185.82.81 by Aaron Bentley
Remove unused functionality
46
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
47
def merge_bundle(reader, tree, check_clean, merge_type, 
1551.11.9 by Aaron Bentley
Apply change reporting to merge
48
                    reprocess, show_base, change_reporter=None):
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
49
    """Merge a revision bundle into the current tree."""
1185.82.84 by Aaron Bentley
Moved stuff around
50
    pb = bzrlib.ui.ui_factory.nested_progress_bar()
1185.82.62 by Aaron Bentley
Don't fail if some data is already installed
51
    try:
1185.82.84 by Aaron Bentley
Moved stuff around
52
        pp = ProgressPhase("Merge phase", 6, pb)
53
        pp.next_phase()
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
54
        install_bundle(tree.branch.repository, reader)
1551.11.9 by Aaron Bentley
Apply change reporting to merge
55
        merger = Merger(tree.branch, this_tree=tree, pb=pb,
56
                        change_reporter=change_reporter)
1185.82.84 by Aaron Bentley
Moved stuff around
57
        merger.pp = pp
58
        merger.pp.next_phase()
59
        merger.check_basis(check_clean, require_commits=False)
1793.2.2 by Aaron Bentley
Move BundleReader into v07 serializer
60
        merger.other_rev_id = reader.target
61
        merger.other_tree = merger.revision_tree(reader.target)
62
        merger.other_basis = reader.target
1185.82.84 by Aaron Bentley
Moved stuff around
63
        merger.pp.next_phase()
64
        merger.find_base()
65
        if merger.base_rev_id == merger.other_rev_id:
66
            note("Nothing to do.")
67
            return 0
68
        merger.merge_type = merge_type
69
        merger.show_base = show_base
70
        merger.reprocess = reprocess
71
        conflicts = merger.do_merge()
72
        merger.set_pending()
73
    finally:
74
        pb.clear()
75
    return conflicts