workspace

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 14 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 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

View Source
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(root string, cfg *config.Config)

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

func FetchClone(repo, ref string) (dir, sha string, err error)

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

func IsGitURL(arg string) bool

IsGitURL reports whether a `workspace add` argument names a remote repository rather than a directory.

func LinkClone

func LinkClone(primary string, link CacheLink) error

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

func LooksLikeProject(dir string) bool

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 RedactURL

func RedactURL(raw string) string

RedactURL removes a user name and password from a URL for display.

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

func RootsOf(root string) []string

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

func SplitURLRef(arg string) (repo, ref string)

SplitURLRef separates "url@ref". An scp-style "git@host:org/repo" keeps its own "@".

func Stamp

func Stamp(primary string) string

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

func UnlinkClone(primary, id string) bool

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 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(primary string) []CacheLink

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.

func Discover

func Discover(primary string, ws *Workspace) []Candidate

Discover finds repositories related to primary, most certain first: directories its manifests point at, then sibling directories whose manifests declare a package it requires or require a package it declares. It reads manifest files only. Nothing is indexed, linked, or written.

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.

func (Root) Unusable

func (r Root) Unusable() string

Unusable says why a declared root cannot be consulted, or "" when it can. Answers name every unusable root: one dropped without a word reads as searched.

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`.

func Inspect

func Inspect(r Root) Status

Inspect reads a root's git state and whether it has an index. It changes nothing in the root.

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

func CurrentTree(root string) TreeState

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.

func Missing

func Missing(primary string, ws *Workspace, found []Candidate) []Unlinked

Missing lists the requirements of primary that neither a discovered candidate nor an already linked repository satisfies: what a cache clone or the link server would have to supply. Most entries are ordinary third-party packages; the list is for picking out the ones that matter.

type Workspace

type Workspace struct {
	Primary string
	Roots   []Root
}

Workspace is the primary root plus the roots linked to it.

func Load

func Load(primary string, cfg *config.Config) *Workspace

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

func (w *Workspace) Describe() string

Describe lists the linked roots as "id (relative path)", for one-line notes.

func (*Workspace) DisplayPath

func (w *Workspace) DisplayPath(r Root) string

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.

func (*Workspace) Linked

func (w *Workspace) Linked() []Root

Linked returns the roots that exist on disk.

func (*Workspace) RelPath

func (w *Workspace) RelPath(abs string) string

RelPath returns abs as a slash path relative to the primary root, which is the form answers print for a file in another repository ("../grove/x.go"): the agent's own file tools accept it from the primary root unchanged.

Jump to

Keyboard shortcuts

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