1162
1162
@needs_write_lock
1163
1163
def update(self):
1164
"""Update a working tree along its branch.
1166
This will update the branch if its bound too, which means we have multiple trees involved:
1167
The new basis tree of the master.
1168
The old basis tree of the branch.
1169
The old basis tree of the working tree.
1170
The current working tree state.
1171
pathologically all three may be different, and non ancestors of each other.
1172
Conceptually we want to:
1173
Preserve the wt.basis->wt.state changes
1174
Transform the wt.basis to the new master basis.
1175
Apply a merge of the old branch basis to get any 'local' changes from it into the tree.
1176
Restore the wt.basis->wt.state changes.
1178
There isn't a single operation at the moment to do that, so we:
1179
Merge current state -> basis tree of the master w.r.t. the old tree basis.
1180
Do a 'normal' merge of the old branch basis if it is relevant.
1164
1182
old_tip = self.branch.update()
1183
if old_tip is not None:
1184
self.add_pending_merge(old_tip)
1165
1185
self.branch.lock_read()
1167
if self.last_revision() == self.branch.last_revision():
1170
basis = self.basis_tree()
1171
to_tree = self.branch.basis_tree()
1172
result = merge_inner(self.branch,
1176
self.set_last_revision(self.branch.last_revision())
1188
if self.last_revision() != self.branch.last_revision():
1189
# merge tree state up to new branch tip.
1190
basis = self.basis_tree()
1191
to_tree = self.branch.basis_tree()
1192
result += merge_inner(self.branch,
1196
self.set_last_revision(self.branch.last_revision())
1197
if old_tip and old_tip != self.last_revision():
1198
# our last revision was not the prior branch last reivison
1199
# and we have converted that last revision to a pending merge.
1200
# base is somewhere between the branch tip now
1201
# and the now pending merge
1202
from bzrlib.revision import common_ancestor
1204
base_rev_id = common_ancestor(self.branch.last_revision(),
1206
self.branch.repository)
1207
except errors.NoCommonAncestor:
1209
base_tree = self.branch.repository.revision_tree(base_rev_id)
1210
other_tree = self.branch.repository.revision_tree(old_tip)
1211
result += merge_inner(self.branch,
1179
1217
self.branch.unlock()