/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/smart/request.py

Merge the fix for bug #819604 into trunk, resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
31
31
# of a SmartServerRequest subclass.
32
32
 
33
33
 
34
 
import tempfile
35
 
import thread
36
34
import threading
37
35
 
38
36
from bzrlib import (
48
46
from bzrlib.lazy_import import lazy_import
49
47
lazy_import(globals(), """
50
48
from bzrlib.bundle import serializer
 
49
 
 
50
import tempfile
 
51
import thread
51
52
""")
52
53
 
53
54
 
134
135
        It will return a SmartServerResponse if the command does not expect a
135
136
        body.
136
137
 
137
 
        :param *args: the arguments of the request.
 
138
        :param args: the arguments of the request.
138
139
        """
139
140
        self._check_enabled()
140
141
        return self.do(*args)
446
447
        return ('TokenMismatch', err.given_token, err.lock_token)
447
448
    elif isinstance(err, errors.LockContention):
448
449
        return ('LockContention',)
 
450
    elif isinstance(err, MemoryError):
 
451
        # GZ 2011-02-24: Copy bzrlib.trace -Dmem_dump functionality here?
 
452
        return ('MemoryError',)
449
453
    # Unserialisable error.  Log it, and return a generic error
450
454
    trace.log_exception_quietly()
451
 
    return ('error', str(err))
 
455
    return ('error', trace._qualified_exception_name(err.__class__, True),
 
456
        str(err))
452
457
 
453
458
 
454
459
class HelloRequest(SmartServerRequest):
486
491
        return SuccessfulSmartServerResponse((answer,))
487
492
 
488
493
 
 
494
# In the 'info' attribute, we store whether this request is 'safe' to retry if
 
495
# we get a disconnect while reading the response. It can have the values:
 
496
#   read    This is purely a read request, so retrying it is perfectly ok.
 
497
#   idem    An idempotent write request. Something like 'put' where if you put
 
498
#           the same bytes twice you end up with the same final bytes.
 
499
#   semi    This is a request that isn't strictly idempotent, but doesn't
 
500
#           result in corruption if it is retried. This is for things like
 
501
#           'lock' and 'unlock'. If you call lock, it updates the disk
 
502
#           structure. If you fail to read the response, you won't be able to
 
503
#           use the lock, because you don't have the lock token. Calling lock
 
504
#           again will fail, because the lock is already taken. However, we
 
505
#           can't tell if the server received our request or not. If it didn't,
 
506
#           then retrying the request is fine, as it will actually do what we
 
507
#           want. If it did, we will interrupt the current operation, but we
 
508
#           are no worse off than interrupting the current operation because of
 
509
#           a ConnectionReset.
 
510
#   semivfs Similar to semi, but specific to a Virtual FileSystem request.
 
511
#   stream  This is a request that takes a stream that cannot be restarted if
 
512
#           consumed. This request is 'safe' in that if we determine the
 
513
#           connection is closed before we consume the stream, we can try
 
514
#           again.
 
515
#   mutate  State is updated in a way that replaying that request results in a
 
516
#           different state. For example 'append' writes more bytes to a given
 
517
#           file. If append succeeds, it moves the file pointer.
489
518
request_handlers = registry.Registry()
490
519
request_handlers.register_lazy(
491
 
    'append', 'bzrlib.smart.vfs', 'AppendRequest')
 
520
    'append', 'bzrlib.smart.vfs', 'AppendRequest', info='mutate')
492
521
request_handlers.register_lazy(
493
522
    'Branch.get_config_file', 'bzrlib.smart.branch',
494
 
    'SmartServerBranchGetConfigFile')
 
523
    'SmartServerBranchGetConfigFile', info='read')
495
524
request_handlers.register_lazy(
496
 
    'Branch.get_parent', 'bzrlib.smart.branch', 'SmartServerBranchGetParent')
 
525
    'Branch.get_parent', 'bzrlib.smart.branch', 'SmartServerBranchGetParent',
 
526
    info='read')
497
527
request_handlers.register_lazy(
498
528
    'Branch.get_tags_bytes', 'bzrlib.smart.branch',
499
 
    'SmartServerBranchGetTagsBytes')
 
529
    'SmartServerBranchGetTagsBytes', info='read')
500
530
request_handlers.register_lazy(
501
531
    'Branch.set_tags_bytes', 'bzrlib.smart.branch',
502
 
    'SmartServerBranchSetTagsBytes')
503
 
request_handlers.register_lazy(
504
 
    'Branch.get_stacked_on_url', 'bzrlib.smart.branch', 'SmartServerBranchRequestGetStackedOnURL')
505
 
request_handlers.register_lazy(
506
 
    'Branch.last_revision_info', 'bzrlib.smart.branch', 'SmartServerBranchRequestLastRevisionInfo')
507
 
request_handlers.register_lazy(
508
 
    'Branch.lock_write', 'bzrlib.smart.branch', 'SmartServerBranchRequestLockWrite')
509
 
request_handlers.register_lazy( 'Branch.revision_history',
510
 
    'bzrlib.smart.branch', 'SmartServerRequestRevisionHistory')
511
 
request_handlers.register_lazy( 'Branch.set_config_option',
512
 
    'bzrlib.smart.branch', 'SmartServerBranchRequestSetConfigOption')
513
 
request_handlers.register_lazy( 'Branch.set_last_revision',
514
 
    'bzrlib.smart.branch', 'SmartServerBranchRequestSetLastRevision')
 
532
    'SmartServerBranchSetTagsBytes', info='idem')
 
533
request_handlers.register_lazy(
 
534
    'Branch.heads_to_fetch', 'bzrlib.smart.branch',
 
535
    'SmartServerBranchHeadsToFetch', info='read')
 
536
request_handlers.register_lazy(
 
537
    'Branch.get_stacked_on_url', 'bzrlib.smart.branch',
 
538
    'SmartServerBranchRequestGetStackedOnURL', info='read')
 
539
request_handlers.register_lazy(
 
540
    'Branch.last_revision_info', 'bzrlib.smart.branch',
 
541
    'SmartServerBranchRequestLastRevisionInfo', info='read')
 
542
request_handlers.register_lazy(
 
543
    'Branch.lock_write', 'bzrlib.smart.branch',
 
544
    'SmartServerBranchRequestLockWrite', info='semi')
 
545
request_handlers.register_lazy(
 
546
    'Branch.revision_history', 'bzrlib.smart.branch',
 
547
    'SmartServerRequestRevisionHistory', info='read')
 
548
request_handlers.register_lazy(
 
549
    'Branch.set_config_option', 'bzrlib.smart.branch',
 
550
    'SmartServerBranchRequestSetConfigOption', info='idem')
 
551
request_handlers.register_lazy(
 
552
    'Branch.set_config_option_dict', 'bzrlib.smart.branch',
 
553
    'SmartServerBranchRequestSetConfigOptionDict', info='idem')
 
554
request_handlers.register_lazy(
 
555
    'Branch.set_last_revision', 'bzrlib.smart.branch',
 
556
    'SmartServerBranchRequestSetLastRevision', info='idem')
515
557
request_handlers.register_lazy(
516
558
    'Branch.set_last_revision_info', 'bzrlib.smart.branch',
517
 
    'SmartServerBranchRequestSetLastRevisionInfo')
 
559
    'SmartServerBranchRequestSetLastRevisionInfo', info='idem')
518
560
request_handlers.register_lazy(
519
561
    'Branch.set_last_revision_ex', 'bzrlib.smart.branch',
520
 
    'SmartServerBranchRequestSetLastRevisionEx')
 
562
    'SmartServerBranchRequestSetLastRevisionEx', info='idem')
521
563
request_handlers.register_lazy(
522
564
    'Branch.set_parent_location', 'bzrlib.smart.branch',
523
 
    'SmartServerBranchRequestSetParentLocation')
 
565
    'SmartServerBranchRequestSetParentLocation', info='idem')
524
566
request_handlers.register_lazy(
525
 
    'Branch.unlock', 'bzrlib.smart.branch', 'SmartServerBranchRequestUnlock')
 
567
    'Branch.unlock', 'bzrlib.smart.branch', 'SmartServerBranchRequestUnlock',
 
568
    info='semi')
526
569
request_handlers.register_lazy(
527
570
    'BzrDir.cloning_metadir', 'bzrlib.smart.bzrdir',
528
 
    'SmartServerBzrDirRequestCloningMetaDir')
 
571
    'SmartServerBzrDirRequestCloningMetaDir', info='read')
529
572
request_handlers.register_lazy(
530
573
    'BzrDir.create_branch', 'bzrlib.smart.bzrdir',
531
 
    'SmartServerRequestCreateBranch')
 
574
    'SmartServerRequestCreateBranch', info='semi')
532
575
request_handlers.register_lazy(
533
576
    'BzrDir.create_repository', 'bzrlib.smart.bzrdir',
534
 
    'SmartServerRequestCreateRepository')
 
577
    'SmartServerRequestCreateRepository', info='semi')
535
578
request_handlers.register_lazy(
536
579
    'BzrDir.find_repository', 'bzrlib.smart.bzrdir',
537
 
    'SmartServerRequestFindRepositoryV1')
 
580
    'SmartServerRequestFindRepositoryV1', info='read')
538
581
request_handlers.register_lazy(
539
582
    'BzrDir.find_repositoryV2', 'bzrlib.smart.bzrdir',
540
 
    'SmartServerRequestFindRepositoryV2')
 
583
    'SmartServerRequestFindRepositoryV2', info='read')
541
584
request_handlers.register_lazy(
542
585
    'BzrDir.find_repositoryV3', 'bzrlib.smart.bzrdir',
543
 
    'SmartServerRequestFindRepositoryV3')
 
586
    'SmartServerRequestFindRepositoryV3', info='read')
544
587
request_handlers.register_lazy(
545
588
    'BzrDir.get_config_file', 'bzrlib.smart.bzrdir',
546
 
    'SmartServerBzrDirRequestConfigFile')
 
589
    'SmartServerBzrDirRequestConfigFile', info='read')
547
590
request_handlers.register_lazy(
548
591
    'BzrDirFormat.initialize', 'bzrlib.smart.bzrdir',
549
 
    'SmartServerRequestInitializeBzrDir')
 
592
    'SmartServerRequestInitializeBzrDir', info='semi')
550
593
request_handlers.register_lazy(
551
594
    'BzrDirFormat.initialize_ex_1.16', 'bzrlib.smart.bzrdir',
552
 
    'SmartServerRequestBzrDirInitializeEx')
553
 
request_handlers.register_lazy(
554
 
    'BzrDir.open', 'bzrlib.smart.bzrdir', 'SmartServerRequestOpenBzrDir')
555
 
request_handlers.register_lazy(
556
 
    'BzrDir.open_2.1', 'bzrlib.smart.bzrdir', 'SmartServerRequestOpenBzrDir_2_1')
 
595
    'SmartServerRequestBzrDirInitializeEx', info='semi')
 
596
request_handlers.register_lazy(
 
597
    'BzrDir.open', 'bzrlib.smart.bzrdir', 'SmartServerRequestOpenBzrDir',
 
598
    info='read')
 
599
request_handlers.register_lazy(
 
600
    'BzrDir.open_2.1', 'bzrlib.smart.bzrdir',
 
601
    'SmartServerRequestOpenBzrDir_2_1', info='read')
557
602
request_handlers.register_lazy(
558
603
    'BzrDir.open_branch', 'bzrlib.smart.bzrdir',
559
 
    'SmartServerRequestOpenBranch')
 
604
    'SmartServerRequestOpenBranch', info='read')
560
605
request_handlers.register_lazy(
561
606
    'BzrDir.open_branchV2', 'bzrlib.smart.bzrdir',
562
 
    'SmartServerRequestOpenBranchV2')
 
607
    'SmartServerRequestOpenBranchV2', info='read')
563
608
request_handlers.register_lazy(
564
609
    'BzrDir.open_branchV3', 'bzrlib.smart.bzrdir',
565
 
    'SmartServerRequestOpenBranchV3')
566
 
request_handlers.register_lazy(
567
 
    'delete', 'bzrlib.smart.vfs', 'DeleteRequest')
568
 
request_handlers.register_lazy(
569
 
    'get', 'bzrlib.smart.vfs', 'GetRequest')
570
 
request_handlers.register_lazy(
571
 
    'get_bundle', 'bzrlib.smart.request', 'GetBundleRequest')
572
 
request_handlers.register_lazy(
573
 
    'has', 'bzrlib.smart.vfs', 'HasRequest')
574
 
request_handlers.register_lazy(
575
 
    'hello', 'bzrlib.smart.request', 'HelloRequest')
576
 
request_handlers.register_lazy(
577
 
    'iter_files_recursive', 'bzrlib.smart.vfs', 'IterFilesRecursiveRequest')
578
 
request_handlers.register_lazy(
579
 
    'list_dir', 'bzrlib.smart.vfs', 'ListDirRequest')
580
 
request_handlers.register_lazy(
581
 
    'mkdir', 'bzrlib.smart.vfs', 'MkdirRequest')
582
 
request_handlers.register_lazy(
583
 
    'move', 'bzrlib.smart.vfs', 'MoveRequest')
584
 
request_handlers.register_lazy(
585
 
    'put', 'bzrlib.smart.vfs', 'PutRequest')
586
 
request_handlers.register_lazy(
587
 
    'put_non_atomic', 'bzrlib.smart.vfs', 'PutNonAtomicRequest')
588
 
request_handlers.register_lazy(
589
 
    'readv', 'bzrlib.smart.vfs', 'ReadvRequest')
590
 
request_handlers.register_lazy(
591
 
    'rename', 'bzrlib.smart.vfs', 'RenameRequest')
 
610
    'SmartServerRequestOpenBranchV3', info='read')
 
611
request_handlers.register_lazy(
 
612
    'delete', 'bzrlib.smart.vfs', 'DeleteRequest', info='semivfs')
 
613
request_handlers.register_lazy(
 
614
    'get', 'bzrlib.smart.vfs', 'GetRequest', info='read')
 
615
request_handlers.register_lazy(
 
616
    'get_bundle', 'bzrlib.smart.request', 'GetBundleRequest', info='read')
 
617
request_handlers.register_lazy(
 
618
    'has', 'bzrlib.smart.vfs', 'HasRequest', info='read')
 
619
request_handlers.register_lazy(
 
620
    'hello', 'bzrlib.smart.request', 'HelloRequest', info='read')
 
621
request_handlers.register_lazy(
 
622
    'iter_files_recursive', 'bzrlib.smart.vfs', 'IterFilesRecursiveRequest',
 
623
    info='read')
 
624
request_handlers.register_lazy(
 
625
    'list_dir', 'bzrlib.smart.vfs', 'ListDirRequest', info='read')
 
626
request_handlers.register_lazy(
 
627
    'mkdir', 'bzrlib.smart.vfs', 'MkdirRequest', info='semivfs')
 
628
request_handlers.register_lazy(
 
629
    'move', 'bzrlib.smart.vfs', 'MoveRequest', info='semivfs')
 
630
request_handlers.register_lazy(
 
631
    'put', 'bzrlib.smart.vfs', 'PutRequest', info='idem')
 
632
request_handlers.register_lazy(
 
633
    'put_non_atomic', 'bzrlib.smart.vfs', 'PutNonAtomicRequest', info='idem')
 
634
request_handlers.register_lazy(
 
635
    'readv', 'bzrlib.smart.vfs', 'ReadvRequest', info='read')
 
636
request_handlers.register_lazy(
 
637
    'rename', 'bzrlib.smart.vfs', 'RenameRequest', info='semivfs')
592
638
request_handlers.register_lazy(
593
639
    'PackRepository.autopack', 'bzrlib.smart.packrepository',
594
 
    'SmartServerPackRepositoryAutopack')
595
 
request_handlers.register_lazy('Repository.gather_stats',
596
 
                               'bzrlib.smart.repository',
597
 
                               'SmartServerRepositoryGatherStats')
598
 
request_handlers.register_lazy('Repository.get_parent_map',
599
 
                               'bzrlib.smart.repository',
600
 
                               'SmartServerRepositoryGetParentMap')
601
 
request_handlers.register_lazy(
602
 
    'Repository.get_revision_graph', 'bzrlib.smart.repository', 'SmartServerRepositoryGetRevisionGraph')
603
 
request_handlers.register_lazy(
604
 
    'Repository.has_revision', 'bzrlib.smart.repository', 'SmartServerRequestHasRevision')
605
 
request_handlers.register_lazy(
606
 
    'Repository.insert_stream', 'bzrlib.smart.repository', 'SmartServerRepositoryInsertStream')
607
 
request_handlers.register_lazy(
608
 
    'Repository.insert_stream_1.19', 'bzrlib.smart.repository', 'SmartServerRepositoryInsertStream_1_19')
609
 
request_handlers.register_lazy(
610
 
    'Repository.insert_stream_locked', 'bzrlib.smart.repository', 'SmartServerRepositoryInsertStreamLocked')
611
 
request_handlers.register_lazy(
612
 
    'Repository.is_shared', 'bzrlib.smart.repository', 'SmartServerRepositoryIsShared')
613
 
request_handlers.register_lazy(
614
 
    'Repository.lock_write', 'bzrlib.smart.repository', 'SmartServerRepositoryLockWrite')
 
640
    'SmartServerPackRepositoryAutopack', info='idem')
 
641
request_handlers.register_lazy(
 
642
    'Repository.gather_stats', 'bzrlib.smart.repository',
 
643
    'SmartServerRepositoryGatherStats', info='read')
 
644
request_handlers.register_lazy(
 
645
    'Repository.get_parent_map', 'bzrlib.smart.repository',
 
646
    'SmartServerRepositoryGetParentMap', info='read')
 
647
request_handlers.register_lazy(
 
648
    'Repository.get_revision_graph', 'bzrlib.smart.repository',
 
649
    'SmartServerRepositoryGetRevisionGraph', info='read')
 
650
request_handlers.register_lazy(
 
651
    'Repository.has_revision', 'bzrlib.smart.repository',
 
652
    'SmartServerRequestHasRevision', info='read')
 
653
request_handlers.register_lazy(
 
654
    'Repository.insert_stream', 'bzrlib.smart.repository',
 
655
    'SmartServerRepositoryInsertStream', info='stream')
 
656
request_handlers.register_lazy(
 
657
    'Repository.insert_stream_1.19', 'bzrlib.smart.repository',
 
658
    'SmartServerRepositoryInsertStream_1_19', info='stream')
 
659
request_handlers.register_lazy(
 
660
    'Repository.insert_stream_locked', 'bzrlib.smart.repository',
 
661
    'SmartServerRepositoryInsertStreamLocked', info='stream')
 
662
request_handlers.register_lazy(
 
663
    'Repository.is_shared', 'bzrlib.smart.repository',
 
664
    'SmartServerRepositoryIsShared', info='read')
 
665
request_handlers.register_lazy(
 
666
    'Repository.lock_write', 'bzrlib.smart.repository',
 
667
    'SmartServerRepositoryLockWrite', info='semi')
615
668
request_handlers.register_lazy(
616
669
    'Repository.set_make_working_trees', 'bzrlib.smart.repository',
617
 
    'SmartServerRepositorySetMakeWorkingTrees')
 
670
    'SmartServerRepositorySetMakeWorkingTrees', info='idem')
618
671
request_handlers.register_lazy(
619
 
    'Repository.unlock', 'bzrlib.smart.repository', 'SmartServerRepositoryUnlock')
 
672
    'Repository.unlock', 'bzrlib.smart.repository',
 
673
    'SmartServerRepositoryUnlock', info='semi')
620
674
request_handlers.register_lazy(
621
675
    'Repository.get_rev_id_for_revno', 'bzrlib.smart.repository',
622
 
    'SmartServerRepositoryGetRevIdForRevno')
 
676
    'SmartServerRepositoryGetRevIdForRevno', info='read')
623
677
request_handlers.register_lazy(
624
678
    'Repository.get_stream', 'bzrlib.smart.repository',
625
 
    'SmartServerRepositoryGetStream')
 
679
    'SmartServerRepositoryGetStream', info='read')
626
680
request_handlers.register_lazy(
627
681
    'Repository.get_stream_1.19', 'bzrlib.smart.repository',
628
 
    'SmartServerRepositoryGetStream_1_19')
 
682
    'SmartServerRepositoryGetStream_1_19', info='read')
629
683
request_handlers.register_lazy(
630
684
    'Repository.tarball', 'bzrlib.smart.repository',
631
 
    'SmartServerRepositoryTarball')
632
 
request_handlers.register_lazy(
633
 
    'rmdir', 'bzrlib.smart.vfs', 'RmdirRequest')
634
 
request_handlers.register_lazy(
635
 
    'stat', 'bzrlib.smart.vfs', 'StatRequest')
636
 
request_handlers.register_lazy(
637
 
    'Transport.is_readonly', 'bzrlib.smart.request', 'SmartServerIsReadonly')
 
685
    'SmartServerRepositoryTarball', info='read')
 
686
request_handlers.register_lazy(
 
687
    'rmdir', 'bzrlib.smart.vfs', 'RmdirRequest', info='semivfs')
 
688
request_handlers.register_lazy(
 
689
    'stat', 'bzrlib.smart.vfs', 'StatRequest', info='read')
 
690
request_handlers.register_lazy(
 
691
    'Transport.is_readonly', 'bzrlib.smart.request', 'SmartServerIsReadonly',
 
692
    info='read')