~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-12 05:06:27 UTC
  • mto: (1185.82.108 w-changeset)
  • mto: This revision was merged to the branch mainline in revision 1738.
  • Revision ID: aaron.bentley@utoronto.ca-20060512050627-577a244f0cf0fb4d
More API updates

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from bzrlib.osutils import sha_string, split_lines
20
20
 
21
21
 
22
 
def _install_info(branch, cset_info, cset_tree):
 
22
def _install_info(repository, cset_info, cset_tree):
23
23
    """Make sure that there is a text entry for each 
24
24
    file in the changeset.
25
25
 
32
32
          as ghost revisions)
33
33
    """
34
34
 
35
 
    if not branch.has_revision(cset_info.target):
36
 
        branch.lock_write()
 
35
    if not repository.has_revision(cset_info.target):
 
36
        repository.lock_write()
37
37
        try:
38
38
            # install the inventory
39
39
            # TODO: Figure out how to handle ghosted revisions
41
41
            parent_invs = []
42
42
            rev = cset_info.real_revisions[-1]
43
43
            for p_id in rev.parent_ids:
44
 
                if branch.has_revision(p_id):
 
44
                if repository.has_revision(p_id):
45
45
                    present_parents.append(p_id)
46
 
                    parent_invs.append(branch.get_inventory(revision))
 
46
                    parent_invs.append(repository.get_inventory(revision))
47
47
 
48
48
            inv = cset_tree.inventory
49
49
            
50
50
            # Add the texts that are not already present
51
51
            for path, ie in inv.iter_entries():
52
 
                w = branch.weave_store.get_weave_or_empty(ie.file_id,
53
 
                        branch.get_transaction())
 
52
                w = repository.weave_store.get_weave_or_empty(ie.file_id,
 
53
                        repository.get_transaction())
54
54
                if ie.revision not in w._name_map:
55
 
                    branch.weave_store.add_text(ie.file_id, rev.revision_id,
56
 
                        cset_tree.get_file(ie.file_id).readlines(),
57
 
                        present_parents, branch.get_transaction())
 
55
                    repository.weave_store.add_text(ie.file_id, 
 
56
                                                    rev.revision_id,
 
57
                    cset_tree.get_file(ie.file_id).readlines(),
 
58
                    present_parents, repository.get_transaction())
58
59
 
59
60
            # Now add the inventory information
60
61
            txt = serializer_v5.write_inventory_to_string(inv)
61
62
            sha1 = sha_string(txt)
62
 
            branch.control_weaves.add_text('inventory', 
 
63
            repository.control_weaves.add_text('inventory', 
63
64
                rev.revision_id, 
64
65
                split_lines(txt), 
65
66
                present_parents,
66
 
                branch.get_transaction())
 
67
                repository.get_transaction())
67
68
 
68
69
            # And finally, insert the revision
69
70
            rev_tmp = StringIO()
70
71
            serializer_v5.write_revision(rev, rev_tmp)
71
72
            rev_tmp.seek(0)
72
 
            branch.revision_store.add(rev_tmp, rev.revision_id)
 
73
            repository.revision_store.add(rev_tmp, rev.revision_id)
73
74
        finally:
74
75
            branch.unlock()
75
76
 
85
86
    if reverse:
86
87
        raise Exception('reverse not implemented yet')
87
88
 
88
 
    cset = read_changeset.read_changeset(from_file, branch)
 
89
    cset = read_changeset.read_changeset(from_file, branch.repository)
89
90
 
90
91
    return _apply_cset(branch, cset, reverse=reverse, auto_commit=auto_commit)
91
92
        
92
 
def _apply_cset(branch, cset, reverse=False, auto_commit=False):
 
93
def _apply_cset(tree, cset, reverse=False, auto_commit=False):
93
94
    """Apply an in-memory changeset to a given branch.
94
95
    """
95
96
 
96
97
    cset_info, cset_tree = cset
97
98
 
98
 
    _install_info(branch, cset_info, cset_tree)
 
99
    _install_info(tree.branch.repository, cset_info, cset_tree)
99
100
 
100
101
    # We could technically optimize more, by using the ChangesetTree
101
102
    # we already have in memory, but after installing revisions
107
108
    #   for the merge, the merge code should pick the best merge
108
109
    #   based on the ancestry of both trees.
109
110
    #
110
 
    if branch.last_revision() is None:
 
111
    if tree.last_revision() is None:
111
112
        base = None
112
113
    else:
113
 
        base = common_ancestor(branch.last_revision(), cset_info.target, branch)
114
 
    merge_inner(branch, branch.revision_tree(cset_info.target),
115
 
                branch.revision_tree(base))
 
114
        base = common_ancestor(tree.last_revision(), cset_info.target, 
 
115
                               tree.branch.repository)
 
116
    merge_inner(tree.branch, 
 
117
                tree.branch.repository.revision_tree(cset_info.target),
 
118
                tree.branch.repository.revision_tree(base), this_tree=tree)
116
119
 
117
120
    auto_committed = False
118
121
    
189
192
                print '** Could not auto-commit.'
190
193
 
191
194
    if not auto_committed:
192
 
        branch.add_pending_merge(cset_info.target)
 
195
        tree.add_pending_merge(cset_info.target)
193
196
 
194
197
    return auto_committed
195
198