git_index/access/sparse.rs
1/// Configuration related to sparse indexes.
2#[derive(Debug, Default, Clone, Copy)]
3pub struct Options {
4 /// If true, certain entries in the index will be excluded / skipped for certain operations,
5 /// based on the ignore patterns in the `.git/info/sparse-checkout` file. These entries will
6 /// carry the [`SKIP_WORKTREE`][crate::entry::Flags::SKIP_WORKTREE] flag.
7 ///
8 /// This typically is the value of `core.sparseCheckout` in the git configuration.
9 pub sparse_checkout: bool,
10
11 /// Interpret the `.git/info/sparse-checkout` file using _cone mode_.
12 ///
13 /// If true, _cone mode_ is active and entire directories will be included in the checkout, as well as files in the root
14 /// of the repository.
15 /// If false, non-cone mode is active and entries to _include_ will be matched with patterns like those found in `.gitignore` files.
16 ///
17 /// This typically is the value of `core.sparseCheckoutCone` in the git configuration.
18 pub directory_patterns_only: bool,
19
20 /// If true, will attempt to write a sparse index file which only works in cone mode.
21 ///
22 /// A sparse index has [`DIR` entries][crate::entry::Mode::DIR] that represent entire directories to be skipped
23 /// during checkout and other operations due to the added presence of
24 /// the [`SKIP_WORKTREE`][crate::entry::Flags::SKIP_WORKTREE] flag.
25 ///
26 /// This is typically the value of `index.sparse` in the git configuration.
27 pub write_sparse_index: bool,
28}
29
30impl Options {
31 /// Derive a valid mode from all parameters that affect the 'sparseness' of the index.
32 ///
33 /// Some combinations of them degenerate to one particular mode.
34 pub fn sparse_mode(&self) -> Mode {
35 match (
36 self.sparse_checkout,
37 self.directory_patterns_only,
38 self.write_sparse_index,
39 ) {
40 (true, true, true) => Mode::IncludeDirectoriesStoreIncludedEntriesAndExcludedDirs,
41 (true, true, false) => Mode::IncludeDirectoriesStoreAllEntriesSkipUnmatched,
42 (true, false, _) => Mode::IncludeByIgnorePatternStoreAllEntriesSkipUnmatched,
43 (false, _, _) => Mode::Disabled,
44 }
45 }
46}
47
48/// Describes the configuration how a sparse index should be written, or if one should be written at all.
49#[derive(Debug)]
50pub enum Mode {
51 /// index with DIR entries for exclusion and included entries, directory-only include patterns in `.git/info/sparse-checkout` file.
52 IncludeDirectoriesStoreIncludedEntriesAndExcludedDirs,
53 /// index with all file entries and skip worktree flags for exclusion, directory-only include patterns in `.git/info/sparse-checkout` file.
54 IncludeDirectoriesStoreAllEntriesSkipUnmatched,
55 /// index with all file entries and skip-worktree flags for exclusion, `ignore` patterns to include entries in `.git/info/sparse-checkout` file.
56 IncludeByIgnorePatternStoreAllEntriesSkipUnmatched,
57 /// index with all entries, non is excluded, `.git/info/sparse-checkout` file is not considered, a regular index.
58 Disabled,
59}