966
def do_repository_request(self, repository, lock_token, write_group_tokens,
966
def do_repository_request(self, repository, lock_token, revision_id,
967
*write_group_tokens):
968
968
"""Add a revision signature text.
970
970
:param repository: Repository to operate on
971
971
:param lock_token: Lock token
972
:param revision_id: Revision for which to add signature
972
973
:param write_group_tokens: Write group tokens
973
:param revision_id: Revision for which to add signature
975
975
self._lock_token = lock_token
976
self._revision_id = revision_id
976
977
self._write_group_tokens = write_group_tokens
977
self._revision_id = revision_id
980
980
def do_body(self, body_bytes):
989
989
self._repository.resume_write_group(self._write_group_tokens)
991
self._repository.add_signature_text(self._revision_id, body_bytes)
991
self._repository.add_signature_text(self._revision_id,
993
994
new_write_group_tokens = self._repository.suspend_write_group()
995
996
self._repository.unlock()
996
return SuccessfulSmartServerResponse(('ok', ) + tuple(new_write_group_tokens))
997
return SuccessfulSmartServerResponse(
998
('ok', ) + tuple(new_write_group_tokens))
999
1001
class SmartServerRepositoryStartWriteGroup(SmartServerRepositoryRequest):
1126
1128
return SuccessfulSmartServerResponse(("ok", ), )
1131
class SmartServerRepositoryIterFilesBytes(SmartServerRepositoryRequest):
1132
"""Iterate over the contents of files.
1134
The client sends a list of desired files to stream, one
1135
per line, and as tuples of file id and revision, separated by
1138
The server replies with a stream. Each entry is preceded by a header,
1139
which can either be:
1141
* "ok\x00IDX\n" where IDX is the index of the entry in the desired files
1142
list sent by the client. This header is followed by the contents of
1143
the file, bzip2-compressed.
1144
* "absent\x00FILEID\x00REVISION\x00IDX" to indicate a text is missing.
1145
The client can then raise an appropriate RevisionNotPresent error
1146
or check its fallback repositories.
1151
def body_stream(self, repository, desired_files):
1152
self._repository.lock_read()
1155
for i, key in enumerate(desired_files):
1157
for record in repository.texts.get_record_stream(text_keys,
1159
identifier = text_keys[record.key]
1160
if record.storage_kind == 'absent':
1161
yield "absent\0%s\0%s\0%d\n" % (record.key[0],
1162
record.key[1], identifier)
1163
# FIXME: Way to abort early?
1165
yield "ok\0%d\n" % identifier
1166
compressor = zlib.compressobj()
1167
for bytes in record.get_bytes_as('chunked'):
1168
data = compressor.compress(bytes)
1171
data = compressor.flush()
1175
self._repository.unlock()
1177
def do_body(self, body_bytes):
1179
tuple(l.split("\0")) for l in body_bytes.splitlines()]
1180
return SuccessfulSmartServerResponse(('ok', ),
1181
body_stream=self.body_stream(self._repository, desired_files))
1183
def do_repository_request(self, repository):
1184
# Signal that we want a body
1129
1188
class SmartServerRepositoryIterRevisions(SmartServerRepositoryRequest):
1130
1189
"""Stream a list of revisions.