gitproto

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 16 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 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

View Source
const Agent = "motte"

Agent is the agent capability of both services.

View Source
const MaxCommands = 1000

MaxCommands bounds the ref commands of one push.

View Source
const MaxTracked = 1000000

MaxTracked bounds the objects that one fetch holds in its sets.

Variables

View Source
var ErrNotFound = errors.New("gitproto: object not found")
View Source
var ErrTooLarge = errors.New("gitproto: fetch has too many objects")

Zero is the all-zero name that a ref command uses for an absent ref.

Functions

func AdvertiseReceive

func AdvertiseReceive(w io.Writer, refs []Ref, version int) error

AdvertiseReceive writes the ref advertisement of receive-pack. version is the protocol version that the client asked for, 0 or 1.

func AdvertiseUpload

func AdvertiseUpload(w io.Writer) error

AdvertiseUpload writes the protocol v2 capability advertisement.

func GitRefName

func GitRefName(stored string) (string, bool)

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

func StoredRefName(git string) (string, bool)

StoredRefName is the stored name of a git ref, or false when no push may write it.

func WriteReport

func WriteReport(w io.Writer, unpackErr string, results []Result) error

WriteReport writes the report-status reply. unpackErr is empty when the pack was stored.

Types

type Command

type Command struct {
	Old, New gitpack.SHA
	Ref      string
}

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 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

type Prefetcher interface {
	Prefetch(ctx context.Context, shas []gitpack.SHA)
}

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.

func ParsePush

func ParsePush(body []byte) (Push, error)

ParsePush reads the commands and the pack of a receive-pack request body.

type Ref

type Ref struct {
	Name string
	SHA  gitpack.SHA
}

Ref is a ref under its git name.

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 Result

type Result struct {
	Ref    string
	Reason string
}

Result is the outcome of one ref command. A reason makes the command fail.

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.

func (*Upload) Serve

func (u *Upload) Serve(ctx context.Context, w io.Writer, body io.Reader) error

Serve answers one command from body. An error before the first byte of w is a refusal. After the first byte it is a failure that the caller must report by closing the connection.

Jump to

Keyboard shortcuts

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