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