Documentation
¶
Overview ¶
Package gitbundle inspects a run's git bundle outside the sandbox and pushes it on the run's behalf (HR24 to HR26). A bundle is hostile input: every git call runs in a bare, blobless mirror with fsck on, no hooks, no worktree, an allow-list of transports, a timeout and an output cap, and the token reaches git only through GIT_CONFIG_* environment variables.
Index ¶
- Constants
- Variables
- type Cache
- type File
- type Inspection
- type Kind
- type Mirror
- func (m *Mirror) Discard(ctx context.Context, in Inspection)
- func (m *Mirror) Inspect(ctx context.Context, bundle []byte, branch, base string) (Inspection, error)
- func (m *Mirror) Push(ctx context.Context, in Inspection) error
- func (m *Mirror) Read(ctx context.Context, bundle []byte, branch, base string) (Inspection, error)
- type Refused
- type Stats
Constants ¶
const DefaultMaxBytes = 1 << 30
DefaultMaxBytes is a mirror's size limit on disk when Cache.MaxBytes is zero.
const MaxBlob = 1 << 20
MaxBlob is the largest blob a push may change, compressed or not: larger is push_size, read by its header alone, never inflated (core.bigFileThreshold matches it).
Variables ¶
var ErrLeaseLost = errors.New("gitbundle: the branch moved since it was read")
ErrLeaseLost is a push whose lease the remote refused: the branch moved since OldHead was read.
var ErrPushRejected = errors.New("gitbundle: the remote refused the push")
ErrPushRejected is a push the remote refused for good, not for the lease: a "[remote rejected]" ref (a pre-receive hook, a missing workflows permission) or a 403 / permission denied.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
Root string
// Remote is a repository's URL; nil means "https://github.com/" + repo + ".git".
Remote func(repo string) string
// Token is the token git sends for repo (the publisher's), only through GIT_CONFIG_COUNT/KEY/VALUE
// env as http.extraHeader; never in argv. nil sends none (tests on file://).
Token func(ctx context.Context, repo string) (string, error)
// Git is the git binary, "git" (from PATH) when empty.
Git string
// Protocols are the allowed transport protocols, ["https"] when empty.
Protocols []string
// Timeout bounds each git call, 60s when zero.
Timeout time.Duration
// MaxBytes bounds one mirror on disk, DefaultMaxBytes when zero: a mirror past it is re-created
// before the next inspection, so pushed objects never accumulate past the cache's emptyDir.
MaxBytes int64
// contains filtered or unexported fields
}
Cache holds one bare, blobless mirror per repository under Root (an emptyDir, MAKU_GIT_CACHE in the factory).
type File ¶
type File struct{ Path, Status, Mode string }
File is one changed entry: Status is git's raw letter (A, M, D, T), Mode is the new mode ("100644", "100755", "120000", "160000"), the old mode for a deletion.
type Inspection ¶
type Inspection struct {
Ref string // the one ref, refs/heads/<branch>
Head string // the bundle's head SHA (40 or 64 hex)
OldHead string // the branch's head on the remote when read, "" when absent: the lease
BaseHead string // the base branch's head on the remote when read
Kind Kind
// Files is the union of OldHead..Head (FastForward) or merge-base(BaseHead, Head)..Head
// (Rebase) and every intermediate commit in that range, deletions included.
Files []File
// Added is every commit's added lines in Files' range (no "+" prefix), then each new commit's
// author/committer headers and message.
Added []string
// Cumulative is merge-base(BaseHead, Head)..Head, always.
Cumulative Stats
// contains filtered or unexported fields
}
Inspection is what a bundle would change on the remote.
type Mirror ¶
type Mirror struct {
// contains filtered or unexported fields
}
Mirror is one repository's bare, blobless mirror. Inspect and Push hold its lock.
func (*Mirror) Discard ¶
func (m *Mirror) Discard(ctx context.Context, in Inspection)
Discard deletes the ref in's bundle was fetched into, for a push the applier refuses or holds after the inspection (#505's review); Push and Inspect's own refusals delete it themselves. It holds the mirror's lock, and is a no-op for a ref already gone.
func (*Mirror) Inspect ¶
func (m *Mirror) Inspect(ctx context.Context, bundle []byte, branch, base string) (Inspection, error)
Inspect checks bundle as a push of exactly refs/heads/<branch> onto base (e.g. "agent/t-1", "main"), and returns what it would change. A *Refused error is the bundle's fault; any other error is the factory's (retry later). It holds the mirror's lock for its whole run.
func (*Mirror) Push ¶
func (m *Mirror) Push(ctx context.Context, in Inspection) error
Push pushes in.Head to in.Ref with --force-with-lease=<ref>:<in.OldHead> (an empty OldHead: the ref must be absent). A remote already at in.Head is success with nothing pushed only when the inspection read it there (HR26); one that moved there since, by another hand, is ErrLeaseLost, as is any other move. It holds the mirror's lock. The head's objects are the mirror's, from the Inspect that returned in.
func (*Mirror) Read ¶ added in v0.47.0
Read is the cumulative change bundle carries onto base, merge-base(base, head)..head, whatever the branch holds now: the drill runner reads an applied push with it after the fact (HR38), when the branch may have moved past the bundle's head. Files and Added are that range's, and Kind is Rebase. It pushes nothing and keeps no ref to the bundle's objects; its refusals are Inspect's.