mercurial/repository.py
author Gregory Szorc <gregory.szorc@gmail.com>
Sun, 13 Aug 2017 11:04:42 -0700
changeset 33822 558f5b2ee10e
parent 33821 f257943e47ab
child 33823 a0aad86b3b6a
permissions -rw-r--r--
repository: formalize wire protocol interface There are a well-defined set of commands constituting the wire protocol. Interaction with these and methods for calling them in batches are exposed via methods on peer instances. Let's formalize support for these features in abstract classes. The command parts come from the existing wireproto.wirepeer class. The batch methods come from peer.peerrepository. Ample documentation has been added as part of defining the interfaces. # no-check-commit Differential Revision: https://phab.mercurial-scm.org/D333
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33821
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
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    12
class _basepeer(object):
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    13
    """Represents a "connection" to a repository.
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    14
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    15
    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
    16
    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
    17
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    18
    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
    19
    outside of this module.
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    20
    """
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    21
    __metaclass__ = abc.ABCMeta
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
    @abc.abstractproperty
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    24
    def ui(self):
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    25
        """ui.ui instance."""
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    26
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    27
    @abc.abstractmethod
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    28
    def url(self):
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    29
        """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
    30
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    31
        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
    32
        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
    33
        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
    34
        data leakage.
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
        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
    37
        value.
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    38
        """
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    39
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    40
    @abc.abstractmethod
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    41
    def local(self):
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    42
        """Returns a local repository instance.
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
        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
    45
        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
    46
        """
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    47
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    48
    @abc.abstractmethod
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    49
    def peer(self):
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    50
        """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
    51
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    52
        Most implementations will ``return self``.
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    53
        """
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    54
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    55
    @abc.abstractmethod
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    56
    def canpush(self):
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    57
        """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
    58
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    59
    @abc.abstractmethod
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    60
    def close(self):
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    61
        """Close the connection to this peer.
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    62
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    63
        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
    64
        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
    65
        """
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    66
33822
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    67
class _basewirecommands(object):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    68
    """Client-side interface for communicating over the wire protocol.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    69
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    70
    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: 33821
diff changeset
    71
    methods commonly call wire protocol commands of the same name.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    72
    """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    73
    __metaclass__ = abc.ABCMeta
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    74
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    75
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    76
    def branchmap(self):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    77
        """Obtain heads in named branches.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    78
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    79
        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: 33821
diff changeset
    80
        heads on that branch.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    81
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    82
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    83
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    84
    def capabilities(self):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    85
        """Obtain capabilities of the peer.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    86
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    87
        Returns a set of string capabilities.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    88
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    89
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    90
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    91
    def debugwireargs(self, one, two, three=None, four=None, five=None):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    92
        """Used to facilitate debugging of arguments passed over the wire."""
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    93
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    94
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    95
    def getbundle(self, source, **kwargs):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    96
        """Obtain remote repository data as a bundle.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    97
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
    98
        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: 33821
diff changeset
    99
        the peer to the local repository
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   100
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   101
        Returns a generator of bundle data.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   102
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   103
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   104
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   105
    def heads(self):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   106
        """Determine all known head revisions in the peer.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   107
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   108
        Returns an iterable of binary nodes.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   109
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   110
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   111
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   112
    def known(self, nodes):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   113
        """Determine whether multiple nodes are known.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   114
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   115
        Accepts an iterable of nodes whose presence to check for.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   116
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   117
        Returns an iterable of booleans indicating of the corresponding node
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   118
        at that index is known to the peer.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   119
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   120
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   121
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   122
    def listkeys(self, namespace):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   123
        """Obtain all keys in a pushkey namespace.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   124
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   125
        Returns an iterable of key names.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   126
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   127
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   128
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   129
    def lookup(self, key):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   130
        """Resolve a value to a known revision.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   131
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   132
        Returns a binary node of the resolved revision on success.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   133
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   134
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   135
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   136
    def pushkey(self, namespace, key, old, new):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   137
        """Set a value using the ``pushkey`` protocol.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   138
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   139
        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: 33821
diff changeset
   140
        the old and new values for that key.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   141
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   142
        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: 33821
diff changeset
   143
        namespace.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   144
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   145
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   146
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   147
    def stream_out(self):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   148
        """Obtain streaming clone data.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   149
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   150
        Successful result should be a generator of data chunks.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   151
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   152
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   153
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   154
    def unbundle(self, bundle, heads, url):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   155
        """Transfer repository data to the peer.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   156
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   157
        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: 33821
diff changeset
   158
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   159
        Returns the integer number of heads added to the peer.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   160
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   161
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   162
class _baselegacywirecommands(object):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   163
    """Interface for implementing support for legacy wire protocol commands.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   164
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   165
    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: 33821
diff changeset
   166
    used by modern clients. To facilitate identifying which commands are
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   167
    legacy, the interfaces are split.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   168
    """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   169
    __metaclass__ = abc.ABCMeta
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   170
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   171
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   172
    def between(self, pairs):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   173
        """Obtain nodes between pairs of nodes.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   174
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   175
        ``pairs`` is an iterable of node pairs.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   176
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   177
        Returns an iterable of iterables of nodes corresponding to each
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   178
        requested pair.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   179
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   180
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   181
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   182
    def branches(self, nodes):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   183
        """Obtain ancestor changesets of specific nodes back to a branch point.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   184
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   185
        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: 33821
diff changeset
   186
        a DAG root or is a merge.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   187
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   188
        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: 33821
diff changeset
   189
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   190
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   191
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   192
    def changegroup(self, nodes, kind):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   193
        """Obtain a changegroup with data for descendants of specified nodes."""
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   194
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   195
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   196
    def changegroupsubset(self, bases, heads, kind):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   197
        pass
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   198
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   199
class peer(_basepeer, _basewirecommands):
33821
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   200
    """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
   201
33822
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   202
    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: 33821
diff changeset
   203
    interface.
33821
f257943e47ab repository: formalize peer interface with abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   204
    """
33822
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   205
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   206
    @abc.abstractmethod
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   207
    def iterbatch(self):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   208
        """Obtain an object to be used for multiple method calls.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   209
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   210
        Various operations call several methods on peer instances. If each
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   211
        method call were performed immediately and serially, this would
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   212
        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: 33821
diff changeset
   213
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   214
        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: 33821
diff changeset
   215
        round trips or to facilitate concurrent execution.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   216
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   217
        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: 33821
diff changeset
   218
        perform batched method calls.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   219
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   220
        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: 33821
diff changeset
   221
        batchable methods and queues them instead of performing them
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   222
        immediately. This proxy object has a ``submit`` method that will
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   223
        perform all queued batchable method calls. A ``results()`` method
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   224
        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: 33821
diff changeset
   225
        of results in the order they were called.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   226
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   227
        Not all peers or wire protocol implementations may actually batch method
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   228
        calls. However, they must all support this API.
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   229
        """
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   230
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   231
class legacypeer(peer, _baselegacywirecommands):
558f5b2ee10e repository: formalize wire protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33821
diff changeset
   232
    """peer but with support for legacy wire protocol commands."""