Documentation
¶
Overview ¶
Package gitproto speaks the git smart HTTP protocol over an object reader: ref advertisement, protocol v2 fetch and ls-refs, and the commands and report of receive-pack. It has no HTTP, grant or storage code.
Index ¶
- Constants
- Variables
- func AdvertiseReceive(w io.Writer, refs []Ref, version int) error
- func AdvertiseUpload(w io.Writer) error
- func GitRefName(stored string) (string, bool)
- func StoredRefName(git string) (string, bool)
- func WriteReport(w io.Writer, unpackErr string, results []Result) error
- type Command
- type CommitSource
- type Copier
- type Objects
- type Prefetcher
- type Push
- type Ref
- type RequestError
- type Result
- type Upload
Constants ¶
const Agent = "motte"
Agent is the agent capability of both services.
const MaxCommands = 1000
MaxCommands bounds the ref commands of one push.
const MaxTracked = 1000000
MaxTracked bounds the objects that one fetch holds in its sets.
Variables ¶
var ErrNotFound = errors.New("gitproto: object not found")
var ErrTooLarge = errors.New("gitproto: fetch has too many objects")
var Zero gitpack.SHA
Zero is the all-zero name that a ref command uses for an absent ref.
Functions ¶
func AdvertiseReceive ¶
AdvertiseReceive writes the ref advertisement of receive-pack. version is the protocol version that the client asked for, 0 or 1.
func AdvertiseUpload ¶
AdvertiseUpload writes the protocol v2 capability advertisement.
func GitRefName ¶
GitRefName is the git name of a stored ref. A stored name that does not start with refs/ is a branch. A stored name under refs/heads/ has no git name, because the git name would address the branch of the rest.
func StoredRefName ¶
StoredRefName is the stored name of a git ref, or false when no push may write it.
Types ¶
type Command ¶
Command is one ref update of a push. A zero Old creates the ref and a zero New deletes it.
type CommitSource ¶ added in v0.15.0
type CommitSource interface {
CommitInfo(ctx context.Context, sha gitpack.SHA) (tree gitpack.SHA, parents []gitpack.SHA, when int64, ok bool, err error)
}
CommitSource is an optional method of Objects: it returns the tree, the parents and the commit time of a commit from a commit graph, without reading the commit object, and false when no graph holds the commit.
type Copier ¶ added in v0.16.0
type Copier interface {
Copy(ctx context.Context, shas []gitpack.SHA, fn func(sha gitpack.SHA, raw *gitpack.Raw) error) error
}
Copier is an optional method of Objects. Copy calls fn once for each of shas, in an order of its own choice, with the stored pack entry of the object when a pack can copy it as it is, and with nil when the caller must read the object with Get. The entry is valid until fn returns.
type Objects ¶
type Objects interface {
Get(ctx context.Context, sha gitpack.SHA) (gitpack.Type, []byte, error)
Has(ctx context.Context, shas []gitpack.SHA) ([]bool, error)
}
Objects is the object reader of one repository. Get answers ErrNotFound for an absent object.
type Prefetcher ¶ added in v0.11.0
Prefetcher is an optional method of Objects: it reads the objects of shas ahead, so the Get calls that follow cost few reads. It never fails a fetch.
type Push ¶
type Push struct {
Commands []Command
ReportStatus bool
// Pack is the pack that follows the commands. It is empty when every command deletes.
Pack []byte
}
Push is a parsed receive-pack request.
type RequestError ¶
type RequestError string
RequestError is a request that the protocol refuses. Its text is safe to send to the client.
func (RequestError) Error ¶
func (e RequestError) Error() string
type Upload ¶
type Upload struct {
Objects Objects
// Refs are the refs under their git names.
Refs []Ref
// Head is the git name of the ref that HEAD names, or empty.
Head string
// Track, when set, is called with the objects that a fetch holds in its sets, before it holds them, each time
// that count grows. An error of Track stops the fetch.
Track func(objects int) error
// Phase, when set, is called with the name of each phase of a fetch as it ends: has_wants, has_haves, commit_walk,
// edge_trees, tree_walk and pack_write.
Phase func(name string)
}
Upload serves the protocol v2 commands ls-refs and fetch of one repository.