Documentation
¶
Overview ¶
Package workspace groups repositories so one radar gate checks them together. It owns the local registry, repository identity, repo IDs and the pure rules that turn an invocation into a scope, targets and bases.
Index ¶
- Constants
- func AdhocKey(current Location) string
- func ConfigDir() (string, error)
- func DefaultID(folder string) string
- func ShellPath(p string) string
- func Update(dir string, fn func(*Registry) error) error
- func Usable(ctx context.Context, repo Repo) string
- func ValidID(id string) error
- func WriteAtomic(path string, data []byte) error
- type AddResult
- type Consume
- type ConsumesFile
- type Error
- type Link
- type Location
- type PathChange
- type Producer
- type Registry
- func (r *Registry) Add(current, target Location, id, name string, usable func(Repo) string) (AddResult, error)
- func (r Registry) Find(commonDir string) (int, int, bool)
- func (r Registry) Named(name string) int
- func (r *Registry) Remove(current Location, id string) (string, Repo, error)
- func (r Registry) Validate() error
- type Repo
- type Scope
- func (s Scope) AssignBases(values []string) (map[string]string, error)
- func (s Scope) AssignTargets(targets []Target) (map[string][]string, error)
- func (s Scope) Has(id string) bool
- func (s Scope) Partial() bool
- func (s Scope) Qualify(targets []Target) []string
- func (s Scope) QualifyBases(values []string) []string
- type ScopeInput
- type ScopeRepo
- type Target
- type TeamFile
- type TeamRepo
- type Workspace
Constants ¶
const ( SourceRegistry = "registry" SourceWith = "--with" SourceReplay = "replay" SourceTeamFile = "team file" )
Scope sources: where the set of repositories came from.
const ConsumesPath = ".radar/consumes.json"
const MaxIDLength = 64
MaxIDLength bounds repo IDs and workspace names, which also name run directories.
const RegistryFile = "workspaces.json"
RegistryFile is the registry's name inside the configuration directory.
const RegistryVersion = 1
RegistryVersion is the local registry format version.
const TeamPath = ".radar/workspace.json"
Variables ¶
This section is empty.
Functions ¶
func AdhocKey ¶
AdhocKey names the run records of a one-off scope started from a repository that is not in a workspace. Every worktree of the repository derives the same key.
func DefaultID ¶
DefaultID derives a valid ID from a folder name: invalid characters become '-', and a name that does not start with a letter is prefixed with "repo-".
func ShellPath ¶
ShellPath quotes a value for a copyable POSIX shell command unless every character is known to be safe there. Suggested commands are presentation only, but must stay one safe command when pasted.
func Update ¶
Update applies fn to the registry under an exclusive lock and replaces the file atomically, so concurrent writers serialize and readers never see a partial file. fn's changes are discarded when it returns an error.
func ValidID ¶
ValidID checks a repo ID or workspace name: a letter, then letters, digits, '-' or '_'.
func WriteAtomic ¶
WriteAtomic replaces path with data through a synced temporary file and a rename in the same directory.
Types ¶
type AddResult ¶
type AddResult struct {
Workspace string `json:"workspace"`
Created bool `json:"created"`
Added []Repo `json:"added"`
Updated *PathChange `json:"updated,omitempty"`
Unchanged bool `json:"unchanged"`
Repo Repo `json:"repo"`
}
AddResult describes what Add changed.
type ConsumesFile ¶
func ParseConsumes ¶
func ParseConsumes(data []byte) (*ConsumesFile, error)
ParseConsumes validates consumer expectations; malformed entries stay errors.
type Location ¶
type Location struct {
Root string `json:"root"`
CommonDir string `json:"common_dir"`
MainPath string `json:"main_path"`
}
Location identifies the repository a checkout belongs to. Root is the checkout's top level; MainPath is the main worktree, which names the repo.
func Locate ¶
Locate resolves path to its repository. Linked worktrees of one repository share CommonDir, so they locate to the same repository.
func (Location) DefaultRepoID ¶
DefaultRepoID is the ID a repository gets unless one is chosen: its main worktree's folder name, normalized.
type PathChange ¶
PathChange records a registered repository whose location was updated.
type Producer ¶
type Producer struct{ Repo, Path, Pointer string }
Producer identifies a schema in a workspace repository.
func ParseProducer ¶
ParseProducer parses repo:path#pointer without performing Git or file I/O.
type Registry ¶
Registry is the machine-local list of workspaces. It holds absolute paths, so it is never committed. Only `radar workspace add/remove` write it.
func (*Registry) Add ¶
func (r *Registry) Add(current, target Location, id, name string, usable func(Repo) string) (AddResult, error)
Add registers target in the workspace of current, creating the workspace (current plus target) when current is in none. id overrides the default repo ID; an existing ID given explicitly moves that repo to target. name names a new workspace. usable reports why a registered location is gone.
type Repo ¶
type Repo struct {
ID string `json:"id"`
Path string `json:"path"`
CommonDir string `json:"common_dir"`
}
Repo locates one repository. CommonDir, the absolute Git common directory, identifies it: every worktree of a repository shares it.
type Scope ¶
type Scope struct {
// Workspace is the registered workspace name; empty for a one-off scope
// built only from --with.
Workspace string
// Key names the run-record directory: the workspace name, or a key
// derived from the current repository for an unregistered one.
Key string
Source string
// OneOff is set when --with added repositories for this run only.
OneOff bool
// Only lists the --only repo IDs; All is every repo ID before --only.
Only []string
All []string
// Current is the ID of the repository radar runs in.
Current string
Repos []ScopeRepo
Excluded []ScopeRepo
}
Scope is the resolved set of repositories one gate run checks.
func ResolveScope ¶
func ResolveScope(in ScopeInput) (*Scope, error)
ResolveScope applies the scope rules: the registered workspace of the current repository, else a one-off scope when --with is given, else nil for the unchanged single-repository gate. --with adds repositories and --only restricts the run to the named repo IDs.
func ResolveTeamScope ¶
func ResolveTeamScope(scope Scope, team *TeamFile, member func(ScopeRepo, string) bool) (Scope, error)
ResolveTeamScope applies team membership before --only, retaining explicit --with additions. member reports whether a registered repository is the one a team entry identifies. A team repo with no usable registered location is kept as Missing, so it is reported (or excluded by --only) instead of stopping the run; a registered repository with another identity is an error.
func (Scope) AssignBases ¶
AssignBases maps --base values (REF for the current repo, REPO:REF for a workspace repo) to repo IDs. Two bases for one repo are ambiguous.
func (Scope) AssignTargets ¶
AssignTargets groups targets by repo ID, keeping argument order, which is the merge order within each repository.
func (Scope) Qualify ¶
Qualify returns targets with every repo spelled out, so a repeated run resolves them the same way from any repository of the workspace.
func (Scope) QualifyBases ¶
QualifyBases is Qualify for --base values.
type ScopeInput ¶
type ScopeInput struct {
Registry Registry
Current Location
// With are the --with locations, in argument order, with the raw
// arguments for messages.
With []Location
WithArgs []string
Only []string
// Usable reports why a registered location cannot be used now, or "".
Usable func(Repo) string
}
ScopeInput is everything scope resolution reads; it performs no I/O.
type ScopeRepo ¶
type ScopeRepo struct {
ID string `json:"id"`
Path string `json:"path"`
CommonDir string `json:"common_dir"`
Origin string `json:"origin"`
Missing string `json:"missing,omitempty"`
TeamBase string `json:"team_base,omitempty"`
}
ScopeRepo is one repository in a gate run. Missing explains why its registered location cannot be used; such a repo is reported, not checked.
type Target ¶
Target is one positional gate argument: REF names a ref of the current repository and REPO:REF a ref of that workspace repository. Git ref names cannot contain ':', so the first ':' always separates the repo ID.
func ParseTargets ¶
ParseTargets applies the single-repository rule to every positional argument: an argument that names a valid target is kept whole (commas are legal in ref names); otherwise it is a comma-separated list of targets. valid reports whether a target names a known repository and an existing ref.
type TeamFile ¶
type TeamFile struct {
Version int `json:"version"`
Repos []TeamRepo `json:"repos"`
Links []Link `json:"links"`
Retired []contracts.Retirement `json:"retired,omitempty"`
}
TeamFile is the committed declaration of repository membership and links.