gitproto

package
v0.13.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendAgentToReceivePackBody added in v0.13.0

func AppendAgentToReceivePackBody(body *RequestBody, helperAgent string) error

AppendAgentToReceivePackBody appends helperAgent to the agent capability on the request's first command line: the first pkt-line carrying a NUL before the flush. Shallow lines can precede it, and send-pack's stateless-rpc framing can split it across chunks, so the lines are read through the body. Only that line is copied. It leaves requests without agent= unchanged.

func AppendAgentToReceivePackRequest

func AppendAgentToReceivePackRequest(message []byte, helperAgent string) ([]byte, error)

AppendAgentToReceivePackRequest appends helperAgent to the agent capability on the first receive-pack command line. It leaves requests without agent= unchanged.

func AppendAgentToUploadPackRequest

func AppendAgentToUploadPackRequest(message []byte, helperAgent string) ([]byte, error)

AppendAgentToUploadPackRequest appends helperAgent to the agent capability in a v0/v1 upload-pack request. It leaves requests without agent= unchanged.

func AppendAgentToV2Request

func AppendAgentToV2Request(message []byte, helperAgent string) ([]byte, error)

AppendAgentToV2Request appends helperAgent to an existing v2 client-side agent line. It leaves requests without agent= unchanged.

func IsV2Advertisement

func IsV2Advertisement(p []byte) bool

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

func ReadFlushTerminatedMessage(r io.Reader) ([]byte, bool, error)

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

func ReadPostServiceAdvertisement(r io.Reader) ([]byte, error)

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 ReadSendPackRequest

func ReadSendPackRequest(r *bufio.Reader, dst *RequestBody) error

ReadSendPackRequest reads one request emitted by `git send-pack --stateless-rpc` and appends 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. Each payload is kept as its own chunk of dst rather than copied into one buffer, so the pack is held once.

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 RemoveV2FetchFeature added in v0.11.5

func RemoveV2FetchFeature(advertisement []byte, feature string) ([]byte, error)

RemoveV2FetchFeature drops feature from the fetch= capability in a v2 advertisement and leaves every other byte intact. A fetch line with no feature left becomes the bare key "fetch", which gitprotocol-v2(5) permits: capability = PKT-LINE(key[=value] LF). Advertisements without the feature come back unchanged. A server sends each capability key once, so a second fetch= line is an error.

func V2Command

func V2Command(message []byte) string

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

type RequestBody added in v0.13.0

type RequestBody struct {
	// contains filtered or unexported fields
}

RequestBody is a receive-pack request held as the chunks it was read in rather than one contiguous buffer. A push holds its pack in memory once: appending to a growing buffer would hold up to two copies while the buffer grows, and amending the agent capability would need a third.

The body is replayable — Reader returns a fresh io.ReadSeeker each time — so the transport's 401 retry and replica failover can resend it.

func ReadReceivePackRequest

func ReadReceivePackRequest(r io.Reader) (*RequestBody, error)

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 body is exactly what was on the wire — caller streams it 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 (*RequestBody) ApplyTo added in v0.13.0

func (b *RequestBody) ApplyTo(req *http.Request)

ApplyTo declares the body's size on req and lets net/http rewind it. http.NewRequest infers both only for bytes and strings readers; without them the POST goes out chunked, and a redirect that must resend the body can't.

func (*RequestBody) Len added in v0.13.0

func (b *RequestBody) Len() int64

Len returns the body's size in bytes.

func (*RequestBody) ReadAt added in v0.13.0

func (b *RequestBody) ReadAt(p []byte, off int64) (int, error)

ReadAt implements io.ReaderAt over the chunks.

func (*RequestBody) ReadFrom added in v0.13.0

func (b *RequestBody) ReadFrom(r io.Reader) (int64, error)

ReadFrom appends everything r yields until io.EOF, in bodyChunkSize blocks. Like io.Copy, it treats only io.EOF itself as the end: any other error, io.ErrUnexpectedEOF and wrapped EOFs included, means the body is incomplete and is returned, even after a full block.

func (*RequestBody) Reader added in v0.13.0

func (b *RequestBody) Reader() *io.SectionReader

Reader returns a new reader positioned at the start of the body.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL