Skip to content

Commit

Permalink
Flag to hide extension details (#293)
Browse files Browse the repository at this point in the history
That way understanding which extension is present is a bit easier
  • Loading branch information
Byron committed Jan 24, 2022
1 parent 3aba4b4 commit 34ea001
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
17 changes: 10 additions & 7 deletions gitoxide-core/src/index/information.rs
Original file line number Diff line number Diff line change
@@ -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))]
Expand Down Expand Up @@ -76,18 +81,16 @@ pub(crate) struct Collection {
extensions: Extensions,
}

impl TryFrom<git::index::File> for Collection {
type Error = anyhow::Error;

fn try_from(f: git::index::File) -> Result<Self, Self::Error> {
impl Collection {
pub fn try_from_file(f: git::index::File, extension_details: bool) -> anyhow::Result<Self> {
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
Expand Down
10 changes: 6 additions & 4 deletions gitoxide-core/src/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path>,
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 {
Expand All @@ -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(())
}
Expand Down
11 changes: 9 additions & 2 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 5 additions & 1 deletion src/plumbing/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
}

Expand Down

0 comments on commit 34ea001

Please sign in to comment.