Documentation
¶
Overview ¶
Package workspace models the set of repositories linked to the one a command answers for. Each repository keeps its own index; the workspace only says which other roots may be consulted and why.
Index ¶
- Constants
- func CacheDir() string
- func ConfirmLinks(root string, cfg *config.Config)
- func FetchClone(repo, ref string) (dir, sha string, err error)
- func IsGitURL(arg string) bool
- func LinkClone(primary string, link CacheLink) error
- func LinkReverse(linker, target string)
- func LooksLikeProject(dir string) bool
- func PruneClones() []string
- func RedactURL(raw string) string
- func Register(root string)
- func RootsOf(root string) []string
- func SplitURLRef(arg string) (repo, ref string)
- func Stamp(primary string) string
- func StateDir() string
- func UnlinkClone(primary, id string) bool
- func UnlinkReverse(linker, target string)
- type CacheLink
- type Candidate
- type RegistryEntry
- type Root
- type Status
- type TreeState
- type Unlinked
- type Workspace
Constants ¶
const Unconfirmed = "" /* 128-byte string literal not displayed */
Unconfirmed is the reason a link written in a prism.yaml is not yet in force on this machine.
Variables ¶
This section is empty.
Functions ¶
func CacheDir ¶
func CacheDir() string
CacheDir is where cache clones live: $PRISM_CACHE_DIR, else the user cache directory.
func ConfirmLinks ¶
ConfirmLinks records the other end of every link in root's prism.yaml whose directory exists. It runs from explicit `prism workspace` and `prism init` commands, so a repository cloned with links already written becomes visible from the repositories it links once the user has run one of them there.
func FetchClone ¶
FetchClone makes sure the commit that ref names in the remote is checked out in the cache, and returns its directory and commit. An empty ref is the remote's default branch. Full history objects are fetched: a blob-filtered clone downloads file by file on first read, which stalls an indexer that reads every file.
func IsGitURL ¶
IsGitURL reports whether a `workspace add` argument names a remote repository rather than a directory.
func LinkClone ¶
LinkClone records that primary uses the cache clone at dir. A link with the same id is replaced: fetching a moved branch points the id at the new commit's directory and leaves the old directory for other users of it.
func LinkReverse ¶
func LinkReverse(linker, target string)
LinkReverse records that linker's prism.yaml links target, so target's workspace includes linker.
func LooksLikeProject ¶
LooksLikeProject reports whether dir holds a repository marker: .git, .grove, prism.yaml or a build manifest.
func PruneClones ¶
func PruneClones() []string
PruneClones deletes cached worktrees that no link refers to and returns their directories. Bare clones are kept: they make the next fetch cheap.
func Register ¶
func Register(root string)
Register records root and the packages its manifests declare. A repository that declares none is not recorded: nothing could match it. Failures are ignored; the registry is a convenience, never a dependency.
func RootsOf ¶
RootsOf returns the directories of the repositories linked to root that exist on disk: what an index run of root is told about.
func SplitURLRef ¶
SplitURLRef separates "url@ref". An scp-style "git@host:org/repo" keeps its own "@".
func Stamp ¶
Stamp changes whenever what Load(primary) would return may have changed: the repository's prism.yaml, a workspace file above it, or the per-user link records. A long-lived process compares stamps instead of re-reading the files on every call.
func StateDir ¶
func StateDir() string
StateDir is where Prism keeps per-user state: $PRISM_STATE_DIR, else the user configuration directory.
func UnlinkClone ¶
UnlinkClone removes primary's cache link with this id. The cached directory stays; PruneClones removes directories nothing links to.
func UnlinkReverse ¶
func UnlinkReverse(linker, target string)
UnlinkReverse removes the record LinkReverse made.
Types ¶
type CacheLink ¶
type CacheLink struct {
Primary string `json:"primary"`
ID string `json:"id"`
URL string `json:"url"`
Ref string `json:"ref"` // as asked: a branch, tag or commit; "" is the remote's default branch
SHA string `json:"sha"`
Path string `json:"path"`
// Kind is "" for a cache clone and "reverse" for the other end of a
// link a `prism workspace` command made from Path's prism.yaml.
Kind string `json:"kind,omitempty"`
// Trusted: the clone was added with --trusted, so its build tools run
// while it is indexed (workspace fetch keeps the choice).
Trusted bool `json:"trusted,omitempty"`
}
CacheLink records one cache clone linked to a primary repository. It is per-machine state and lives outside every repository.
func CacheLinks ¶
CacheLinks returns the cache clones linked to primary.
type Candidate ¶
type Candidate struct {
ID string
Path string // absolute
// Explicit is true when the primary repository's own build already
// points at this directory (go.work use, replace => ../x, file:../x).
// Otherwise the match is a declared package name found in a sibling.
Explicit bool
// Relation is "depends on" (the primary requires it) or "used by" (it
// requires the primary).
Relation string
Package string // the package that links the two
Version string // the version the requiring side pins, as written
Evidence string
Linked bool // already in the workspace
}
Candidate is a repository on disk that the manifests say is related to the primary one. Discovery only reports; linking is a separate, explicit step.
type RegistryEntry ¶
type RegistryEntry struct {
Path string `json:"path"`
Packages []string `json:"packages"` // "ecosystem:name"
Updated string `json:"updated"`
}
RegistryEntry is one known repository.
func Known ¶
func Known() []RegistryEntry
Known returns the registered repositories that still exist on disk.
type Root ¶
type Root struct {
ID string
// Path is the absolute, symlink-resolved directory. For a missing root it
// is the cleaned absolute path that was declared.
Path string
// Evidence says where the link was declared, for `prism workspace`.
Evidence string
// Missing is true when the declared directory does not exist.
Missing bool
// Cache is true for a clone Prism fetched: reference source at a fixed
// commit, not a checkout the user works in.
Cache bool
// Refused, when not empty, says why a declared link is not used: not
// confirmed on this machine, or not a repository.
Refused string
}
Root is one linked repository.
type Status ¶
type Status struct {
Root
Ref string // branch name, or "" when detached or not a git work tree
Head string // short commit SHA
Dirty bool
Indexed bool
IndexedAt time.Time
}
Status is the state of one root on disk, for `prism workspace`.
type TreeState ¶
type TreeState struct {
Head string // full commit SHA; "" when not a git work tree
Ref string // branch; "" when detached
// Changed lists files git reports as modified, added or untracked,
// repository-relative.
Changed []string
}
TreeState is what is checked out in a repository right now.
func CurrentTree ¶
CurrentTree reads a repository's checked-out commit and its uncommitted files. It changes nothing.
type Unlinked ¶
type Unlinked struct {
Ecosystem string
Name string
Version string
Evidence string
// URL is where the source can be fetched from, when the package name
// says so (a Go module path). Empty otherwise.
URL string
}
Unlinked is a dependency this repository declares that no checkout on this machine was found for.
type Workspace ¶
Workspace is the primary root plus the roots linked to it.
func Load ¶
Load builds the workspace for primary from two sources: the `workspace_repo:` lines of its own prism.yaml (cfg), and those of the nearest ancestor prism.yaml, which is how a parent folder holding several checkouts declares them once. It returns nil when nothing is linked, so a repository with no workspace behaves exactly as before.
A link written in a prism.yaml is a proposal. It takes effect on a machine once the user has run a `prism workspace`, `prism init` or `prism index` command in the repository that declares it (ConfirmLinks), and only for a target that looks like a repository. Otherwise a cloned repository's committed file could point Prism at any directory on the machine. Under an untrusted repository (GROVE_UNTRUSTED, prism untrust, PRISM_UNTRUSTED) nothing is linked at all.
func (*Workspace) Describe ¶
Describe lists the linked roots as "id (relative path)", for one-line notes.
func (*Workspace) DisplayPath ¶
DisplayPath is the path answers print for a linked root: relative to the primary for a checkout beside it, absolute for a cache clone, whose relative path would be a long climb out of the repository.