1092
1093
self._ensure_real()
1093
1094
return self._real_repository.pack()
1097
def revisions(self):
1098
"""Decorate the real repository for now.
1100
In the short term this should become a real object to intercept graph
1103
In the long term a full blown network facility is needed.
1106
return self._real_repository.revisions
1095
1108
def set_make_working_trees(self, new_value):
1096
1109
self._ensure_real()
1097
1110
self._real_repository.set_make_working_trees(new_value)
1113
def signatures(self):
1114
"""Decorate the real repository for now.
1116
In the long term a full blown network facility is needed to avoid
1117
creating a real repository object locally.
1120
return self._real_repository.signatures
1099
1122
@needs_write_lock
1100
1123
def sign_revision(self, revision_id, gpg_strategy):
1101
1124
self._ensure_real()
1102
1125
return self._real_repository.sign_revision(revision_id, gpg_strategy)
1129
"""Decorate the real repository for now.
1131
In the long term a full blown network facility is needed to avoid
1132
creating a real repository object locally.
1135
return self._real_repository.texts
1104
1137
@needs_read_lock
1105
1138
def get_revisions(self, revision_ids):
1106
1139
self._ensure_real()
1176
1220
raise errors.UnexpectedSmartServerResponse(response)
1179
def _serialise_search_recipe(recipe):
1180
"""Serialise a graph search recipe.
1182
:param recipe: A search recipe (start, stop, count).
1183
:return: Serialised bytes.
1185
start_keys = ' '.join(recipe[0])
1186
stop_keys = ' '.join(recipe[1])
1187
count = str(recipe[2])
1188
return '\n'.join((start_keys, stop_keys, count))
1191
def _serialise_record_stream(stream):
1192
"""Takes a record stream as returned by get_record_stream and yields bytes.
1194
# Yields bencode of (sha1, storage_kind, key, parents, build_details,
1197
# - if sha1 is None, sha1 is ''
1198
# - if parents is None, parents is 'nil' (to distinguish it from empty
1200
# - if record has no _build_details, build_details is ()
1201
for record in stream:
1205
parents = record.parents
1206
if record.parents is None:
1208
if record.storage_kind.startswith('knit-'):
1209
build_details = record._build_details
1212
struct = (sha1, record.storage_kind, record.key, parents,
1213
build_details, record.get_bytes_as(record.storage_kind))
1214
yield bencode.bencode(struct)
1217
class RemoteVersionedFiles(VersionedFiles):
1219
def __init__(self, remote_repo, vf_name):
1220
self.remote_repo = remote_repo
1221
self.vf_name = vf_name
1223
def _get_real_vf(self):
1224
self.remote_repo._ensure_real()
1225
return getattr(self.remote_repo._real_repository, self.vf_name)
1227
def add_lines(self, version_id, parents, lines, parent_texts=None,
1228
left_matching_blocks=None, nostore_sha=None, random_id=False,
1229
check_content=True):
1230
real_vf = self._get_real_vf()
1231
return real_vf.add_lines(version_id, parents, lines,
1232
parent_texts=parent_texts,
1233
left_matching_blocks=left_matching_blocks,
1234
nostore_sha=nostore_sha, random_id=random_id,
1235
check_content=check_content)
1237
def add_mpdiffs(self, records):
1238
real_vf = self._get_real_vf()
1239
return real_vf.add_mpdiffs(records)
1241
def annotate(self, key):
1242
real_vf = self._get_real_vf()
1243
return real_vf.annotate(key)
1245
def check(self, progress_bar=None):
1246
real_vf = self._get_real_vf()
1247
return real_vf.check(progress_bar=progress_bar)
1249
def get_parent_map(self, keys):
1250
real_vf = self._get_real_vf()
1251
return real_vf.get_parent_map(keys)
1253
def get_record_stream(self, keys, ordering, include_delta_closure):
1254
real_vf = self._get_real_vf()
1255
return real_vf.get_record_stream(keys, ordering, include_delta_closure)
1257
def get_sha1s(self, keys):
1258
real_vf = self._get_real_vf()
1259
return real_vf.get_sha1s(keys)
1261
def insert_record_stream(self, stream, _record_serialiser=None):
1262
lock_token = self.remote_repo._lock_token
1263
if lock_token is None:
1265
if _record_serialiser is None:
1266
_record_serialiser = _serialise_record_stream
1267
# Tee the stream, because we may need to replay it if we have to
1268
# fallback to the VFS implementation. This unfortunately means
1269
# the entire record stream will temporarily be buffered in memory, even
1270
# if we don't need to fallback.
1271
# TODO: remember if this server accepts the insert_record_stream RPC,
1272
# and if so skip the buffering. (And if not, fallback immediately,
1273
# again no buffering.)
1274
stream, fallback_stream = itertools.tee(stream)
1275
byte_stream = _record_serialiser(stream)
1276
client = self.remote_repo._client
1277
path = self.remote_repo.bzrdir._path_for_remote_call(client)
1279
response = client.call_with_body_stream(
1280
('VersionedFile.insert_record_stream', path, self.vf_name,
1281
lock_token), byte_stream)
1282
except errors.UnknownSmartMethod:
1283
real_vf = self._get_real_vf()
1284
return real_vf.insert_record_stream(fallback_stream)
1286
response_tuple, response_handler = response
1287
if response_tuple != ('ok',):
1288
raise errors.UnexpectedSmartServerResponse(response_tuple)
1290
def iter_lines_added_or_present_in_keys(self, keys, pb=None):
1291
real_vf = self._get_real_vf()
1292
return real_vf.iter_lines_added_or_present_in_keys(keys, pb=pb)
1295
real_vf = self._get_real_vf()
1296
return real_vf.keys()
1298
def make_mpdiffs(self, keys):
1299
real_vf = self._get_real_vf()
1300
return real_vf.make_mpdiffs(keys)
1303
1223
class RemoteBranchLockableFiles(LockableFiles):
1304
1224
"""A 'LockableFiles' implementation that talks to a smart server.