Skip to content

Commit 07149e3

Browse files
committed
feat: Allow index access to be toggled with the index feature.
1 parent d45ca62 commit 07149e3

File tree

10 files changed

+26
-8
lines changed

10 files changed

+26
-8
lines changed

gix/Cargo.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ default = ["max-performance-safe", "comfort", "basic", "extras"]
4848
#! Bundles are for convenience only and bear no further meaning beyond the cargo manifest file.
4949

5050
## More fundamental components that most will be able to make good use of.
51-
basic = ["blob-diff", "revision"]
51+
basic = ["blob-diff", "revision", "index"]
5252

5353
## Various additional features and capabilities that are not necessarily part of what most users would need.
5454
extras = ["worktree-stream", "worktree-archive", "revparse-regex", "mailmap", "excludes", "attributes", "worktree-mutation", "credentials"]
@@ -61,14 +61,17 @@ comfort = ["gix-features/progress-unit-bytes", "gix-features/progress-unit-human
6161
#! A component is a distinct feature which may be comprised of one or more methods around a particular topic.
6262
#! Providers of libraries should only activate the components they need.
6363

64+
## Access to `.git/index` files.
65+
index = ["dep:gix-index"]
66+
6467
## Access to credential helpers, which provide credentials for URLs.
6568
credentials = ["dep:gix-credentials", "dep:gix-prompt"]
6669

6770
## Various ways to alter the worktree makeup by checkout and reset.
6871
worktree-mutation = ["attributes", "dep:gix-worktree-state"]
6972

7073
## Retrieve a worktree stack for querying exclude information
71-
excludes = ["dep:gix-ignore", "dep:gix-worktree"]
74+
excludes = ["dep:gix-ignore", "dep:gix-worktree", "index"]
7275

7376
## Query attributes and excludes. Enables access to pathspecs, worktree checkouts, filter-pipelines and submodules.
7477
attributes = ["excludes", "dep:gix-filter", "dep:gix-pathspec", "dep:gix-attributes", "dep:gix-submodule", "gix-worktree?/attributes"]
@@ -164,7 +167,7 @@ serde = [ "dep:serde",
164167
"gix-transport?/serde",
165168
"gix-ref/serde",
166169
"gix-odb/serde",
167-
"gix-index/serde",
170+
"gix-index?/serde",
168171
"gix-mailmap?/serde",
169172
"gix-url/serde",
170173
"gix-attributes?/serde",
@@ -217,7 +220,7 @@ gix-trace = { version = "^0.1.3", path = "../gix-trace" }
217220
gix-glob = { version = "^0.11.0", path = "../gix-glob" }
218221
gix-credentials = { version = "^0.18.0", path = "../gix-credentials", optional = true }
219222
gix-prompt = { version = "^0.6.0", path = "../gix-prompt", optional = true }
220-
gix-index = { version = "^0.23.1", path = "../gix-index" }
223+
gix-index = { version = "^0.23.1", path = "../gix-index", optional = true }
221224
gix-attributes = { version = "^0.17.0", path = "../gix-attributes", optional = true }
222225
gix-ignore = { version = "^0.6.0", path = "../gix-ignore", optional = true }
223226
gix-worktree = { version = "^0.25.0", path = "../gix-worktree", optional = true, default-features = false }

gix/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pub use gix_hashtable as hashtable;
9797
#[cfg(feature = "excludes")]
9898
pub use gix_ignore as ignore;
9999
#[doc(inline)]
100+
#[cfg(feature = "index")]
100101
pub use gix_index as index;
101102
pub use gix_lock as lock;
102103
pub use gix_negotiate as negotiate;

gix/src/open/repository.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ impl ThreadSafeRepository {
292292
config,
293293
// used when spawning new repositories off this one when following worktrees
294294
linked_worktree_options: options,
295+
#[cfg(feature = "index")]
295296
index: gix_fs::SharedFileSnapshotMut::new().into(),
296297
shallow_commits: gix_fs::SharedFileSnapshotMut::new().into(),
297298
#[cfg(feature = "attributes")]

gix/src/repository/impls.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ impl Clone for crate::Repository {
77
self.common_dir.clone(),
88
self.config.clone(),
99
self.options.clone(),
10+
#[cfg(feature = "index")]
1011
self.index.clone(),
1112
self.shallow_commits.clone(),
1213
#[cfg(feature = "attributes")]
@@ -42,6 +43,7 @@ impl From<&crate::ThreadSafeRepository> for crate::Repository {
4243
repo.common_dir.clone(),
4344
repo.config.clone(),
4445
repo.linked_worktree_options.clone(),
46+
#[cfg(feature = "index")]
4547
repo.index.clone(),
4648
repo.shallow_commits.clone(),
4749
#[cfg(feature = "attributes")]
@@ -59,6 +61,7 @@ impl From<crate::ThreadSafeRepository> for crate::Repository {
5961
repo.common_dir,
6062
repo.config,
6163
repo.linked_worktree_options,
64+
#[cfg(feature = "index")]
6265
repo.index,
6366
repo.shallow_commits,
6467
#[cfg(feature = "attributes")]
@@ -76,6 +79,7 @@ impl From<crate::Repository> for crate::ThreadSafeRepository {
7679
common_dir: r.common_dir,
7780
config: r.config,
7881
linked_worktree_options: r.options,
82+
#[cfg(feature = "index")]
7983
index: r.index,
8084
#[cfg(feature = "attributes")]
8185
modules: r.modules,

gix/src/repository/init.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ impl crate::Repository {
99
common_dir: Option<std::path::PathBuf>,
1010
config: crate::config::Cache,
1111
linked_worktree_options: crate::open::Options,
12-
index: crate::worktree::IndexStorage,
12+
#[cfg(feature = "index")] index: crate::worktree::IndexStorage,
1313
shallow_commits: crate::shallow::CommitsStorage,
1414
#[cfg(feature = "attributes")] modules: crate::submodule::ModulesFileStorage,
1515
) -> Self {
@@ -22,6 +22,7 @@ impl crate::Repository {
2222
refs,
2323
config,
2424
options: linked_worktree_options,
25+
#[cfg(feature = "index")]
2526
index,
2627
shallow_commits,
2728
#[cfg(feature = "attributes")]

gix/src/repository/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub mod filter;
4545
mod graph;
4646
pub(crate) mod identity;
4747
mod impls;
48+
#[cfg(feature = "index")]
4849
mod index;
4950
pub(crate) mod init;
5051
mod kind;
@@ -66,6 +67,7 @@ mod thread_safe;
6667
mod worktree;
6768

6869
/// A type to represent an index which either was loaded from disk as it was persisted there, or created on the fly in memory.
70+
#[cfg(feature = "index")]
6971
pub enum IndexPersistedOrInMemory {
7072
/// The index as loaded from disk, and shared across clones of the owning `Repository`.
7173
Persisted(crate::worktree::Index),
@@ -90,6 +92,7 @@ pub mod pathspec_defaults_ignore_case {
9092
}
9193

9294
///
95+
#[cfg(feature = "index")]
9396
pub mod index_or_load_from_head {
9497
/// The error returned by [`Repository::index_or_load_from_head()`][crate::Repository::index_or_load_from_head()].
9598
#[derive(thiserror::Error, Debug)]

gix/src/types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ pub struct Repository {
138138
///
139139
/// Particularly useful when following linked worktrees and instantiating new equally configured worktree repositories.
140140
pub(crate) options: crate::open::Options,
141+
#[cfg(feature = "index")]
141142
pub(crate) index: crate::worktree::IndexStorage,
142143
#[cfg(feature = "attributes")]
143144
pub(crate) modules: crate::submodule::ModulesFileStorage,
@@ -167,6 +168,7 @@ pub struct ThreadSafeRepository {
167168
/// options obtained when instantiating this repository for use when following linked worktrees.
168169
pub(crate) linked_worktree_options: crate::open::Options,
169170
/// The index of this instances worktree.
171+
#[cfg(feature = "index")]
170172
pub(crate) index: crate::worktree::IndexStorage,
171173
#[cfg(feature = "attributes")]
172174
pub(crate) modules: crate::submodule::ModulesFileStorage,

gix/src/worktree/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ use crate::{
1414
Repository,
1515
};
1616

17+
#[cfg(feature = "index")]
1718
pub(crate) type IndexStorage = gix_features::threading::OwnShared<gix_fs::SharedFileSnapshotMut<gix_index::File>>;
1819
/// A lazily loaded and auto-updated worktree index.
20+
#[cfg(feature = "index")]
1921
pub type Index = gix_fs::SharedFileSnapshot<gix_index::File>;
2022

2123
/// A stand-in to a worktree as result of a worktree iteration.
@@ -84,6 +86,7 @@ pub(crate) fn id(git_dir: &std::path::Path, has_common_dir: bool) -> Option<&BSt
8486
pub mod proxy;
8587

8688
///
89+
#[cfg(feature = "index")]
8790
pub mod open_index {
8891
/// The error returned by [`Worktree::open_index()`][crate::Worktree::open_index()].
8992
#[derive(Debug, thiserror::Error)]

gix/tests/repository/worktree.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ fn archive() -> crate::Result {
3434
mod with_core_worktree_config {
3535
use std::io::BufRead;
3636

37-
use crate::repository::worktree::Baseline;
38-
3937
#[test]
38+
#[cfg(feature = "index")]
4039
fn relative() -> crate::Result {
4140
for (name, is_relative) in [("absolute-worktree", false), ("relative-worktree", true)] {
4241
let repo = repo(name);
@@ -61,7 +60,7 @@ mod with_core_worktree_config {
6160
"current worktree is based on work-tree dir"
6261
);
6362

64-
let baseline = Baseline::collect(repo.git_dir())?;
63+
let baseline = crate::repository::worktree::Baseline::collect(repo.git_dir())?;
6564
assert_eq!(baseline.len(), 1, "git lists the main worktree");
6665
assert_eq!(
6766
baseline[0].root,

justfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ check:
126126
cargo check -p gix --no-default-features --features attributes --tests
127127
cargo check -p gix --no-default-features --features worktree-mutation --tests
128128
cargo check -p gix --no-default-features --features credentials --tests
129+
cargo check -p gix --no-default-features --features index --tests
129130
cargo check -p gix --no-default-features
130131
cargo check -p gix-odb --features serde
131132
cargo check --no-default-features --features max-control

0 commit comments

Comments
 (0)