~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/repository.py

  • Committer: Vincent Ladeuil
  • Date: 2009-05-05 15:31:34 UTC
  • mto: (4343.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4344.
  • Revision ID: v.ladeuil+lp@free.fr-20090505153134-q4bp4is9gywsmzrv
Clean up test for log formats.

* bzrlib/tests/blackbox/test_logformats.py:
Update tests to actual style.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import bz2
20
20
import os
21
21
import Queue
 
22
import struct
22
23
import sys
23
24
import tarfile
24
25
import tempfile
25
26
import threading
26
27
 
27
28
from bzrlib import (
28
 
    bencode,
29
29
    errors,
30
30
    graph,
31
31
    osutils,
39
39
    )
40
40
from bzrlib.repository import _strip_NULL_ghosts, network_format_registry
41
41
from bzrlib import revision as _mod_revision
 
42
from bzrlib.util import bencode
42
43
from bzrlib.versionedfile import NetworkRecordStream, record_to_fulltext_bytes
43
44
 
44
45
 
70
71
        # is expected)
71
72
        return None
72
73
 
73
 
    def recreate_search(self, repository, search_bytes, discard_excess=False):
74
 
        """Recreate a search from its serialised form.
75
 
 
76
 
        :param discard_excess: If True, and the search refers to data we don't
77
 
            have, just silently accept that fact - the verb calling
78
 
            recreate_search trusts that clients will look for missing things
79
 
            they expected and get it from elsewhere.
80
 
        """
 
74
    def recreate_search(self, repository, search_bytes):
81
75
        lines = search_bytes.split('\n')
82
76
        if lines[0] == 'ancestry-of':
83
77
            heads = lines[1:]
84
78
            search_result = graph.PendingAncestryResult(heads, repository)
85
79
            return search_result, None
86
80
        elif lines[0] == 'search':
87
 
            return self.recreate_search_from_recipe(repository, lines[1:],
88
 
                discard_excess=discard_excess)
 
81
            return self.recreate_search_from_recipe(repository, lines[1:])
89
82
        else:
90
83
            return (None, FailedSmartServerResponse(('BadSearch',)))
91
84
 
92
 
    def recreate_search_from_recipe(self, repository, lines,
93
 
        discard_excess=False):
94
 
        """Recreate a specific revision search (vs a from-tip search).
95
 
 
96
 
        :param discard_excess: If True, and the search refers to data we don't
97
 
            have, just silently accept that fact - the verb calling
98
 
            recreate_search trusts that clients will look for missing things
99
 
            they expected and get it from elsewhere.
100
 
        """
 
85
    def recreate_search_from_recipe(self, repository, lines):
101
86
        start_keys = set(lines[0].split(' '))
102
87
        exclude_keys = set(lines[1].split(' '))
103
88
        revision_count = int(lines[2])
112
97
                    break
113
98
                search.stop_searching_any(exclude_keys.intersection(next_revs))
114
99
            search_result = search.get_result()
115
 
            if (not discard_excess and
116
 
                search_result.get_recipe()[3] != revision_count):
 
100
            if search_result.get_recipe()[3] != revision_count:
117
101
                # we got back a different amount of data than expected, this
118
102
                # gets reported as NoSuchRevision, because less revisions
119
103
                # indicates missing revisions, and more should never happen as
283
267
        return SuccessfulSmartServerResponse(('ok', ), '\n'.join(lines))
284
268
 
285
269
 
286
 
class SmartServerRepositoryGetRevIdForRevno(SmartServerRepositoryReadLocked):
287
 
 
288
 
    def do_readlocked_repository_request(self, repository, revno,
289
 
            known_pair):
290
 
        """Find the revid for a given revno, given a known revno/revid pair.
291
 
        
292
 
        New in 1.17.
293
 
        """
294
 
        try:
295
 
            found_flag, result = repository.get_rev_id_for_revno(revno, known_pair)
296
 
        except errors.RevisionNotPresent, err:
297
 
            if err.revision_id != known_pair[1]:
298
 
                raise AssertionError(
299
 
                    'get_rev_id_for_revno raised RevisionNotPresent for '
300
 
                    'non-initial revision: ' + err.revision_id)
301
 
            return FailedSmartServerResponse(
302
 
                ('nosuchrevision', err.revision_id))
303
 
        if found_flag:
304
 
            return SuccessfulSmartServerResponse(('ok', result))
305
 
        else:
306
 
            earliest_revno, earliest_revid = result
307
 
            return SuccessfulSmartServerResponse(
308
 
                ('history-incomplete', earliest_revno, earliest_revid))
309
 
 
310
 
 
311
270
class SmartServerRequestHasRevision(SmartServerRepositoryRequest):
312
271
 
313
272
    def do_repository_request(self, repository, revision_id):
420
379
        repository = self._repository
421
380
        repository.lock_read()
422
381
        try:
423
 
            search_result, error = self.recreate_search(repository, body_bytes,
424
 
                discard_excess=True)
 
382
            search_result, error = self.recreate_search(repository, body_bytes)
425
383
            if error is not None:
426
384
                repository.unlock()
427
385
                return error
460
418
        for record in substream:
461
419
            if record.storage_kind in ('chunked', 'fulltext'):
462
420
                serialised = record_to_fulltext_bytes(record)
463
 
            elif record.storage_kind == 'absent':
464
 
                raise ValueError("Absent factory for %s" % (record.key,))
465
421
            else:
466
422
                serialised = record.get_bytes_as(record.storage_kind)
467
423
            if serialised: