Skip to main content

load_or_build

Function load_or_build 

Source
pub fn load_or_build(
    layout: &RepoLayout,
    tree: &Tree,
    filter: &[PathBuf],
) -> Result<SparseOutcome, SparseBuildError>
Expand description

Cache-aware front end for the build_sparseverify_sparsestore pipeline shared by mkit checkout --sparse and mkit clone --sparse (SPEC-SPARSE-CHECKOUT §8).

Looks up (tree_hash(tree), hash_filter(filter)) in the on-disk cache first. A hit means this exact tree/filter pair was already built and self-verified by a previous invocation — the cache file is keyed by tree_hash, which is content-addressed, so a hit is trustworthy without redoing the Merkle-bitmap reconstruction that build_sparse/verify_sparse perform.

A cache-read failure is treated exactly like a plain miss and never propagated: CacheError::FilterMismatch (stale entry for a different filter), a wire-decode failure (corrupt entry), and any I/O error all fall through to a fresh build, which then overwrites the bad entry. The cache is a best-effort optimisation — see CacheError — so a failure to read it must never block sparse checkout.

§Errors

SparseBuildError only from the fresh-build path: a malformed tree/filter (SparseBuildError::Build) or a self-verification failure (SparseBuildError::VerifyFailed). Never returned on a cache hit.