refs

package
v0.2026244.920 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 14 Imported by: 7 modules, 8 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 refs is the spec fabric slice for the remote-repo GIT primitives — pure git-exec + string parsing + cache-path computation, host primitives a plugin composes but the kernel itself needs (reconcile's --remote tag query, the collection walk). RELOCATED from sdk/kit (#55 fabric-primitive extraction), so charly core reaches them via spec/refs directly and the remaining sdk/candy callers keep a thin kit re-export. The FETCH ORCHESTRATION (override → cache → clone → migrate) still lives in the refs plugin (candy/plugin-refs); these are the reusable mechanisms it composes. The only non-stdlib dependency is the advisory file lock (spec/lock) DownloadRepo serializes concurrent cache refresh with.

Index

Constants

View Source
const (
	LatestTagTTL     = 24 * time.Hour
	DefaultBranchTTL = 24 * time.Hour
	ResolveRefTTL    = 5 * time.Minute
)

Cache TTLs (see the freshness policy above).

Variables

This section is empty.

Functions

func CompareSemver

func CompareSemver(a, b string) int

CompareSemver compares two semver-like version strings (e.g. "v1.2.3"). Returns -1 if a < b, 0 if equal, 1 if a > b. It delegates to spec/calver.CompareCalVer — the single dotted-version comparator (which strips the "v" prefix and falls back to lexical comparison for non-numeric parts) — so semver and CalVer strings share ONE implementation.

func DownloadRepo

func DownloadRepo(repoPath string, version string) (string, error)

DownloadRepo downloads a remote repo to the cache. Returns the cache path where the repo was stored.

Freshness contract: the cache is reused ONLY when its recorded provenance (the commit the export was cloned from) equals the ref's CURRENTLY resolved commit — so a branch that advanced upstream (main) is re-downloaded instead of silently serving stale content. The check costs the one ls-remote GitResolveRef already performs; for immutable tags the provenance always matches, so their cache-hit behavior is unchanged. A cache written before this contract has no provenance and is re-downloaded once, then self-heals.

func GitClone

func GitClone(repoURL string, ref string, commit string, targetDir string) error

GitClone clones a git repository at a specific ref into the target directory. Uses shallow clone for efficiency.

func GitDefaultBranch

func GitDefaultBranch(repoURL string) (string, error)

GitDefaultBranch detects the default branch of a remote repository. Uses git ls-remote --symref to find what HEAD points to. Returns the branch name (e.g., "main", "master").

This is the RAW primitive — it always hits the network. Caching is the GitClient's job (refs/git_client.go): every consumer that needs a cached answer goes through GitClient.DefaultBranch. The former per-primitive cache (latest-tags.json) is DELETED — one cache, one layer (R3/R5).

func GitLatestTag

func GitLatestTag(repoURL string) (string, error)

GitLatestTag queries a remote repo for tags and returns the highest semver tag. Looks for tags matching v* pattern, sorts by semver, returns the highest. Returns an error if no version tags are found.

This is the RAW primitive — it always hits the network. Caching is the GitClient's job (refs/git_client.go): every consumer that needs a cached answer goes through GitClient.LatestTag, which wraps this primitive with the persistent `cache:` section of the per-host charly.yml. The former per-primitive cache (latest-tags.json) is DELETED — one cache, one layer (R3/R5).

func GitResolveRef

func GitResolveRef(repoURL string, ref string) (string, error)

GitResolveRef resolves a git reference (tag, branch, or commit) to a full commit hash. Uses git ls-remote for tags/branches; for commit hashes, validates length and returns as-is.

NOTE: deliberately NOT cached. DownloadRepo's freshness contract resolves the ref to its CURRENT commit on every call, so a mutable branch (main) that moved upstream is re-downloaded instead of serving stale content (refs/git_test.go TestDownloadRepoFrom_RefreshesMovedBranch). A TTL cache here would break that contract — the freshness check must see the live commit.

func IsMutableRef

func IsMutableRef(version string) bool

IsMutableRef reports whether a repo ref version can ADVANCE upstream (a branch name such as main, or an empty version that resolves to the default branch). Immutable coordinates — CalVer/semver tags (v…) and full commit SHAs — never change what they point at; the project's tags are add-only. Mutable refs must re-resolve on every access: a cache hit on a branch otherwise freezes it at first-download content forever (the pre-#146 @main protocol skew — a stale main export served protocol-v1 plugin sources indefinitely).

func IsRepoCached

func IsRepoCached(repoPath, version string) (bool, error)

IsRepoCached reports whether a repo version is already in the cache AS A USABLE EXPORT — the directory exists AND every submodule it declares has content.

The completeness half is load-bearing for IMMUTABLE refs. EnsureRepoDownloaded short-circuits on `cached && !IsMutableRef(version)`, returning RepoCachePath directly and never entering DownloadRepo — so the repoCacheFresh completeness check cannot see a tag's cache at all. Directory-exists alone therefore pinned every incomplete TAG export permanently: a tag never moves, so nothing would ever re-fetch it. On the machine this was found, `charly@v2026.183.1359` held 0 of its 9 declared submodules and `charly@v2026.201.0706` held 1 of 10, both unrepairable for the life of the cache. Checking content here routes an incomplete export down the download branch instead, so tag and branch caches self-heal by the SAME predicate rather than one growing its own copy.

func RepoCacheDir

func RepoCacheDir() (string, error)

RepoCacheDir returns the cache directory for remote repos. Uses $CHARLY_REPO_CACHE env var if set, otherwise ~/.cache/charly/repos/.

func RepoCachePath

func RepoCachePath(repoPath, version string) (string, error)

RepoCachePath returns the cache path for a specific repo version. e.g. ~/.cache/charly/repos/github.com/org/repo@v1.0.0/

func RepoGitURL

func RepoGitURL(repoPath string) string

RepoGitURL converts a repo path to a git clone URL. e.g. "github.com/opencharly/ml-layers" -> "https://github.com/opencharly/ml-layers.git"

Types

type GitClient added in v0.2026241.711

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

GitClient is the centralized git layer. Construct once per process (or per project) and share it — the cache is the point.

func NewGitClient added in v0.2026241.711

func NewGitClient(cacheFile string) *GitClient

NewGitClient returns a GitClient whose cache lives in the `cache:` section of the per-host charly.yml at cacheFile. When cacheFile is empty, the default deploy config path (~/.config/charly/charly.yml, honoring the CHARLY_DEPLOY_CONFIG override) is used.

func (*GitClient) DefaultBranch added in v0.2026241.711

func (g *GitClient) DefaultBranch(repoURL string) (string, error)

DefaultBranch returns the default branch of repoURL, cached (the name is stable).

func (*GitClient) Download added in v0.2026241.711

func (g *GitClient) Download(repoPath, version string, download func(repoPath, version string) (string, error)) (string, error)

Download fetches repoPath@version into the repo cache and returns the cache path, CACHED with a short TTL. A mutable ref (a branch or the default branch) can move, so the freshness contract requires re-resolving eventually — but not on every invocation. The 5m TTL means a command run twice in quick succession (e.g. the status fan-out resolving the envelope multiple times) pays the download once.

func (*GitClient) LatestTag added in v0.2026241.711

func (g *GitClient) LatestTag(repoURL string) (string, error)

LatestTag returns the highest semver tag of repoURL, cached (tags are immutable).

func (*GitClient) ResolveRef added in v0.2026241.711

func (g *GitClient) ResolveRef(repoURL, ref string) (string, error)

ResolveRef resolves a ref to a commit SHA, cached with a SHORT TTL (the freshness contract: a mutable branch can move, but not on every invocation).

func (*GitClient) WarmUp added in v0.2026241.711

func (g *GitClient) WarmUp(repoURLs []string, stderr *os.File)

WarmUp prefetches the latest tag and default branch for a set of repo URLs, printing a progress line to stderr on the first (cold) run so the user knows charly is fetching git metadata. It is the "first startup" feedback the CLI shows before a command that will need the refs.

Jump to

Keyboard shortcuts

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