diff --git a/Cargo.lock b/Cargo.lock index 6bac2ccc1ea..58cd70f8830 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1526,6 +1526,7 @@ dependencies = [ "git-diff 0.13.0", "git-features 0.19.0", "git-hash 0.9.0", + "git-index", "git-lock 1.0.1", "git-object 0.17.0", "git-odb 0.26.0", diff --git a/git-bitmap/src/ewah.rs b/git-bitmap/src/ewah.rs index e504050da2c..7575a59e2d6 100644 --- a/git-bitmap/src/ewah.rs +++ b/git-bitmap/src/ewah.rs @@ -119,6 +119,6 @@ mod access { pub struct Vec { num_bits: u32, bits: std::vec::Vec, - /// RLW is an offset into the `bits` buffer, so `1` translates into &bits[1] essentially. + /// RLW is an offset into the `bits` buffer, so `1` translates into &bits\[1] essentially. rlw: usize, } diff --git a/git-repository/Cargo.toml b/git-repository/Cargo.toml index 8cd8801819b..5777f6e22da 100644 --- a/git-repository/Cargo.toml +++ b/git-repository/Cargo.toml @@ -14,7 +14,7 @@ test = true [features] default = ["max-performance", "one-stop-shop"] -unstable = [] +unstable = ["git-index"] serde1 = ["git-pack/serde1", "git-object/serde1", "git-protocol/serde1", "git-transport/serde1", "git-ref/serde1", "git-odb/serde1"] # enable when https://github.com/RustCrypto/asm-hashes/issues/17 is fixed # max-performance = ["git-features/parallel", "git-features/zlib-ng-compat", "git-features/fast-sha1"] @@ -54,6 +54,9 @@ git-transport = { version = "^0.15.0", path = "../git-transport", optional = tru git-diff = { version = "^0.13.0", path = "../git-diff", optional = true } git-features = { version = "^0.19.0", path = "../git-features", features = ["progress"] } +# unstable only +git-index = { version ="^0.1.0", path = "../git-index", optional = true } + signal-hook = { version = "0.3.9", default-features = false } thiserror = "1.0.26" clru = "0.5.0" diff --git a/git-repository/src/lib.rs b/git-repository/src/lib.rs index 8f47c687b0c..fca7e00eb02 100644 --- a/git-repository/src/lib.rs +++ b/git-repository/src/lib.rs @@ -86,6 +86,7 @@ //! * [`url`] //! * [`actor`] //! * [`bstr`][bstr] +//! * [`index`] //! * [`objs`] //! * [`odb`] //! * [`pack`][odb::pack] @@ -118,6 +119,8 @@ pub use git_features::{parallel, progress, progress::Progress, threading}; pub use git_hash as hash; #[doc(inline)] pub use git_hash::{oid, ObjectId}; +#[cfg(all(feature = "unstable", feature = "git-index"))] +pub use git_index as index; pub use git_lock as lock; pub use git_object as objs; pub use git_object::bstr; @@ -151,9 +154,10 @@ pub mod prelude { pub mod path; mod repository; -use git_features::threading::OwnShared; pub use repository::{discover, init, open}; +use git_features::threading::OwnShared; + /// The standard type for a store to handle git references. pub type RefStore = git_ref::file::Store; /// A handle for finding objects in an object database, abstracting away caches for thread-local use. diff --git a/gitoxide-core/src/index.rs b/gitoxide-core/src/index.rs new file mode 100644 index 00000000000..c565d5eb77e --- /dev/null +++ b/gitoxide-core/src/index.rs @@ -0,0 +1,18 @@ +use git_repository as git; +use std::path::Path; + +#[allow(unused)] +pub fn entries( + index_path: impl AsRef, + out: impl std::io::Write, + object_hash: git::hash::Kind, +) -> anyhow::Result<()> { + let file = git::index::File::at( + index_path.as_ref(), + git::index::decode::Options { + object_hash, + ..Default::default() + }, + )?; + todo!("print entries") +} diff --git a/gitoxide-core/src/lib.rs b/gitoxide-core/src/lib.rs index 6977191ee70..0f89d1d0f19 100644 --- a/gitoxide-core/src/lib.rs +++ b/gitoxide-core/src/lib.rs @@ -40,6 +40,7 @@ pub mod net; pub mod commitgraph; #[cfg(feature = "estimate-hours")] pub mod hours; +pub mod index; #[cfg(feature = "organize")] pub mod organize; pub mod pack; diff --git a/src/plumbing/main.rs b/src/plumbing/main.rs index 6824f0abdbf..b26f62ca537 100644 --- a/src/plumbing/main.rs +++ b/src/plumbing/main.rs @@ -12,6 +12,7 @@ use clap::Parser; use gitoxide_core as core; use gitoxide_core::pack::verify; +use crate::plumbing::options::index; #[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))] use crate::plumbing::options::remote; use crate::{ @@ -73,6 +74,19 @@ pub fn main() -> Result<()> { })?; match cmd { + Subcommands::Index(subcommands) => match subcommands { + index::Subcommands::Entries { + object_hash, + index_path, + } => prepare_and_run( + "index-entries", + verbose, + progress, + progress_keep_open, + None, + move |_progress, out, _err| core::index::entries(index_path, out, object_hash), + ), + }, Subcommands::Repository(subcommands) => match subcommands { repo::Subcommands::Verify { args: diff --git a/src/plumbing/options.rs b/src/plumbing/options.rs index e241c5b99d2..23c018554da 100644 --- a/src/plumbing/options.rs +++ b/src/plumbing/options.rs @@ -56,6 +56,9 @@ pub enum Subcommands { /// Subcommands for interacting with commit-graphs #[clap(subcommand)] CommitGraph(commitgraph::Subcommands), + /// Subcommands for interacting with a worktree index, typically at .git/index + #[clap(subcommand)] + Index(index::Subcommands), /// Subcommands for interacting with entire git repositories #[clap(subcommand)] Repository(repo::Subcommands), @@ -344,6 +347,28 @@ pub mod repo { } } +/// +pub mod index { + use std::path::PathBuf; + + use clap::AppSettings; + + #[derive(Debug, clap::Parser)] + #[clap(alias = "repo")] + pub enum Subcommands { + /// Print all entries to standard output + #[clap(setting = AppSettings::DisableVersionFlag)] + Entries { + /// The object format to assume when reading files that don't inherently know about it, or when writing files. + #[clap(long, default_value = "sha1", possible_values(&["sha1"]))] + object_hash: git_repository::hash::Kind, + + /// The path too the index file. + index_path: PathBuf, + }, + } +} + /// pub mod commitgraph { use std::path::PathBuf;