Documentation
¶
Overview ¶
Package gitproto serves Git wire protocol v2 (fetch side) from a Repository, over any transport that gives an io.Reader and an io.Writer.
It knows nothing about forges, users or permissions: the caller decides who may reach which repository and mounts Serve (stateful: ssh, stdio, git://) or Advertise plus ServeRequest (stateless: smart HTTP) on its transport.
Supported: capability advertisement, ls-refs (peel, symrefs, ref-prefix, unborn), fetch (want, have, done, thin-pack, no-progress, include-tag, ofs-delta). Everything else is refused by name with an "ERR" pkt-line: shallow and deepen*, filter, want-ref, sideband-all, packfile-uris, wait-for-done, object-info, bundle-uri, server-option, any object format but sha1, and protocol versions 0 and 1.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultLimits = Limits{
MaxRequestBytes: 8 << 20,
MaxRequestLines: 100_000,
MaxWants: 50_000,
MaxHaves: 50_000,
MaxRefPrefixes: 1024,
}
DefaultLimits are used for every zero field of Limits.
Functions ¶
Types ¶
type FetchArgs ¶
type FetchArgs struct {
Wants []string
Haves []string
Done bool
ThinPack bool
NoProgress bool
IncludeTag bool
OfsDelta bool
}
FetchArgs are the parsed arguments of a fetch request.
type GitRepo ¶
type GitRepo struct {
// Dir is the repository's git directory (a bare repository, or a
// .git directory).
Dir string
// Git is the git executable. Empty means "git" found on PATH.
Git string
// PackThreads is passed to git pack-objects as --threads. Zero leaves
// git's default (all cores).
PackThreads int
// NoNativeRefs makes Refs always ask git, never read the ref files.
NoNativeRefs bool
}
GitRepo is a Repository backed by the git binary on an on-disk repository.
Milestone 1 delegates object reading and pack building to git: every command line is fixed in this file, nothing from the wire reaches argv (object ids are validated 40-hex strings written to stdin), no shell is involved, and git runs with a minimal environment and no user or system configuration.
func (*GitRepo) CommonCommits ¶
CommonCommits implements Repository.
func (*GitRepo) Refs ¶
Refs implements Repository. A repository using the files ref backend is read directly (refs_files.go); anything that reader does not fully understand, reftable included, is answered by git.
func (*GitRepo) RefsUnpeeled ¶
RefsUnpeeled is Refs without the peeling that costs a process: a loose ref outside refs/heads/ may lack its Peeled id. Every ID is exact, so it answers "is this object a ref's tip" without spawning git; serveFetch asks it first and falls back to Refs only for a want that is not a tip.
type Limits ¶
type Limits struct {
// MaxRequestBytes bounds the bytes read for one command request.
MaxRequestBytes int64
// MaxRequestLines bounds the pkt-lines of one command request.
MaxRequestLines int
// MaxWants bounds "want" lines of a fetch request.
MaxWants int
// MaxHaves bounds "have" lines of a fetch request.
MaxHaves int
// MaxRefPrefixes bounds "ref-prefix" lines of an ls-refs request.
MaxRefPrefixes int
}
Limits bound what one request may cost. The zero value of a field means the default; a negative value is refused by Validate.
type LsRefsArgs ¶
LsRefsArgs are the parsed arguments of an ls-refs request (gitprotocol-v2, "ls-refs").
func ParseLsRefs ¶
func ParseLsRefs(args []string, lim Limits) (LsRefsArgs, error)
ParseLsRefs parses the argument lines of an ls-refs request. Unknown arguments are refused.
type PackRequest ¶
type PackRequest struct {
// Wants are the objects to send, with everything reachable from them.
Wants []string
// Common are commits the client has; everything reachable from them is
// left out.
Common []string
// Thin permits deltas against objects the client has.
Thin bool
// OfsDelta permits OBJ_OFS_DELTA.
OfsDelta bool
// IncludeTag adds annotated tags that point at sent objects.
IncludeTag bool
}
PackRequest is what fetch asks of the object store. Every id has already been validated as 40 lowercase hex digits by the protocol layer.
type ProtocolError ¶
type ProtocolError struct{ Msg string }
ProtocolError is a refusal caused by the client's request. It is reported to the client as an "ERR <message>" pkt-line.
func (*ProtocolError) Error ¶
func (e *ProtocolError) Error() string
type Ref ¶
type Ref struct {
// Name is the full ref name, or "HEAD".
Name string
// ID is the object id the ref resolves to (40 lowercase hex digits).
// It is empty only for an unborn HEAD.
ID string
// Target is the name of the ref this symbolic ref points to, or "".
Target string
// Peeled is the fully peeled object id when ID is an annotated tag.
Peeled string
}
Ref is one reference as ls-refs reports it.
type Repository ¶
type Repository interface {
// Refs lists HEAD (first, possibly unborn) and every ref, sorted by
// name, with symbolic targets and peeled ids.
Refs(ctx context.Context) ([]Ref, error)
// CommonCommits returns, in input order, those of ids that are commits
// present in the repository.
CommonCommits(ctx context.Context, ids []string) ([]string, error)
// WritePack writes a pack file for req to w.
WritePack(ctx context.Context, req PackRequest, w io.Writer) error
}
Repository is the narrow interface between the protocol and an object store. The git-binary-backed implementation is GitRepo; a pure-Go store can implement it later without touching the protocol code.
type Request ¶
type Request struct {
// Command is the value of "command=".
Command string
// Agent is the client's agent string, if it sent one.
Agent string
// Args are the command-specific argument lines, LF stripped, after the
// delim-pkt.
Args []string
}
Request is a parsed command request (gitprotocol-v2: command-request).
func ParseRequest ¶
ParseRequest reads one command request from r. It returns io.EOF for a clean end of session: end of input between requests, or the empty request (a lone flush-pkt). Every other malformed input is a *ProtocolError, except for transport failures, which are returned as read.
type Server ¶
type Server struct {
Repo Repository
Limits Limits
// Agent is advertised as agent=<Agent>. Empty means "gitproto".
Agent string
}
Server serves protocol v2 requests from Repo.
func (*Server) Advertise ¶
Advertise writes the capability advertisement: "version 2", the capabilities and a flush-pkt (gitprotocol-v2, "Capability Advertisement").
func (*Server) Serve ¶
Serve is a stateful session: it advertises, then answers command requests until the client sends the empty request or closes the connection. It returns nil on a clean end, a *ProtocolError after refusing a request (the client has been sent the "ERR" line), or the transport / repository error.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
gitproto-upload-pack
command
Command gitproto-upload-pack serves git-upload-pack over stdio using gitproto: protocol v2 only, fetch side.
|
Command gitproto-upload-pack serves git-upload-pack over stdio using gitproto: protocol v2 only, fetch side. |
|
Package pktline implements Git's pkt-line framing as specified by gitprotocol-common(5) and the protocol v2 special packets of gitprotocol-v2(5): flush-pkt "0000", delim-pkt "0001" and response-end-pkt "0002".
|
Package pktline implements Git's pkt-line framing as specified by gitprotocol-common(5) and the protocol v2 special packets of gitprotocol-v2(5): flush-pkt "0000", delim-pkt "0001" and response-end-pkt "0002". |
|
Package receivepack parses the client side of git-receive-pack and writes its reply, as specified by gitprotocol-pack(5) ("Reference Update Request and Packfile Transfer", "Report Status") and gitprotocol-capabilities(5).
|
Package receivepack parses the client side of git-receive-pack and writes its reply, as specified by gitprotocol-pack(5) ("Reference Update Request and Packfile Transfer", "Report Status") and gitprotocol-capabilities(5). |