~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/repository.py

(gz) Fix test failure on alpha by correcting format string for
 gc_chk_sha1_record (Martin [gz])

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
from bzrlib import (
27
27
    bencode,
28
 
    commands,
29
28
    errors,
30
 
    estimate_compressed_size,
31
29
    graph,
32
30
    osutils,
33
31
    pack,
34
 
    trace,
35
32
    ui,
36
33
    )
37
34
from bzrlib.bzrdir import BzrDir
144
141
        finally:
145
142
            repository.unlock()
146
143
 
147
 
_lsprof_count = 0
148
144
 
149
145
class SmartServerRepositoryGetParentMap(SmartServerRepositoryRequest):
150
146
    """Bzr 1.2+ - get parent data for revisions during a graph search."""
184
180
        finally:
185
181
            repository.unlock()
186
182
 
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
 
187
        if include_missing:
 
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:
 
193
            return error
 
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)
 
199
        lines = []
 
200
        repo_graph = repository.get_graph()
189
201
        result = {}
190
202
        queried_revs = set()
191
 
        estimator = estimate_compressed_size.ZLibEstimator(max_size)
 
203
        size_so_far = 0
192
204
        next_revs = revision_ids
193
205
        first_loop_done = False
194
206
        while next_revs:
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()
230
239
                break
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
234
 
        return result
235
 
 
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
240
 
        if include_missing:
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:
246
 
            return error
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)
252
 
 
253
 
        repo_graph = repository.get_graph()
254
 
        result = self._expand_requested_revs(repo_graph, revision_ids,
255
 
                                             client_seen_revs, include_missing)
256
243
 
257
244
        # sorting trivially puts lexographically similar revision ids together.
258
245
        # Compression FTW.
259
 
        lines = []
260
246
        for revision, parents in sorted(result.items()):
261
247
            lines.append(' '.join((revision, ) + tuple(parents)))
262
248