pub struct SparseCheckout { /* private fields */ }Expand description
The active sparse-checkout definition of a repository, compiled once for path checks.
Checkout-updating operations (reset --hard, switch, merge, pull, restore, …) load
this once per operation: paths it excludes are recorded in the index with the
skip-worktree bit instead of being written to the work tree, like Git’s sparse checkout.
SparseCheckout::load returns None when core.sparseCheckout is off or
info/sparse-checkout does not exist, so non-sparse repositories pay only a config lookup.
Implementations§
Source§impl SparseCheckout
impl SparseCheckout
Sourcepub fn load(repo: &Repository) -> Result<Option<Self>>
pub fn load(repo: &Repository) -> Result<Option<Self>>
Load the sparse-checkout definition of repo from its config and info/sparse-checkout.
Reads core.sparseCheckout and core.sparseCheckoutCone from the repository’s cached
configuration; the pattern file is only read when sparse checkout is enabled.
§Returns
Ok(None) when sparse checkout is disabled or the pattern file is missing.
§Errors
crate::error::Error::Config when either key holds an invalid boolean, and
crate::error::Error::Io when the pattern file exists but cannot be read.
Sourcepub fn from_config(git_dir: &Path, config: &ConfigSet) -> Result<Option<Self>>
pub fn from_config(git_dir: &Path, config: &ConfigSet) -> Result<Option<Self>>
Like SparseCheckout::load, with an explicit git directory and configuration.
§Parameters
git_dir— directory holdinginfo/sparse-checkout(the per-worktree git dir).config— configuration providingcore.sparseCheckout/core.sparseCheckoutCone.
§Errors
Same as SparseCheckout::load.
Sourcepub fn parse(content: &str, cone: bool) -> Self
pub fn parse(content: &str, cone: bool) -> Self
Compile sparse-checkout file content.
§Parameters
content— text ofinfo/sparse-checkout.cone— the value ofcore.sparseCheckoutCone; a file that is not a valid cone definition falls back to non-cone matching.
Sourcepub fn includes(&self, path: &str) -> bool
pub fn includes(&self, path: &str) -> bool
Whether the repository-relative file path (/-separated) belongs in the work tree.
Sourcepub fn includes_index_path(&self, path: &[u8]) -> bool
pub fn includes_index_path(&self, path: &[u8]) -> bool
Like SparseCheckout::includes, for a raw index path.
Sourcepub fn mark_index_entries(&self, index: &mut Index, work_tree: Option<&Path>)
pub fn mark_index_entries(&self, index: &mut Index, work_tree: Option<&Path>)
Set skip-worktree on every stage-0 entry of index that is outside the definition
and clear it on the others; bumps the index to version 3 when any bit is set.
§Parameters
index— index to update in place.work_tree— when set, on-disk directories can match directory-only non-cone patterns.
Sourcepub fn carry_skip_worktree(&self, index: &mut Index, previous: &Index)
pub fn carry_skip_worktree(&self, index: &mut Index, previous: &Index)
Carry sparse state into index, an index rebuilt from a tree without touching the
work tree (mixed reset, merge abort, stash): a stage-0 entry gets skip-worktree when
previous marks the same path skip-worktree, or when previous has no entry for the
path and the path is outside the definition.
§Parameters
index— the rebuilt index, updated in place.previous— the index the rebuild replaces.