128
128
return SuccessfulSmartServerResponse(('ok',))
131
class SmartServerBranchRequestSetLastRevisionEx(SmartServerLockedBranchRequest):
133
def do_with_locked_branch(self, branch, new_last_revision_id,
134
allow_divergence, allow_overwrite_descendant):
135
"""Set the last revision of the branch.
139
:param new_last_revision_id: the revision ID to set as the last
140
revision of the branch.
141
:param allow_divergence: A flag. If non-zero, change the revision ID
142
even if the new_last_revision_id's ancestry has diverged from the
143
current last revision. If zero, a 'Diverged' error will be
144
returned if new_last_revision_id is not a descendant of the current
146
:param allow_overwrite_descendant: A flag. If zero and
147
new_last_revision_id is not a descendant of the current last
148
revision, then the last revision will not be changed. If non-zero
149
and there is no divergence, then the last revision is always
152
:returns: on success, a tuple of ('ok', revno, revision_id), where
153
revno and revision_id are the new values of the current last
154
revision info. The revision_id might be different to the
155
new_last_revision_id if allow_overwrite_descendant was not set.
157
do_not_overwrite_descendant = not allow_overwrite_descendant
159
last_revno, last_rev = branch.last_revision_info()
160
graph = branch.repository.get_graph()
161
if not allow_divergence or do_not_overwrite_descendant:
162
relation = branch._revision_relations(
163
last_rev, new_last_revision_id, graph)
164
if relation == 'diverged' and not allow_divergence:
165
return FailedSmartServerResponse(('Diverged',))
166
if relation == 'a_descends_from_b' and do_not_overwrite_descendant:
167
return SuccessfulSmartServerResponse(
168
('ok', last_revno, last_rev))
169
new_revno = graph.find_distance_to_null(
170
new_last_revision_id, [(last_rev, last_revno)])
171
branch.set_last_revision_info(new_revno, new_last_revision_id)
172
except errors.GhostRevisionsHaveNoRevno:
173
return FailedSmartServerResponse(
174
('NoSuchRevision', new_last_revision_id))
175
return SuccessfulSmartServerResponse(
176
('ok', new_revno, new_last_revision_id))
131
179
class SmartServerBranchRequestSetLastRevisionInfo(
132
180
SmartServerLockedBranchRequest):
133
181
"""Branch.set_last_revision_info. Sets the revno and the revision ID of