-
-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
445 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/// Configuration related to sparse indexes. | ||
#[derive(Debug, Default, Clone, Copy)] | ||
pub struct Options { | ||
/// If true, certain entries in the index will be excluded / skipped for certain operations, | ||
/// based on the ignore patterns in the `.git/info/sparse-checkout` file. These entries will | ||
/// carry the [`SKIP_WORKTREE`][crate::entry::Flags::SKIP_WORKTREE] flag. | ||
/// | ||
/// This typically is the value of `core.sparseCheckout` in the git configuration. | ||
pub sparse_checkout: bool, | ||
|
||
/// Interpret the `.git/info/sparse-checkout` file using _cone mode_. | ||
/// | ||
/// If true, _cone mode_ is active and entire directories will be included in the checkout, as well as files in the root | ||
/// of the repository. | ||
/// If false, non-cone mode is active and entries to _include_ will be matched with patterns like those found in `.gitignore` files. | ||
/// | ||
/// This typically is the value of `core.sparseCheckoutCone` in the git configuration. | ||
pub directory_patterns_only: bool, | ||
|
||
/// If true, will attempt to write a sparse index file which only works in cone mode. | ||
/// | ||
/// A sparse index has [`DIR` entries][crate::entry::Mode::DIR] that represent entire directories to be skipped | ||
/// during checkout and other operations due to the added presence of | ||
/// the [`SKIP_WORKTREE`][crate::entry::Flags::SKIP_WORKTREE] flag. | ||
/// | ||
/// This is typically the value of `index.sparse` in the git configuration. | ||
pub write_sparse_index: bool, | ||
} | ||
|
||
impl Options { | ||
/// Derive a valid mode from all parameters that affect the 'sparseness' of the index. | ||
/// | ||
/// Some combinations of them degenerate to one particular mode. | ||
pub fn sparse_mode(&self) -> Mode { | ||
match ( | ||
self.sparse_checkout, | ||
self.directory_patterns_only, | ||
self.write_sparse_index, | ||
) { | ||
(true, true, true) => Mode::IncludeDirectoriesStoreIncludedEntriesAndExcludedDirs, | ||
(true, true, false) => Mode::IncludeDirectoriesStoreAllEntriesSkipUnmatched, | ||
(true, false, _) => Mode::IncludeByIgnorePatternStoreAllEntriesSkipUnmatched, | ||
(false, _, _) => Mode::Disabled, | ||
} | ||
} | ||
} | ||
|
||
/// Describes the configuration how a sparse index should be written, or if one should be written at all. | ||
#[derive(Debug)] | ||
pub enum Mode { | ||
/// index with DIR entries for exclusion and included entries, directory-only include patterns in `.git/info/sparse-checkout` file. | ||
IncludeDirectoriesStoreIncludedEntriesAndExcludedDirs, | ||
/// index with all file entries and skip worktree flags for exclusion, directory-only include patterns in `.git/info/sparse-checkout` file. | ||
IncludeDirectoriesStoreAllEntriesSkipUnmatched, | ||
/// index with all file entries and skip-worktree flags for exclusion, `ignore` patterns to include entries in `.git/info/sparse-checkout` file. | ||
IncludeByIgnorePatternStoreAllEntriesSkipUnmatched, | ||
/// index with all entries, non is excluded, `.git/info/sparse-checkout` file is not considered, a regular index. | ||
Disabled, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use crate::extension::Signature; | ||
|
||
/// The signature of the sparse index extension, nothing more than an indicator at this time. | ||
pub const SIGNATURE: Signature = *b"sdir"; | ||
|
||
/// Serialize the sparse index extension to `out` | ||
pub fn write_to(mut out: impl std::io::Write) -> Result<(), std::io::Error> { | ||
out.write_all(&SIGNATURE)?; | ||
out.write_all(&0_u32.to_be_bytes())?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
git-index/tests/fixtures/generated-archives/v2_sparse_index_no_dirs.tar.xz
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
git-index/tests/fixtures/generated-archives/v3_skip_worktree.tar.xz
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
git-index/tests/fixtures/generated-archives/v3_sparse_index.tar.xz
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
git-index/tests/fixtures/generated-archives/v3_sparse_index_non_cone.tar.xz
Git LFS file not shown
4 changes: 2 additions & 2 deletions
4
git-index/tests/fixtures/generated-archives/v4_more_files_IEOT.tar.xz
Git LFS file not shown
20 changes: 20 additions & 0 deletions
20
git-index/tests/fixtures/make_index/v2_sparse_index_no_dirs.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
set -eu -o pipefail | ||
|
||
git init -q | ||
|
||
touch a b c | ||
|
||
git add . | ||
git commit -m "init" | ||
|
||
git config extensions.worktreeConfig true | ||
|
||
git config --worktree core.sparseCheckout true | ||
git config --worktree core.sparseCheckoutCone true | ||
git config --worktree index.sparse true | ||
|
||
echo "/*" > .git/info/sparse-checkout && | ||
echo "!/*/" >> .git/info/sparse-checkout | ||
|
||
git checkout main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
set -eu -o pipefail | ||
|
||
git init -q | ||
|
||
touch a b | ||
mkdir c1 | ||
(cd c1 && touch a b && mkdir c2 && cd c2 && touch a b) | ||
(cd c1 && mkdir c3 && cd c3 && touch a b) | ||
mkdir d | ||
(cd d && touch a b && mkdir c4 && cd c4 && touch a b c5) | ||
|
||
git add . | ||
git commit -m "init" | ||
|
||
git sparse-checkout set c1/c2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
set -eu -o pipefail | ||
|
||
git init -q | ||
|
||
touch a b | ||
mkdir c1 | ||
(cd c1 && touch a b && mkdir c2 && cd c2 && touch a b) | ||
(cd c1 && mkdir c3 && cd c3 && touch a b) | ||
mkdir d | ||
(cd d && touch a b && mkdir c4 && cd c4 && touch a b c5) | ||
|
||
git add . | ||
git commit -m "init" | ||
|
||
git sparse-checkout set c1/c2 --sparse-index |
16 changes: 16 additions & 0 deletions
16
git-index/tests/fixtures/make_index/v3_sparse_index_non_cone.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
set -eu -o pipefail | ||
|
||
git init -q | ||
|
||
touch a b | ||
mkdir c1 | ||
(cd c1 && touch a b && mkdir c2 && cd c2 && touch a b) | ||
(cd c1 && mkdir c3 && cd c3 && touch a b) | ||
mkdir d | ||
(cd d && touch a b && mkdir c4 && cd c4 && touch a b c5) | ||
|
||
git add . | ||
git commit -m "init" | ||
|
||
git sparse-checkout set c1/c2 --no-cone |
Oops, something went wrong.