Skip to content

Commit

Permalink
Add 'index verify' subcommand to 'gix' (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jan 27, 2022
1 parent 2d101eb commit 1ac2c21
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
30 changes: 27 additions & 3 deletions gitoxide-core/src/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,43 @@ mod entries;

pub mod information;

#[cfg_attr(not(feature = "serde1"), allow(unused_variables))]
pub fn verify(
index_path: impl AsRef<Path>,
mut out: impl std::io::Write,
Options { object_hash, format }: Options,
) -> anyhow::Result<()> {
let file = parse_file(index_path, object_hash)?;
file.verify_integrity()?;
file.verify_entries()?;
#[cfg_attr(not(feature = "serde1"), allow(irrefutable_let_patterns))]
if let crate::OutputFormat::Human = format {
writeln!(out, "OK").ok();
}
Ok(())
}

#[cfg_attr(not(feature = "serde1"), allow(unused_variables, unused_mut))]
pub fn information(
index_path: impl AsRef<Path>,
out: impl std::io::Write,
mut err: impl std::io::Write,
information::Options {
index: Options { object_hash, format },
index: Options {
object_hash,
mut format,
},
extension_details,
}: information::Options,
) -> anyhow::Result<()> {
use crate::OutputFormat::*;
#[cfg(feature = "serde1")]
if let Human = format {
writeln!(err, "Defaulting to JSON printing as nothing else will be implemented.").ok();
format = Json;
}
match format {
Human => {
anyhow::bail!("Only JSON output is implemented");
anyhow::bail!("Cannot print information using 'human' format.")
}
#[cfg(feature = "serde1")]
Json => {
Expand Down
13 changes: 12 additions & 1 deletion src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ pub fn main() -> Result<()> {
progress,
progress_keep_open,
None,
move |_progress, out, _err| {
move |_progress, out, err| {
core::index::information(
index_path,
out,
err,
core::index::information::Options {
index: core::index::Options { object_hash, format },
extension_details: !no_details,
Expand All @@ -105,6 +106,16 @@ pub fn main() -> Result<()> {
core::index::entries(index_path, out, core::index::Options { object_hash, format })
},
),
index::Subcommands::Verify => prepare_and_run(
"index-verify",
verbose,
progress,
progress_keep_open,
None,
move |_progress, out, _err| {
core::index::verify(index_path, out, core::index::Options { object_hash, format })
},
),
},
Subcommands::Repository(subcommands) => match subcommands {
repo::Subcommands::Verify {
Expand Down
2 changes: 2 additions & 0 deletions src/plumbing/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ pub mod index {

#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
/// Validate constraints and assumptions of an index along with its integrity.
Verify,
/// Print all entries to standard output
Entries,
/// Print information about the index structure
Expand Down

0 comments on commit 1ac2c21

Please sign in to comment.