/breezy/unstable

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy/unstable

« back to all changes in this revision

Viewing changes to breezy/smart/repository.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-24 01:39:33 UTC
  • mfrom: (3815.3776.6)
  • Revision ID: jelmer@jelmer.uk-20170524013933-ir4y4tqtrsiz2ka2
New upstream snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
import bz2
22
22
import os
23
 
import Queue
 
23
try:
 
24
    import queue
 
25
except ImportError:
 
26
    import Queue as queue
24
27
import sys
25
28
import tempfile
26
29
import threading
27
30
import zlib
28
31
 
29
 
from bzrlib import (
 
32
from .. import (
30
33
    bencode,
31
34
    errors,
32
35
    estimate_compressed_size,
38
41
    ui,
39
42
    vf_search,
40
43
    )
41
 
from bzrlib.bzrdir import BzrDir
42
 
from bzrlib.smart.request import (
 
44
from ..bzrdir import BzrDir
 
45
from ..sixish import (
 
46
    reraise,
 
47
)
 
48
from .request import (
43
49
    FailedSmartServerResponse,
44
50
    SmartServerRequest,
45
51
    SuccessfulSmartServerResponse,
46
52
    )
47
 
from bzrlib.repository import _strip_NULL_ghosts, network_format_registry
48
 
from bzrlib import revision as _mod_revision
49
 
from bzrlib.versionedfile import (
 
53
from ..repository import _strip_NULL_ghosts, network_format_registry
 
54
from .. import revision as _mod_revision
 
55
from ..versionedfile import (
50
56
    ChunkedContentFactory,
51
57
    NetworkRecordStream,
52
58
    record_to_fulltext_bytes,
327
333
        """
328
334
        try:
329
335
            found_flag, result = repository.get_rev_id_for_revno(revno, known_pair)
330
 
        except errors.RevisionNotPresent, err:
 
336
        except errors.RevisionNotPresent as err:
331
337
            if err.revision_id != known_pair[1]:
332
338
                raise AssertionError(
333
339
                    'get_rev_id_for_revno raised RevisionNotPresent for '
428
434
            return FailedSmartServerResponse(('nosuchrevision', revid))
429
435
 
430
436
        body = ''
431
 
        if stats.has_key('committers'):
 
437
        if 'committers' in stats:
432
438
            body += 'committers: %d\n' % stats['committers']
433
 
        if stats.has_key('firstrev'):
 
439
        if 'firstrev' in stats:
434
440
            body += 'firstrev: %.3f %d\n' % stats['firstrev']
435
 
        if stats.has_key('latestrev'):
 
441
        if 'latestrev' in stats:
436
442
             body += 'latestrev: %.3f %d\n' % stats['latestrev']
437
 
        if stats.has_key('revisions'):
 
443
        if 'revisions' in stats:
438
444
            body += 'revisions: %d\n' % stats['revisions']
439
 
        if stats.has_key('size'):
 
445
        if 'size' in stats:
440
446
            body += 'size: %d\n' % stats['size']
441
447
 
442
448
        return SuccessfulSmartServerResponse(('ok', ), body)
458
464
        """
459
465
        try:
460
466
            text = repository.get_signature_text(revision_id)
461
 
        except errors.NoSuchRevision, err:
 
467
        except errors.NoSuchRevision as err:
462
468
            return FailedSmartServerResponse(
463
469
                ('nosuchrevision', err.revision))
464
470
        return SuccessfulSmartServerResponse(('ok', ), text)
504
510
            token = None
505
511
        try:
506
512
            token = repository.lock_write(token=token).repository_token
507
 
        except errors.LockContention, e:
 
513
        except errors.LockContention as e:
508
514
            return FailedSmartServerResponse(('LockContention',))
509
515
        except errors.UnlockableTransport:
510
516
            return FailedSmartServerResponse(('UnlockableTransport',))
511
 
        except errors.LockFailed, e:
 
517
        except errors.LockFailed as e:
512
518
            return FailedSmartServerResponse(('LockFailed',
513
519
                str(e.lock), str(e.why)))
514
520
        if token is not None:
584
590
            source = repository._get_source(self._to_format)
585
591
            stream = source.get_stream(search_result)
586
592
        except Exception:
587
 
            exc_info = sys.exc_info()
588
593
            try:
589
594
                # On non-error, unlocking is done by the body stream handler.
590
595
                repository.unlock()
591
596
            finally:
592
 
                raise exc_info[0], exc_info[1], exc_info[2]
 
597
                raise
593
598
        return SuccessfulSmartServerResponse(('ok',),
594
599
            body_stream=self.body_stream(stream, repository))
595
600
 
598
603
        try:
599
604
            for bytes in byte_stream:
600
605
                yield bytes
601
 
        except errors.RevisionNotPresent, e:
 
606
        except errors.RevisionNotPresent as e:
602
607
            # This shouldn't be able to happen, but as we don't buffer
603
608
            # everything it can in theory happen.
604
609
            repository.unlock()
778
783
    def do_repository_request(self, repository, token):
779
784
        try:
780
785
            repository.lock_write(token=token)
781
 
        except errors.TokenMismatch, e:
 
786
        except errors.TokenMismatch as e:
782
787
            return FailedSmartServerResponse(('TokenMismatch',))
783
788
        repository.dont_leave_lock_in_place()
784
789
        repository.unlock()
887
892
        tokens = [token for token in resume_tokens.split(' ') if token]
888
893
        self.tokens = tokens
889
894
        self.repository = repository
890
 
        self.queue = Queue.Queue()
 
895
        self.queue = queue.Queue()
891
896
        self.insert_thread = threading.Thread(target=self._inserter_thread)
892
897
        self.insert_thread.start()
893
898
 
918
923
        if self.insert_thread is not None:
919
924
            self.insert_thread.join()
920
925
        if not self.insert_ok:
921
 
            exc_info = self.insert_exception
922
 
            raise exc_info[0], exc_info[1], exc_info[2]
 
926
            try:
 
927
                reraise(*self.insert_exception)
 
928
            finally:
 
929
                del self.insert_exception
923
930
        write_group_tokens, missing_keys = self.insert_result
924
931
        if write_group_tokens or missing_keys:
925
932
            # bzip needed? missing keys should typically be a small set.
1040
1047
        try:
1041
1048
            try:
1042
1049
                repository.resume_write_group(write_group_tokens)
1043
 
            except errors.UnresumableWriteGroup, e:
 
1050
            except errors.UnresumableWriteGroup as e:
1044
1051
                return FailedSmartServerResponse(
1045
1052
                    ('UnresumableWriteGroup', e.write_groups, e.reason))
1046
1053
            try:
1067
1074
        try:
1068
1075
            try:
1069
1076
                repository.resume_write_group(write_group_tokens)
1070
 
            except errors.UnresumableWriteGroup, e:
 
1077
            except errors.UnresumableWriteGroup as e:
1071
1078
                return FailedSmartServerResponse(
1072
1079
                    ('UnresumableWriteGroup', e.write_groups, e.reason))
1073
1080
                repository.abort_write_group()
1088
1095
        try:
1089
1096
            try:
1090
1097
                repository.resume_write_group(write_group_tokens)
1091
 
            except errors.UnresumableWriteGroup, e:
 
1098
            except errors.UnresumableWriteGroup as e:
1092
1099
                return FailedSmartServerResponse(
1093
1100
                    ('UnresumableWriteGroup', e.write_groups, e.reason))
1094
1101
            else:
1118
1125
    def do_repository_request(self, repository, lock_token):
1119
1126
        try:
1120
1127
            repository.lock_write(token=lock_token)
1121
 
        except errors.TokenLockingNotSupported, e:
 
1128
        except errors.TokenLockingNotSupported as e:
1122
1129
            return FailedSmartServerResponse(
1123
1130
                ('TokenLockingNotSupported', ))
1124
1131
        try: