~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/repository.py

  • Committer: Andrew Bennetts
  • Date: 2009-06-10 10:45:45 UTC
  • mto: This revision was merged to the branch mainline in revision 4446.
  • Revision ID: andrew.bennetts@canonical.com-20090610104545-idppwhjfv7iiz1f4
Add Repository.get_rev_id_for_revno RPC, removes VFS calls from 'pull -r 123' case.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
    SmartServerRequest,
39
39
    SuccessfulSmartServerResponse,
40
40
    )
41
 
from bzrlib.repository import _strip_NULL_ghosts, network_format_registry
 
41
from bzrlib.repository import (
 
42
    _iter_for_revno,
 
43
    network_format_registry,
 
44
    _strip_NULL_ghosts,
 
45
    )
42
46
from bzrlib import revision as _mod_revision
43
47
from bzrlib.versionedfile import NetworkRecordStream, record_to_fulltext_bytes
44
48
 
284
288
        return SuccessfulSmartServerResponse(('ok', ), '\n'.join(lines))
285
289
 
286
290
 
 
291
class SmartServerRepositoryGetRevIdForRevno(SmartServerRepositoryReadLocked):
 
292
 
 
293
    def do_readlocked_repository_request(self, repository, revno,
 
294
            known_pair):
 
295
        """Find the revid for a given revno, given a known revno/revid pair.
 
296
        
 
297
        New in 1.16.
 
298
        """
 
299
        known_revno, known_revid = known_pair
 
300
        history = [known_revid]
 
301
        distance_from_known = known_revno - revno
 
302
        # XXX: handle distance_from_known < 0, etc
 
303
        try:
 
304
            _iter_for_revno(repository, history, stop_index=revno)
 
305
        except errors.RevisionNotPresent, err:
 
306
            # A stacked repository, or a left-hand ghost.  Either way, even
 
307
            # though the named revision isn't in this repo, we know it's the
 
308
            # next step in this left-hand history.  The client can probably
 
309
            # find this revision in a fallback repository.
 
310
            if history[-1] == err.revision_id:
 
311
                raise AssertionError(
 
312
                    'revision_id of RevisionNotPresent err already in history '
 
313
                    'from _iter_for_revno.')
 
314
            history.append(err.revision_id)
 
315
        if len(history) < distance_from_known:
 
316
            earliest_revno = known_revno - len(history)
 
317
            return SuccessfulSmartServerResponse(
 
318
                ('history-incomplete', earliest_revno, history[-1]))
 
319
        return SuccessfulSmartServerResponse(('ok', history[-1],))
 
320
 
 
321
 
287
322
class SmartServerRequestHasRevision(SmartServerRepositoryRequest):
288
323
 
289
324
    def do_repository_request(self, repository, revision_id):