Skip to content

Commit

Permalink
[commitgraph] Stub out commit-graph-verify plumbing command.
Browse files Browse the repository at this point in the history
Commit graphs are optional, so commit-graph plumbing is guarded by a
`commitgraph` feature that is enabled by default.
  • Loading branch information
avoidscorn committed Oct 11, 2020
1 parent d5eef9c commit aacf0f0
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions gitoxide-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ anyhow = "1.0.31"
quick-error = "2.0.0"
bytesize = "1.0.1"
serde_json = { version = "1.0.56", optional = true }
git-commitgraph = { version = "^0.1.2", path = "../git-commitgraph" }
1 change: 1 addition & 0 deletions gitoxide-core/src/commitgraph/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod verify;
36 changes: 36 additions & 0 deletions gitoxide-core/src/commitgraph/verify.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use anyhow::{Context as AnyhowContext, Result};
use std::{io, path::Path};

/// A general purpose context for many operations provided here
pub struct Context<W1: io::Write, W2: io::Write> {
/// A stream to which to output operation results
pub out: W1,
/// A stream to which to errors
pub err: W2,
}

impl Default for Context<Vec<u8>, Vec<u8>> {
fn default() -> Self {
Context {
out: Vec::new(),
err: Vec::new(),
}
}
}

pub fn graph_or_file<W1, W2>(
path: impl AsRef<Path>,
Context {
out: mut _out,
err: mut _err,
}: Context<W1, W2>,
) -> Result<()>
where
W1: io::Write,
W2: io::Write,
{
// TODO: Handle `path` being objects/info, objects/info/commit-graph,
// or objects/info/commit-graphs/graph-xyz.graph.
let _g = git_commitgraph::Graph::from_info_dir(path).with_context(|| "Could not open commit graph")?;
Err(anyhow::Error::msg("not implemented"))
}
1 change: 1 addition & 0 deletions gitoxide-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ impl FromStr for OutputFormat {
mod protocol;
pub use protocol::Protocol;

pub mod commitgraph;
pub mod pack;
pub mod remote;
pub mod repository;
12 changes: 12 additions & 0 deletions src/plumbing/lean/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,17 @@ pub fn main() -> Result<()> {
)
.map(|_| ())
}
SubCommands::CommitGraphVerify(CommitGraphVerify { path }) => {
use self::core::commitgraph::verify;

verify::graph_or_file(
path,
verify::Context {
out: stdout(),
err: stderr(),
},
)
.map(|_| ())
}
}
}
9 changes: 9 additions & 0 deletions src/plumbing/lean/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub enum SubCommands {
IndexFromPack(IndexFromPack),
RemoteRefList(RemoteRefList),
PackReceive(PackReceive),
CommitGraphVerify(CommitGraphVerify),
}

/// Create an index from a packfile.
Expand Down Expand Up @@ -188,3 +189,11 @@ pub struct PackVerify {
#[argh(positional)]
pub path: PathBuf,
}

/// Verify a commit graph
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "commit-graph-verify")]
pub struct CommitGraphVerify {
#[argh(positional)]
pub path: PathBuf,
}
11 changes: 11 additions & 0 deletions src/plumbing/pretty/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,17 @@ pub fn main() -> Result<()> {
},
)
.map(|_| ()),
Subcommands::CommitGraphVerify { path } => prepare_and_run(
"commit-graph-verify",
verbose,
progress,
progress_keep_open,
None,
move |_progress, out, err| {
core::commitgraph::verify::graph_or_file(path, core::commitgraph::verify::Context { out, err })
},
)
.map(|_| ()),
}?;
Ok(())
}
8 changes: 8 additions & 0 deletions src/plumbing/pretty/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,12 @@ pub enum Subcommands {
#[clap(parse(from_os_str))]
path: PathBuf,
},
/// Verify the integrity of a commit graph
#[clap(setting = AppSettings::ColoredHelp)]
#[clap(setting = AppSettings::DisableVersion)]
CommitGraphVerify {
/// The 'objects/info/' dir, 'objects/info/commit-graphs' dir, or 'objects/info/commit-graph' file to validate.
#[clap(parse(from_os_str))]
path: PathBuf,
},
}

0 comments on commit aacf0f0

Please sign in to comment.