class documentation

A graph walker that knows the git protocol.

As a graph walker, this class implements ack(), next(), and reset(). It also contains some base methods for interacting with the wire and walking the commit tree.

The work of determining which acks to send is passed on to the implementation instance stored in _impl. The reason for this is that we do not know at object creation time what ack level the protocol requires. A call to set_ack_type() is required to set up the implementation, before any calls to next() or ack() are made.

Method __init__ Initialize a ProtocolGraphWalker.
Method ack Acknowledge a have reference.
Method all_wants_satisfied Check whether all the current wants are satisfied by a set of haves.
Method determine_wants Determine the wants for a set of heads.
Method handle_done Handle the 'done' command.
Method nak Send a NAK response.
Method next Get the next SHA from the graph walker.
Method notify_done Notify that the client sent 'done'.
Method read_proto_line Read a line from the wire.
Method reset Reset the graph walker cache.
Method send_ack Send an ACK to the client.
Method send_nak Send a NAK to the client.
Method set_ack_type Set the acknowledgment type for the graph walker.
Method set_wants Set the list of wanted objects.
Method unread_proto_line Push a command back to be read again.
Method update_shallow Update shallow/unshallow information to the client.
Instance Variable advertise_refs Undocumented
Instance Variable client_shallow Undocumented
Instance Variable get_peeled Undocumented
Instance Variable get_symrefs Undocumented
Instance Variable handler Undocumented
Instance Variable proto Undocumented
Instance Variable shallow Undocumented
Instance Variable stateless_rpc Undocumented
Instance Variable store Undocumented
Instance Variable unshallow Undocumented
Method _handle_shallow_request Handle shallow clone requests from the client.
Instance Variable _cache Undocumented
Instance Variable _cache_index Undocumented
Instance Variable _cached Undocumented
Instance Variable _impl Undocumented
Instance Variable _wants Undocumented
def __init__(self, handler: UploadPackHandler, object_store: ObjectContainer, get_peeled: Callable[[bytes], ObjectID | None], get_symrefs: Callable[[], dict[Ref, Ref]]):

Initialize a ProtocolGraphWalker.

Parameters
handler:UploadPackHandlerProtocol handler instance
object_store:ObjectContainerObject store for retrieving objects
get_peeled:Callable[[bytes], ObjectID | None]Function to get peeled refs
get_symrefs:Callable[[], dict[Ref, Ref]]Function to get symbolic refs
def ack(self, have_ref: ObjectID):

Acknowledge a have reference.

Parameters
have_ref:ObjectIDSHA to acknowledge (40 bytes hex for SHA-1, 64 bytes for SHA-256)
Raises
ValueErrorIf have_ref is not a valid length
def all_wants_satisfied(self, haves: AbstractSet[ObjectID]) -> bool:

Check whether all the current wants are satisfied by a set of haves.

Note: Wants are specified with set_wants rather than passed in since
in the current interface they are determined outside this class.
Parameters
haves:AbstractSet[ObjectID]A set of commits we know the client has.
Returns
boolUndocumented
def determine_wants(self, heads: Mapping[Ref, ObjectID], depth: int | None = None) -> list[ObjectID]:

Determine the wants for a set of heads.

The given heads are advertised to the client, who then specifies which refs they want using 'want' lines. This portion of the protocol is the same regardless of ack type, and in fact is used to set the ack type of the ProtocolGraphWalker.

If the client has the 'shallow' capability, this method also reads and responds to the 'shallow' and 'deepen' lines from the client. These are not part of the wants per se, but they set up necessary state for walking the graph. Additionally, later code depends on this method consuming everything up to the first 'have' line.

Returns: a list of SHA1s requested by the client

Parameters
heads:Mapping[Ref, ObjectID]a dict of refname->SHA1 to advertise
depth:int | NoneMaximum depth for shallow clones
Returns
list[ObjectID]Undocumented
def handle_done(self, done_required: bool, done_received: bool) -> bool:

Handle the 'done' command.

Returns: True if done handling succeeded

Parameters
done_required:boolWhether done is required
done_received:boolWhether done was received
Returns
boolUndocumented
def nak(self):

Send a NAK response.

def next(self) -> ObjectID | None:

Get the next SHA from the graph walker.

Returns: Next SHA or None if done

def notify_done(self):

Notify that the client sent 'done'.

def read_proto_line(self, allowed: Iterable[bytes | None] | None) -> tuple[bytes | None, bytes | int | None]:

Read a line from the wire.

Returns: A tuple of (command, value); see _split_proto_line.

Parameters
allowed:Iterable[bytes | None] | NoneAn iterable of command names that should be allowed.
Returns
tuple[bytes | None, bytes | int | None]Undocumented
Raises
UnexpectedCommandErrorIf an error occurred reading the line.
def reset(self):

Reset the graph walker cache.

def send_ack(self, sha: ObjectID, ack_type: bytes = b''):

Send an ACK to the client.

Parameters
sha:ObjectIDSHA to acknowledge
ack_type:bytesType of ACK (e.g., b'continue', b'ready')
def send_nak(self):

Send a NAK to the client.

def set_ack_type(self, ack_type: int):

Set the acknowledgment type for the graph walker.

Parameters
ack_type:intOne of SINGLE_ACK, MULTI_ACK, or MULTI_ACK_DETAILED
def set_wants(self, wants: list[ObjectID]):

Set the list of wanted objects.

Parameters
wants:list[ObjectID]List of wanted object SHAs
def unread_proto_line(self, command: bytes, value: bytes | int):

Push a command back to be read again.

Parameters
command:bytesCommand name
value:bytes | intCommand value
def update_shallow(self, new_shallow: AbstractSet[ObjectID], unshallow: AbstractSet[ObjectID]):

Update shallow/unshallow information to the client.

Parameters
new_shallow:AbstractSet[ObjectID]Set of newly shallow commits
unshallow:AbstractSet[ObjectID]Set of commits to unshallow
advertise_refs =

Undocumented

client_shallow: set[ObjectID] =

Undocumented

get_peeled =

Undocumented

get_symrefs =

Undocumented

handler =

Undocumented

proto =

Undocumented

shallow: set[ObjectID] =

Undocumented

stateless_rpc =

Undocumented

Undocumented

unshallow: set[ObjectID] =

Undocumented

def _handle_shallow_request(self, wants: Sequence[ObjectID]):

Handle shallow clone requests from the client.

Parameters
wants:Sequence[ObjectID]List of wanted object SHAs
_cache: list[ObjectID] =

Undocumented

_cache_index: int =

Undocumented

_cached: bool =

Undocumented

Undocumented

_wants: list[ObjectID] =

Undocumented