template

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 18 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 template keeps the templates copy-on-write workspaces are made from: one read-only checkout of a repository at a commit, built once and shared by every workspace of that commit, and retired once none uses it.

A template is what a workspace is today — a checkout whose `.git` borrows from the pool — and it never changes once built: a layer on top of it must never see it move. Building it is the workspace package's (Builder); keeping, sharing and retiring it is this one's.

Index

Constants

View Source
const WarmDir = ".warm"

WarmDir is the directory under the templates where warm layers live. The templates' own walks never enter it.

Variables

This section is empty.

Functions

func ValidWarmName

func ValidWarmName(name string) error

ValidWarmName says why name cannot name a warm layer, or nothing when it can.

Types

type Builder

type Builder interface {
	// BuildTemplate checks key out at building, a directory that does not exist yet and
	// that the store renames to final once it is complete.
	BuildTemplate(ctx context.Context, key Key, building, final string) error
	// ForgetTemplate undoes what building recorded elsewhere — the pools it borrows from —
	// just before the template at dir is removed.
	ForgetTemplate(ctx context.Context, key Key, dir string) error
}

Builder checks a template out, as the workspace package builds a workspace.

type Key

type Key struct {
	Repository repo.Repo
	Commit     string
	Submodules bool
}

Key is which template: a repository at a commit, with its submodules checked out or not.

func (Key) Dir

func (key Key) Dir(templates string) string

Dir is where the template lives under the templates directory: `<host>/<path>/<commit>`, and `<commit>+submodules` with its submodules checked out.

func (Key) String

func (key Key) String() string

func (Key) Valid

func (key Key) Valid() error

Valid says why a key cannot name a template, or nothing when it can.

type Store

type Store struct {
	Dir string
	// contains filtered or unexported fields
}

Store keeps the templates under Dir.

func New

func New(dir string, locks *lock.Locks, builder Builder) *Store

New returns the store of the templates under dir, built by builder.

func (*Store) All

func (store *Store) All() []Key

All are the keys of every template on disk, read back from where each lives.

func (*Store) KeyOf

func (store *Store) KeyOf(dir string) (Key, bool)

KeyOf reads a template's key back from its directory, when the directory is one.

func (*Store) Let

func (store *Store) Let(ctx context.Context, key Key, user string) error

Let says the workspace at user no longer uses the template of key.

func (*Store) LetWarm

func (store *Store) LetWarm(ctx context.Context, dir, user string) error

LetWarm says the workspace at user no longer stands on the warm layer at dir.

func (*Store) Retire

func (store *Store) Retire(ctx context.Context, grace time.Duration) int

Retire removes every template no workspace uses — none noted, or none of those noted still there — and nothing has taken for at least grace, and says how many it removed.

func (*Store) RetireWarm

func (store *Store) RetireWarm(ctx context.Context, grace time.Duration) int

RetireWarm removes every warm layer no workspace stands on and nothing has taken for at least grace, and says how many it removed.

func (*Store) SealWarm

func (store *Store) SealWarm(ctx context.Context, sealed Warm, from string) error

SealWarm makes from, a layer a workspace left, the warm layer name of repository, by moving it, not copying: what overlay marked in it stays as it marked it. A warm layer of that name a workspace still stands on is not replaced.

func (*Store) Sweep

func (store *Store) Sweep() int

Sweep removes what a gitd that died left half built under the templates directory: the temporary directories templates are built in, and the users files left half written. It does not look inside a template, which has nothing of the sort and many files, nor among the warm layers, which SweepWarm sweeps.

func (*Store) SweepWarm

func (store *Store) SweepWarm() int

SweepWarm removes what a gitd that died left half done among the warm layers: a layer set aside to be replaced, or a file half written. It never enters a layer.

func (*Store) Take

func (store *Store) Take(ctx context.Context, key Key, user string) (string, error)

Take returns the template of key for the workspace at user, building it the first time, and notes that user uses it, so it is not retired under it.

func (*Store) TakeWarm

func (store *Store) TakeWarm(ctx context.Context, repository repo.Repo, name, user string) (Warm, error)

TakeWarm returns the warm layer name of repository for the workspace at user, and notes that user stands on it, so it is neither replaced nor retired under it.

func (*Store) Users

func (store *Store) Users(key Key) []string

Users are the workspaces noted as using the template of key.

func (*Store) WarmAt

func (store *Store) WarmAt(dir string) (Warm, error)

WarmAt reads back the warm layer at dir, as a workspace's record names it.

func (*Store) Warms

func (store *Store) Warms(repository repo.Repo) []Warm

Warms are the warm layers of repository.

type Warm

type Warm struct {
	Repository repo.Repo
	Name       string
	// Dir is the layer itself, mounted read-only.
	Dir string
	// Commit is the commit of the template it was sealed on: it stands on that one only.
	Commit string
	// Changed are the paths the layer changes that git does not ignore, as compared with
	// its template, so that what a workspace changed is read without walking the layer.
	Changed []string
	// Sealed is when it was sealed, and From the workspace it was sealed from.
	Sealed time.Time
	From   string
	// Users is how many workspaces stand on it now.
	Users int
}

Warm is a layer sealed from a workspace — what installing its dependencies wrote — that later workspaces of the same repository and commit stand on, between their template and their own layer. It is named per repository, and never changes once sealed: sealing the name again replaces it, once no workspace stands on it.

Jump to

Keyboard shortcuts

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