Documentation
¶
Overview ¶
Package gitproto implements higher-level Git smart-HTTP / stateless-RPC wire helpers built on top of the pkt-line layer in github.com/go-git/go-git/v6/plumbing/format/pktline:
- v2 capability-advertisement detection (IsV2Advertisement)
- v2-request command extraction (V2Command)
- reading a flush-terminated v2 message verbatim (ReadFlushTerminatedMessage)
- stripping the smart-HTTP service announcement (ReadPostServiceAdvertisement, backed by packp.SmartReply)
- reading the receive-pack request body the helper relays
- reading the send-pack stateless-rpc outer framing
Everything here is pure Git protocol — no Entire-specific knowledge.
Index ¶
- func AppendAgentToReceivePackRequest(message []byte, helperAgent string) ([]byte, error)
- func AppendAgentToUploadPackRequest(message []byte, helperAgent string) ([]byte, error)
- func AppendAgentToV2Request(message []byte, helperAgent string) ([]byte, error)
- func IsV2Advertisement(p []byte) bool
- func ReadFlushTerminatedMessage(r io.Reader) ([]byte, bool, error)
- func ReadPostServiceAdvertisement(r io.Reader) ([]byte, error)
- func ReadReceivePackRequest(r io.Reader) ([]byte, error)
- func ReadSendPackRequest(r *bufio.Reader, dst *bytes.Buffer) error
- func V2Command(message []byte) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendAgentToReceivePackRequest ¶
AppendAgentToReceivePackRequest appends helperAgent to the agent capability on the first receive-pack command line. It leaves requests without agent= unchanged.
func AppendAgentToUploadPackRequest ¶
AppendAgentToUploadPackRequest appends helperAgent to the agent capability in a v0/v1 upload-pack request. It leaves requests without agent= unchanged.
func AppendAgentToV2Request ¶
AppendAgentToV2Request appends helperAgent to an existing v2 client-side agent line. It leaves requests without agent= unchanged.
func IsV2Advertisement ¶
IsV2Advertisement reports whether p begins with the v2 service capability line ("version 2\n"). The peek is conservative: if the length prefix is malformed or claims more bytes than p contains, we return false rather than panic.
func ReadFlushTerminatedMessage ¶
ReadFlushTerminatedMessage reads pkt-lines from r until a flush (0000), returning the concatenated raw bytes including every length prefix and the trailing flush. The boolean is false (with nil error) when r is at EOF before any byte has been read — the natural signal that the stream closed cleanly between messages.
Special lengths 0001 (delim) and 0002 (response-end) are passed through verbatim — they're part of v2 framing.
We reach for the raw bytes instead of pktline.Scanner because the helper proxies messages over HTTP unchanged; reconstructing the length prefixes from Scanner's payload-only output would re-encode and risk drift.
func ReadPostServiceAdvertisement ¶
ReadPostServiceAdvertisement reads a v0/v1 smart-HTTP info/refs body and returns the bytes that follow the service announcement plus its terminating flush — i.e. just the ref advertisement.
`git send-pack --stateless-rpc` runs the input through discover_version + get_remote_heads, which die with "protocol error: unexpected '# service=...'" if the announcement preamble is left in. Strip it once, here, so callers can feed the result straight into send-pack.
func ReadReceivePackRequest ¶
ReadReceivePackRequest reads a v0/v1 git-receive-pack request body from r: a sequence of command pkt-lines terminated by a flush, optionally followed by a raw PACK stream when at least one command is not a delete (i.e. the new OID isn't all zeros).
The returned bytes are exactly what was on the wire — caller streams them to the remote without further framing. EOF before the flush is reported (treating it as a clean close would let a truncated request look like a clean delete-only push).
func ReadSendPackRequest ¶
ReadSendPackRequest reads one request emitted by `git send-pack --stateless-rpc` and writes the unwrapped payload to dst. Send-pack wraps the receive-pack request in an outer pkt-line stream so it can mark request boundaries without closing stdout; the HTTP body is the concatenated payload of those outer packets.
Returns when the outer flush is seen. Special lengths 1/2 are tolerated and skipped (current send-pack doesn't emit them, but the shape is permissive). EOF before the flush is wrapped as io.ErrUnexpectedEOF — a truncated send-pack stdout is never a clean end.
func V2Command ¶
V2Command extracts the "command=" value from a v2 fetch / ls-refs / bundle-uri request message. The message is the bytes between two flushes (callers typically pass the buffer returned by ReadFlushTerminatedMessage). Returns "" when the message is malformed, truncated, or carries no command pktline.
Types ¶
This section is empty.