mercurial/repository.py
author Saurabh Singh <singhsrb@fb.com>
Tue, 03 Oct 2017 13:30:36 -0700
changeset 34451 533f32937182
parent 33802 a0aad86b3b6a
child 37181 0dfb5672f015
permissions -rw-r--r--
test-setdiscovery: make test compatible with chg The test checks the output of the blackbox extension which will contain logs corresponding to chg in case chg is running. Therefore, this commit modifies the test to take chg into consideration while working with the blackbox extension. Test Plan: Ran the test 'test-setdiscovery.t' with and without the '--chg' option. Differential Revision: https://phab.mercurial-scm.org/D926
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33800
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     1
# repository.py - Interfaces and base classes for repositories and peers.
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     2
#
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     3
# Copyright 2017 Gregory Szorc <gregory.szorc@gmail.com>
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     4
#
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     7
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     8
from __future__ import absolute_import
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     9
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    10
import abc
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    11
33802
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
    12
from .i18n import _
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
    13
from . import (
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
    14
    error,
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
    15
)
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
    16
33800
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    17
class _basepeer(object):
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    18
    """Represents a "connection" to a repository.
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    19
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    20
    This is the base interface for representing a connection to a repository.
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    21
    It holds basic properties and methods applicable to all peer types.
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    22
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    23
    This is not a complete interface definition and should not be used
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    24
    outside of this module.
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    25
    """
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    26
    __metaclass__ = abc.ABCMeta
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    27
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    28
    @abc.abstractproperty
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    29
    def ui(self):
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    30
        """ui.ui instance."""
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    31
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    32
    @abc.abstractmethod
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    33
    def url(self):
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    34
        """Returns a URL string representing this peer.
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    35
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    36
        Currently, implementations expose the raw URL used to construct the
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    37
        instance. It may contain credentials as part of the URL. The
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    38
        expectations of the value aren't well-defined and this could lead to
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    39
        data leakage.
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    40
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    41
        TODO audit/clean consumers and more clearly define the contents of this
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    42
        value.
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    43
        """
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    44
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    45
    @abc.abstractmethod
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    46
    def local(self):
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    47
        """Returns a local repository instance.
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    48
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    49
        If the peer represents a local repository, returns an object that
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    50
        can be used to interface with it. Otherwise returns ``None``.
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    51
        """
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    52
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    53
    @abc.abstractmethod
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    54
    def peer(self):
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    55
        """Returns an object conforming to this interface.
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    56
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    57
        Most implementations will ``return self``.
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    58
        """
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    59
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    60
    @abc.abstractmethod
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    61
    def canpush(self):
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    62
        """Returns a boolean indicating if this peer can be pushed to."""
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    63
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    64
    @abc.abstractmethod
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    65
    def close(self):
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    66
        """Close the connection to this peer.
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    67
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    68
        This is called when the peer will no longer be used. Resources
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    69
        associated with the peer should be cleaned up.
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    70
        """
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    71
33801
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    72
class _basewirecommands(object):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    73
    """Client-side interface for communicating over the wire protocol.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    74
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    75
    This interface is used as a gateway to the Mercurial wire protocol.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    76
    methods commonly call wire protocol commands of the same name.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    77
    """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    78
    __metaclass__ = abc.ABCMeta
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    79
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    80
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    81
    def branchmap(self):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    82
        """Obtain heads in named branches.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    83
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    84
        Returns a dict mapping branch name to an iterable of nodes that are
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    85
        heads on that branch.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    86
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    87
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    88
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    89
    def capabilities(self):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    90
        """Obtain capabilities of the peer.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    91
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    92
        Returns a set of string capabilities.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    93
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    94
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    95
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    96
    def debugwireargs(self, one, two, three=None, four=None, five=None):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    97
        """Used to facilitate debugging of arguments passed over the wire."""
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    98
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
    99
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   100
    def getbundle(self, source, **kwargs):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   101
        """Obtain remote repository data as a bundle.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   102
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   103
        This command is how the bulk of repository data is transferred from
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   104
        the peer to the local repository
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   105
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   106
        Returns a generator of bundle data.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   107
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   108
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   109
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   110
    def heads(self):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   111
        """Determine all known head revisions in the peer.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   112
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   113
        Returns an iterable of binary nodes.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   114
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   115
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   116
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   117
    def known(self, nodes):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   118
        """Determine whether multiple nodes are known.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   119
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   120
        Accepts an iterable of nodes whose presence to check for.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   121
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   122
        Returns an iterable of booleans indicating of the corresponding node
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   123
        at that index is known to the peer.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   124
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   125
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   126
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   127
    def listkeys(self, namespace):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   128
        """Obtain all keys in a pushkey namespace.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   129
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   130
        Returns an iterable of key names.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   131
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   132
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   133
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   134
    def lookup(self, key):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   135
        """Resolve a value to a known revision.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   136
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   137
        Returns a binary node of the resolved revision on success.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   138
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   139
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   140
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   141
    def pushkey(self, namespace, key, old, new):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   142
        """Set a value using the ``pushkey`` protocol.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   143
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   144
        Arguments correspond to the pushkey namespace and key to operate on and
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   145
        the old and new values for that key.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   146
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   147
        Returns a string with the peer result. The value inside varies by the
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   148
        namespace.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   149
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   150
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   151
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   152
    def stream_out(self):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   153
        """Obtain streaming clone data.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   154
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   155
        Successful result should be a generator of data chunks.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   156
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   157
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   158
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   159
    def unbundle(self, bundle, heads, url):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   160
        """Transfer repository data to the peer.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   161
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   162
        This is how the bulk of data during a push is transferred.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   163
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   164
        Returns the integer number of heads added to the peer.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   165
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   166
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   167
class _baselegacywirecommands(object):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   168
    """Interface for implementing support for legacy wire protocol commands.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   169
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   170
    Wire protocol commands transition to legacy status when they are no longer
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   171
    used by modern clients. To facilitate identifying which commands are
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   172
    legacy, the interfaces are split.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   173
    """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   174
    __metaclass__ = abc.ABCMeta
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   175
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   176
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   177
    def between(self, pairs):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   178
        """Obtain nodes between pairs of nodes.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   179
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   180
        ``pairs`` is an iterable of node pairs.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   181
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   182
        Returns an iterable of iterables of nodes corresponding to each
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   183
        requested pair.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   184
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   185
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   186
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   187
    def branches(self, nodes):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   188
        """Obtain ancestor changesets of specific nodes back to a branch point.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   189
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   190
        For each requested node, the peer finds the first ancestor node that is
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   191
        a DAG root or is a merge.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   192
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   193
        Returns an iterable of iterables with the resolved values for each node.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   194
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   195
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   196
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   197
    def changegroup(self, nodes, kind):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   198
        """Obtain a changegroup with data for descendants of specified nodes."""
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   199
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   200
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   201
    def changegroupsubset(self, bases, heads, kind):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   202
        pass
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   203
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   204
class peer(_basepeer, _basewirecommands):
33800
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   205
    """Unified interface and base class for peer repositories.
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   206
33801
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   207
    All peer instances must inherit from this class and conform to its
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   208
    interface.
33800
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   209
    """
33801
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   210
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   211
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   212
    def iterbatch(self):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   213
        """Obtain an object to be used for multiple method calls.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   214
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   215
        Various operations call several methods on peer instances. If each
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   216
        method call were performed immediately and serially, this would
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   217
        require round trips to remote peers and/or would slow down execution.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   218
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   219
        Some peers have the ability to "batch" method calls to avoid costly
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   220
        round trips or to facilitate concurrent execution.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   221
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   222
        This method returns an object that can be used to indicate intent to
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   223
        perform batched method calls.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   224
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   225
        The returned object is a proxy of this peer. It intercepts calls to
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   226
        batchable methods and queues them instead of performing them
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   227
        immediately. This proxy object has a ``submit`` method that will
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   228
        perform all queued batchable method calls. A ``results()`` method
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   229
        exposes the results of queued/batched method calls. It is a generator
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   230
        of results in the order they were called.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   231
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   232
        Not all peers or wire protocol implementations may actually batch method
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   233
        calls. However, they must all support this API.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   234
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   235
33802
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   236
    def capable(self, name):
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   237
        """Determine support for a named capability.
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   238
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   239
        Returns ``False`` if capability not supported.
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   240
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   241
        Returns ``True`` if boolean capability is supported. Returns a string
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   242
        if capability support is non-boolean.
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   243
        """
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   244
        caps = self.capabilities()
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   245
        if name in caps:
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   246
            return True
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   247
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   248
        name = '%s=' % name
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   249
        for cap in caps:
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   250
            if cap.startswith(name):
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   251
                return cap[len(name):]
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   252
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   253
        return False
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   254
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   255
    def requirecap(self, name, purpose):
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   256
        """Require a capability to be present.
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   257
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   258
        Raises a ``CapabilityError`` if the capability isn't present.
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   259
        """
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   260
        if self.capable(name):
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   261
            return
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   262
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   263
        raise error.CapabilityError(
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   264
            _('cannot %s; remote repository does not support the %r '
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   265
              'capability') % (purpose, name))
a0aad86b3b6a repository: implement generic capability methods on peer class
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33801
diff changeset
   266
33801
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   267
class legacypeer(peer, _baselegacywirecommands):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33800
diff changeset
   268
    """peer but with support for legacy wire protocol commands."""