Skip to content

Commit

Permalink
feat: Allow index access to be toggled with the index feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Sep 8, 2023
1 parent d45ca62 commit 07149e3
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 8 deletions.
11 changes: 7 additions & 4 deletions gix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ default = ["max-performance-safe", "comfort", "basic", "extras"]
#! Bundles are for convenience only and bear no further meaning beyond the cargo manifest file.

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

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

## Access to `.git/index` files.
index = ["dep:gix-index"]

## Access to credential helpers, which provide credentials for URLs.
credentials = ["dep:gix-credentials", "dep:gix-prompt"]

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

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

## Query attributes and excludes. Enables access to pathspecs, worktree checkouts, filter-pipelines and submodules.
attributes = ["excludes", "dep:gix-filter", "dep:gix-pathspec", "dep:gix-attributes", "dep:gix-submodule", "gix-worktree?/attributes"]
Expand Down Expand Up @@ -164,7 +167,7 @@ serde = [ "dep:serde",
"gix-transport?/serde",
"gix-ref/serde",
"gix-odb/serde",
"gix-index/serde",
"gix-index?/serde",
"gix-mailmap?/serde",
"gix-url/serde",
"gix-attributes?/serde",
Expand Down Expand Up @@ -217,7 +220,7 @@ gix-trace = { version = "^0.1.3", path = "../gix-trace" }
gix-glob = { version = "^0.11.0", path = "../gix-glob" }
gix-credentials = { version = "^0.18.0", path = "../gix-credentials", optional = true }
gix-prompt = { version = "^0.6.0", path = "../gix-prompt", optional = true }
gix-index = { version = "^0.23.1", path = "../gix-index" }
gix-index = { version = "^0.23.1", path = "../gix-index", optional = true }
gix-attributes = { version = "^0.17.0", path = "../gix-attributes", optional = true }
gix-ignore = { version = "^0.6.0", path = "../gix-ignore", optional = true }
gix-worktree = { version = "^0.25.0", path = "../gix-worktree", optional = true, default-features = false }
Expand Down
1 change: 1 addition & 0 deletions gix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pub use gix_hashtable as hashtable;
#[cfg(feature = "excludes")]
pub use gix_ignore as ignore;
#[doc(inline)]
#[cfg(feature = "index")]
pub use gix_index as index;
pub use gix_lock as lock;
pub use gix_negotiate as negotiate;
Expand Down
1 change: 1 addition & 0 deletions gix/src/open/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ impl ThreadSafeRepository {
config,
// used when spawning new repositories off this one when following worktrees
linked_worktree_options: options,
#[cfg(feature = "index")]
index: gix_fs::SharedFileSnapshotMut::new().into(),
shallow_commits: gix_fs::SharedFileSnapshotMut::new().into(),
#[cfg(feature = "attributes")]
Expand Down
4 changes: 4 additions & 0 deletions gix/src/repository/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ impl Clone for crate::Repository {
self.common_dir.clone(),
self.config.clone(),
self.options.clone(),
#[cfg(feature = "index")]
self.index.clone(),
self.shallow_commits.clone(),
#[cfg(feature = "attributes")]
Expand Down Expand Up @@ -42,6 +43,7 @@ impl From<&crate::ThreadSafeRepository> for crate::Repository {
repo.common_dir.clone(),
repo.config.clone(),
repo.linked_worktree_options.clone(),
#[cfg(feature = "index")]
repo.index.clone(),
repo.shallow_commits.clone(),
#[cfg(feature = "attributes")]
Expand All @@ -59,6 +61,7 @@ impl From<crate::ThreadSafeRepository> for crate::Repository {
repo.common_dir,
repo.config,
repo.linked_worktree_options,
#[cfg(feature = "index")]
repo.index,
repo.shallow_commits,
#[cfg(feature = "attributes")]
Expand All @@ -76,6 +79,7 @@ impl From<crate::Repository> for crate::ThreadSafeRepository {
common_dir: r.common_dir,
config: r.config,
linked_worktree_options: r.options,
#[cfg(feature = "index")]
index: r.index,
#[cfg(feature = "attributes")]
modules: r.modules,
Expand Down
3 changes: 2 additions & 1 deletion gix/src/repository/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl crate::Repository {
common_dir: Option<std::path::PathBuf>,
config: crate::config::Cache,
linked_worktree_options: crate::open::Options,
index: crate::worktree::IndexStorage,
#[cfg(feature = "index")] index: crate::worktree::IndexStorage,
shallow_commits: crate::shallow::CommitsStorage,
#[cfg(feature = "attributes")] modules: crate::submodule::ModulesFileStorage,
) -> Self {
Expand All @@ -22,6 +22,7 @@ impl crate::Repository {
refs,
config,
options: linked_worktree_options,
#[cfg(feature = "index")]
index,
shallow_commits,
#[cfg(feature = "attributes")]
Expand Down
3 changes: 3 additions & 0 deletions gix/src/repository/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub mod filter;
mod graph;
pub(crate) mod identity;
mod impls;
#[cfg(feature = "index")]
mod index;
pub(crate) mod init;
mod kind;
Expand All @@ -66,6 +67,7 @@ mod thread_safe;
mod worktree;

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

///
#[cfg(feature = "index")]
pub mod index_or_load_from_head {
/// The error returned by [`Repository::index_or_load_from_head()`][crate::Repository::index_or_load_from_head()].
#[derive(thiserror::Error, Debug)]
Expand Down
2 changes: 2 additions & 0 deletions gix/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ pub struct Repository {
///
/// Particularly useful when following linked worktrees and instantiating new equally configured worktree repositories.
pub(crate) options: crate::open::Options,
#[cfg(feature = "index")]
pub(crate) index: crate::worktree::IndexStorage,
#[cfg(feature = "attributes")]
pub(crate) modules: crate::submodule::ModulesFileStorage,
Expand Down Expand Up @@ -167,6 +168,7 @@ pub struct ThreadSafeRepository {
/// options obtained when instantiating this repository for use when following linked worktrees.
pub(crate) linked_worktree_options: crate::open::Options,
/// The index of this instances worktree.
#[cfg(feature = "index")]
pub(crate) index: crate::worktree::IndexStorage,
#[cfg(feature = "attributes")]
pub(crate) modules: crate::submodule::ModulesFileStorage,
Expand Down
3 changes: 3 additions & 0 deletions gix/src/worktree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ use crate::{
Repository,
};

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

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

///
#[cfg(feature = "index")]
pub mod open_index {
/// The error returned by [`Worktree::open_index()`][crate::Worktree::open_index()].
#[derive(Debug, thiserror::Error)]
Expand Down
5 changes: 2 additions & 3 deletions gix/tests/repository/worktree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ fn archive() -> crate::Result {
mod with_core_worktree_config {
use std::io::BufRead;

use crate::repository::worktree::Baseline;

#[test]
#[cfg(feature = "index")]
fn relative() -> crate::Result {
for (name, is_relative) in [("absolute-worktree", false), ("relative-worktree", true)] {
let repo = repo(name);
Expand All @@ -61,7 +60,7 @@ mod with_core_worktree_config {
"current worktree is based on work-tree dir"
);

let baseline = Baseline::collect(repo.git_dir())?;
let baseline = crate::repository::worktree::Baseline::collect(repo.git_dir())?;
assert_eq!(baseline.len(), 1, "git lists the main worktree");
assert_eq!(
baseline[0].root,
Expand Down
1 change: 1 addition & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ check:
cargo check -p gix --no-default-features --features attributes --tests
cargo check -p gix --no-default-features --features worktree-mutation --tests
cargo check -p gix --no-default-features --features credentials --tests
cargo check -p gix --no-default-features --features index --tests
cargo check -p gix --no-default-features
cargo check -p gix-odb --features serde
cargo check --no-default-features --features max-control
Expand Down

0 comments on commit 07149e3

Please sign in to comment.