Skip to content

Gitproto

Gitproto

go-vcs/gitproto is the Git wire protocol as a Go library, with no knowledge of any forge. v0.1.0 serves protocol v2 ls-refs and fetch; a full clone takes 0.93 to 0.96 of the time of git upload-pack. v0.2.0 adds the request side of a push, the receivepack package.

receivepack

github.com/go-vcs/gitproto/receivepack reads a push request so that a forge can decide its policy before one byte of the pack is read.

req, err := receivepack.Parse(pktline.NewReader(conn), receivepack.Limits{})
// req.Commands: old id, new id and ref of each command (Create, Delete)
// req.Caps, req.PushOptions, req.WantsPack
a, b, collide, err := req.FoldCollision()
FunctionWhat it does
ParseReads the command list and the push options and returns a plain *Request; the source is left on the first byte of the pack.
CheckRefNameRefuses bad ref names: git’s check-ref-format rules, C1 controls, U+FFFD, invalid UTF-8, names a case-folding file system cannot store safely, and names longer than 65520 bytes.
FoldKeyThe key under which a folding file system (APFS, NTFS) stores a name: canonical caseless match, Unicode D145, Unicode 17.0.0. Call it on names that passed CheckRefName; never persist a key.
Request.FoldCollisionReports two refs of one request that would become one file.
WriteReportWrites report-status and report-status-v2, wrapped in side-band-64k when negotiated.
AdvertiseWrites the v0 ref advertisement.

What is refused

Each refusal has a test: shallow, push certificates, a too small side-band, unknown capabilities, an object-format other than sha1, malformed ids, bad ref names, duplicate refs, and bounds on commands, push options and request bytes. MaxMemoryBytes is finite by default (64 MiB) and charged before each allocation. A deadline overrun is an error in Parse and in FoldCollision, never a late answer.

FoldCollision refuses a Request that Parse did not make, because only Parse gives it a budget and a deadline. The fold follows the Unicode tables of the Go toolchain that built the binary, so CheckRefName fails closed on a code point those tables leave unassigned.

Checked against

FuzzParse has a committed corpus, and TestRealGitPush runs the real git push against a server built on the package.

Try it

The playground runs CheckRefName, FoldKey, FoldCollision and Parse in your browser, compiled to WebAssembly: paste ref names to see which are refused and which collide, or a push request to see its commands.