181
185
repository.unlock()
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()
187
def _expand_requested_revs(self, repo_graph, revision_ids, client_seen_revs,
188
include_missing, max_size=65536):
202
190
queried_revs = set()
191
estimator = estimate_compressed_size.ZLibEstimator(max_size)
204
192
next_revs = revision_ids
205
193
first_loop_done = False
228
216
# add parents to the result
229
217
result[encoded_id] = parents
230
218
# Approximate the serialized cost of this revision_id.
231
size_so_far += 2 + len(encoded_id) + sum(map(len, parents))
219
line = '%s %s\n' % (encoded_id, ' '.join(parents))
220
estimator.add_content(line)
232
221
# get all the directly asked for parents, and then flesh out to
233
222
# 64K (compressed) or so. We do one level of depth at a time to
234
223
# stay in sync with the client. The 250000 magic number is
235
224
# estimated compression ratio taken from bzr.dev itself.
236
if self.no_extra_results or (
237
first_loop_done and size_so_far > 250000):
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))
238
229
next_revs = set()
240
231
# don't query things we've already queried
241
232
next_revs = next_revs.difference(queried_revs)
242
233
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)
244
257
# sorting trivially puts lexographically similar revision ids together.
245
258
# Compression FTW.
246
260
for revision, parents in sorted(result.items()):
247
261
lines.append(' '.join((revision, ) + tuple(parents)))