1109
1108
returned (old tip of the branch or None). _marker is used
1112
if self.branch.get_bound_location() is not None:
1114
update_branch = (old_tip is self._marker)
1116
self.lock_tree_write()
1117
update_branch = False
1120
old_tip = self.branch.update(possible_transports)
1122
if old_tip is self._marker:
1124
return self._update_tree(old_tip, change_reporter, revision, show_base)
1128
def _update_tree(self, old_tip=None, change_reporter=None, revision=None,
1130
"""Update a tree to the master branch.
1132
:param old_tip: if supplied, the previous tip revision the branch,
1133
before it was changed to the master branch's tip.
1135
# here if old_tip is not None, it is the old tip of the branch before
1136
# it was updated from the master branch. This should become a pending
1137
# merge in the working tree to preserve the user existing work. we
1138
# cant set that until we update the working trees last revision to be
1139
# one from the new branch, because it will just get absorbed by the
1140
# parent de-duplication logic.
1142
# We MUST save it even if an error occurs, because otherwise the users
1143
# local work is unreferenced and will appear to have been lost.
1145
with self.lock_tree_write():
1148
last_rev = self.get_parent_ids()[0]
1150
last_rev = _mod_revision.NULL_REVISION
1151
if revision is None:
1152
revision = self.branch.last_revision()
1154
old_tip = old_tip or _mod_revision.NULL_REVISION
1156
if not _mod_revision.is_null(old_tip) and old_tip != last_rev:
1157
# the branch we are bound to was updated
1158
# merge those changes in first
1159
base_tree = self.basis_tree()
1160
other_tree = self.branch.repository.revision_tree(old_tip)
1161
nb_conflicts = merge.merge_inner(self.branch, other_tree,
1162
base_tree, this_tree=self,
1163
change_reporter=change_reporter,
1164
show_base=show_base)
1166
self.add_parent_tree((old_tip, other_tree))
1167
note(gettext('Rerun update after fixing the conflicts.'))
1170
if last_rev != _mod_revision.ensure_null(revision):
1171
# the working tree is up to date with the branch
1172
# we can merge the specified revision from master
1173
to_tree = self.branch.repository.revision_tree(revision)
1174
to_root_id = to_tree.path2id('')
1176
basis = self.basis_tree()
1177
with basis.lock_read():
1178
if (basis.path2id('') is None or basis.path2id('') != to_root_id):
1179
self.set_root_id(to_root_id)
1182
# determine the branch point
1183
graph = self.branch.repository.get_graph()
1184
base_rev_id = graph.find_unique_lca(self.branch.last_revision(),
1186
base_tree = self.branch.repository.revision_tree(base_rev_id)
1188
nb_conflicts = merge.merge_inner(self.branch, to_tree, base_tree,
1190
change_reporter=change_reporter,
1191
show_base=show_base)
1192
self.set_last_revision(revision)
1193
# TODO - dedup parents list with things merged by pull ?
1194
# reuse the tree we've updated to to set the basis:
1195
parent_trees = [(revision, to_tree)]
1196
merges = self.get_parent_ids()[1:]
1197
# Ideally we ask the tree for the trees here, that way the working
1198
# tree can decide whether to give us the entire tree or give us a
1199
# lazy initialised tree. dirstate for instance will have the trees
1200
# in ram already, whereas a last-revision + basis-inventory tree
1201
# will not, but also does not need them when setting parents.
1202
for parent in merges:
1203
parent_trees.append(
1204
(parent, self.branch.repository.revision_tree(parent)))
1205
if not _mod_revision.is_null(old_tip):
1206
parent_trees.append(
1207
(old_tip, self.branch.repository.revision_tree(old_tip)))
1208
self.set_parent_trees(parent_trees)
1209
last_rev = parent_trees[0][0]
1111
raise NotImplementedError(self.update)
1212
1113
def set_conflicts(self, arg):
1213
1114
raise errors.UnsupportedOperation(self.set_conflicts, self)