warm

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 20 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 warm serves the tree of a check from a local bare clone of the repository. It keeps one bare clone per repository, updates it when a Watcher reports a ref change, and keeps a few ready checkouts that it moves to the requested commit. A checkout holds plain files and no .git, so a check cannot write into the shared clone.

Index

Constants

View Source
const MinGit = "2.31"

MinGit is the oldest git that the warm path runs: the environment variables GIT_CONFIG_COUNT, GIT_CONFIG_KEY_n and GIT_CONFIG_VALUE_n, which carry the credential header, need git 2.31.

Variables

This section is empty.

Functions

func CheckGitVersion

func CheckGitVersion(out string) error

CheckGitVersion fails when the output of git --version names a git older than MinGit.

Types

type Config

type Config struct {
	// Dir holds the bare clones. It lives across restarts.
	Dir string
	// PoolDir holds the ready checkouts. It must be on the file system of the check directories, so that a handout is a
	// rename. The fetcher empties it at start.
	PoolDir string
	// Remote returns the git URL of repo.
	Remote func(repo string) (string, error)
	// Header returns a complete HTTP header line that authenticates a git request. Empty or nil means none.
	Header func(ctx context.Context) (string, error)
	// Fallback gets the tree when the warm path fails for a reason other than a refusal. Nil means the failure stands.
	Fallback func(ctx context.Context, req runnerproto.Request, dir string) error
	// PoolSize is the ready checkouts for each repository. Default 2.
	PoolSize int
	// MaxRepos and MaxBytes bound the cache. The fetcher removes the clone that was used least recently and is idle.
	// Defaults 16 and 20 GiB.
	MaxRepos int
	MaxBytes int64
	Clock    check.Clock
	Log      *slog.Logger
}

Config says where the caches live and how large they grow. Dir, PoolDir and Remote are required.

type Fetcher

type Fetcher struct {
	// contains filtered or unexported fields
}

Fetcher serves trees from the warm cache. Fetch has the signature of runner.Options.Fetch.

func New

func New(cfg Config) (*Fetcher, error)

New makes a fetcher. It starts no background work until a request or a sync needs it. Close stops that work.

func (*Fetcher) Changed

func (f *Fetcher) Changed(repo string)

Changed syncs the clone of repo in the background. An empty repo syncs every clone.

func (*Fetcher) Close

func (f *Fetcher) Close()

Close cancels the background work, refuses new work and waits for the work that is under way. It is safe to call twice.

func (*Fetcher) Fetch

func (f *Fetcher) Fetch(ctx context.Context, req runnerproto.Request, dir string) error

Fetch writes the files of req.Tree to the empty directory dir. It refuses a commit whose tree is another tree and a tree that holds a submodule. A failure of the cache makes one new clone and a second try, and then runs the fallback.

func (*Fetcher) Repos

func (f *Fetcher) Repos() []string

Repos returns the repositories that have a clone.

func (*Fetcher) Run

func (f *Fetcher) Run(ctx context.Context, ws ...Watcher)

Run starts each watcher and syncs the clone of each reported repository. It returns when ctx ends. A sweep runs every ten minutes.

func (*Fetcher) Sweep

func (f *Fetcher) Sweep()

Sweep removes idle clones, least recently used first, until the cache fits MaxBytes.

func (*Fetcher) Sync

func (f *Fetcher) Sync(ctx context.Context, name string)

Sync fetches the branches of repo into its clone and then moves the ready checkouts. It does nothing for a repository without a clone. A sync that runs when another is under way makes the other run once more.

func (*Fetcher) Wait

func (f *Fetcher) Wait()

Wait returns when the background work that is under way has ended.

type Watcher

type Watcher interface {
	Watch(ctx context.Context, changed func(repo string)) error
}

Watcher reports each change of a ref until ctx ends. It calls changed with the repository, or with "" when any repository may have changed. Watch returns an error only when it cannot go on, and the caller starts it again.

Directories

Path Synopsis
Package motteevents is a warm.Watcher that polls the ref events of motte.
Package motteevents is a warm.Watcher that polls the ref events of motte.
Package periodic is the fallback warm.Watcher: it reports every known repository as changed at a fixed interval.
Package periodic is the fallback warm.Watcher: it reports every known repository as changed at a fixed interval.
Package warmtest is the conformance suite of warm.Watcher.
Package warmtest is the conformance suite of warm.Watcher.

Jump to

Keyboard shortcuts

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