185
181
repository.unlock()
187
def _expand_requested_revs(self, repo_graph, revision_ids, client_seen_revs,
188
include_missing, max_size=65536):
183
def _do_repository_request(self, body_bytes):
184
repository = self._repository
185
revision_ids = set(self._revision_ids)
186
include_missing = 'include-missing:' in revision_ids
188
revision_ids.remove('include-missing:')
189
body_lines = body_bytes.split('\n')
190
search_result, error = self.recreate_search_from_recipe(
191
repository, body_lines)
192
if error is not None:
194
# TODO might be nice to start up the search again; but thats not
195
# written or tested yet.
196
client_seen_revs = set(search_result.get_keys())
197
# Always include the requested ids.
198
client_seen_revs.difference_update(revision_ids)
200
repo_graph = repository.get_graph()
190
202
queried_revs = set()
191
estimator = estimate_compressed_size.ZLibEstimator(max_size)
192
204
next_revs = revision_ids
193
205
first_loop_done = False
216
228
# add parents to the result
217
229
result[encoded_id] = parents
218
230
# Approximate the serialized cost of this revision_id.
219
line = '%s %s\n' % (encoded_id, ' '.join(parents))
220
estimator.add_content(line)
231
size_so_far += 2 + len(encoded_id) + sum(map(len, parents))
221
232
# get all the directly asked for parents, and then flesh out to
222
233
# 64K (compressed) or so. We do one level of depth at a time to
223
234
# stay in sync with the client. The 250000 magic number is
224
235
# estimated compression ratio taken from bzr.dev itself.
225
if self.no_extra_results or (first_loop_done and estimator.full()):
226
trace.mutter('size: %d, z_size: %d'
227
% (estimator._uncompressed_size_added,
228
estimator._compressed_size_added))
236
if self.no_extra_results or (
237
first_loop_done and size_so_far > 250000):
229
238
next_revs = set()
231
240
# don't query things we've already queried
232
next_revs = next_revs.difference(queried_revs)
241
next_revs.difference_update(queried_revs)
233
242
first_loop_done = True
236
def _do_repository_request(self, body_bytes):
237
repository = self._repository
238
revision_ids = set(self._revision_ids)
239
include_missing = 'include-missing:' in revision_ids
241
revision_ids.remove('include-missing:')
242
body_lines = body_bytes.split('\n')
243
search_result, error = self.recreate_search_from_recipe(
244
repository, body_lines)
245
if error is not None:
247
# TODO might be nice to start up the search again; but thats not
248
# written or tested yet.
249
client_seen_revs = set(search_result.get_keys())
250
# Always include the requested ids.
251
client_seen_revs.difference_update(revision_ids)
253
repo_graph = repository.get_graph()
254
result = self._expand_requested_revs(repo_graph, revision_ids,
255
client_seen_revs, include_missing)
257
244
# sorting trivially puts lexographically similar revision ids together.
258
245
# Compression FTW.
260
246
for revision, parents in sorted(result.items()):
261
247
lines.append(' '.join((revision, ) + tuple(parents)))