Skip to main content

Module service_protocol

Module service_protocol 

Source
Expand description

Messages between the wrapper and the resident commit service. What: The messages between the wrapper and the resident commit service, one JSON object per line. Why: A client sends a prepared change with a request identity and waits; the service answers with a landing, a queue position, a request to prepare again, or a failure from a closed list. The line form needs no framing library and every field is checked on read, so a damaged or hostile line is refused rather than guessed (doc/planning/cli-git-resident-service.md, “Protocol and request identity”).

In TS you’d write (pseudocode):

socket.write(JSON.stringify(encodeRequest(request)) + '\n'); const reply = decodeResponse(await readLine(socket));

Structs§

Change
What: One path a commit changes: a file to set, or a file to delete. Why: The client has already written the file’s content into the repository’s object store, so the service names the object and never reads the user’s worktree.
CommitRequest
What: A request to land one commit. Why: Every field the service needs to land it on the current branch without asking the client anything.

Enums§

ClientMessage
What a client sends.
FailureCode
The closed list of reasons the service gives for not landing a request.
ServiceMessage
What the service sends.

Constants§

ALLOWED_MODES
Modes a change may give a file.
MAX_CHANGES
The most paths one request may change.
MAX_LINE_BYTES
The longest line either side accepts, in bytes.
PROTOCOL_VERSION
The protocol version this build speaks; a service and a client agree when their versions are equal.

Functions§

decode_client
What: Reads and checks one client line. Why: The service trusts nothing from a socket: sizes, names, paths, modes and the object names are all checked.
decode_service
What: Reads one service line. Why: The client checks what it is told as strictly as the service checks what it is sent.
encode_client
What: The line for a client message. Why: One object per line, no newline inside any field.
encode_service
What: The line for a service message. Why: The same one-object form in the other direction.
is_object_name
Whether text is a full object name in hexadecimal (40 or 64 digits).
is_plain_path
Whether path is a plain repository-relative path: no leading slash, no empty, . or .. part, no NUL or newline.