19
19
from bzrlib.osutils import sha_string, split_lines
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.
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))
48
48
inv = cset_tree.inventory
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,
57
cset_tree.get_file(ie.file_id).readlines(),
58
present_parents, repository.get_transaction())
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',
66
branch.get_transaction())
67
repository.get_transaction())
68
69
# And finally, insert the revision
69
70
rev_tmp = StringIO()
70
71
serializer_v5.write_revision(rev, rev_tmp)
72
branch.revision_store.add(rev_tmp, rev.revision_id)
73
repository.revision_store.add(rev_tmp, rev.revision_id)
86
87
raise Exception('reverse not implemented yet')
88
cset = read_changeset.read_changeset(from_file, branch)
89
cset = read_changeset.read_changeset(from_file, branch.repository)
90
91
return _apply_cset(branch, cset, reverse=reverse, auto_commit=auto_commit)
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.
96
97
cset_info, cset_tree = cset
98
_install_info(branch, cset_info, cset_tree)
99
_install_info(tree.branch.repository, cset_info, cset_tree)
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.
110
if branch.last_revision() is None:
111
if tree.last_revision() is None:
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)
117
120
auto_committed = False