diff --git a/gitoxide-core/src/index/information.rs b/gitoxide-core/src/index/information.rs index 8649aae5e87..238f04c2ce0 100644 --- a/gitoxide-core/src/index/information.rs +++ b/gitoxide-core/src/index/information.rs @@ -1,5 +1,10 @@ use git_repository as git; -use std::convert::TryFrom; + +pub struct Options { + pub index: super::Options, + /// If true, show exstension in detail. + pub extension_details: bool, +} mod ext { #[cfg_attr(feature = "serde1", derive(serde::Serialize))] @@ -76,18 +81,16 @@ pub(crate) struct Collection { extensions: Extensions, } -impl TryFrom for Collection { - type Error = anyhow::Error; - - fn try_from(f: git::index::File) -> Result { +impl Collection { + pub fn try_from_file(f: git::index::File, extension_details: bool) -> anyhow::Result { Ok(Collection { version: f.version() as u8, checksum: f.checksum.to_hex().to_string(), extensions: { let mut count = 0; - let tree = f.tree().map(|tree| { + let tree = f.tree().and_then(|tree| { count += 1; - tree.into() + extension_details.then(|| tree.into()) }); if f.link().is_some() { count += 1 diff --git a/gitoxide-core/src/index/mod.rs b/gitoxide-core/src/index/mod.rs index 6b31dadb358..d8f2e8c2275 100644 --- a/gitoxide-core/src/index/mod.rs +++ b/gitoxide-core/src/index/mod.rs @@ -10,13 +10,16 @@ pub struct Options { mod entries; #[cfg(feature = "serde1")] -mod information; +pub mod information; #[cfg_attr(not(feature = "serde1"), allow(unused_variables))] pub fn information( index_path: impl AsRef, out: impl std::io::Write, - Options { object_hash, format }: Options, + information::Options { + index: Options { object_hash, format }, + extension_details, + }: information::Options, ) -> anyhow::Result<()> { use crate::OutputFormat::*; match format { @@ -25,8 +28,7 @@ pub fn information( } #[cfg(feature = "serde1")] Json => { - use std::convert::TryFrom; - let info = information::Collection::try_from(parse_file(index_path, object_hash)?)?; + let info = information::Collection::try_from_file(parse_file(index_path, object_hash)?, extension_details)?; serde_json::to_writer_pretty(out, &info)?; Ok(()) } diff --git a/src/plumbing/main.rs b/src/plumbing/main.rs index d410daea355..2fff55607bd 100644 --- a/src/plumbing/main.rs +++ b/src/plumbing/main.rs @@ -78,14 +78,21 @@ pub fn main() -> Result<()> { index_path, cmd, }) => match cmd { - index::Subcommands::Info => prepare_and_run( + index::Subcommands::Info { no_details } => prepare_and_run( "index-entries", verbose, progress, progress_keep_open, None, move |_progress, out, _err| { - core::index::information(index_path, out, core::index::Options { object_hash, format }) + core::index::information( + index_path, + out, + core::index::information::Options { + index: core::index::Options { object_hash, format }, + extension_details: !no_details, + }, + ) }, ), index::Subcommands::Entries => prepare_and_run( diff --git a/src/plumbing/options.rs b/src/plumbing/options.rs index 59de45761b0..df5b4d1769e 100644 --- a/src/plumbing/options.rs +++ b/src/plumbing/options.rs @@ -356,7 +356,11 @@ pub mod index { /// Print all entries to standard output Entries, /// Print information about the index structure - Info, + Info { + /// Do not extract specific extension information to gain only a superficial idea of the index's composition. + #[clap(long)] + no_details: bool, + }, } }