Skip to content

Commit c418871

Browse files
committed
[commitgraph] Stub out commit-graph-verify plumbing command.
Commit graphs are optional, so commit-graph plumbing is guarded by a `commitgraph` feature that is enabled by default.
1 parent 98c1360 commit c418871

File tree

9 files changed

+80
-0
lines changed

9 files changed

+80
-0
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gitoxide-core/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ anyhow = "1.0.31"
2828
quick-error = "2.0.0"
2929
bytesize = "1.0.1"
3030
serde_json = { version = "1.0.56", optional = true }
31+
git-commitgraph = { version = "^0.1.2", path = "../git-commitgraph" }

gitoxide-core/src/commitgraph/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod verify;
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use anyhow::{Context as AnyhowContext, Result};
2+
use std::{io, path::Path};
3+
4+
/// A general purpose context for many operations provided here
5+
pub struct Context<W1: io::Write, W2: io::Write> {
6+
/// A stream to which to output operation results
7+
pub out: W1,
8+
/// A stream to which to errors
9+
pub err: W2,
10+
}
11+
12+
impl Default for Context<Vec<u8>, Vec<u8>> {
13+
fn default() -> Self {
14+
Context {
15+
out: Vec::new(),
16+
err: Vec::new(),
17+
}
18+
}
19+
}
20+
21+
pub fn graph_or_file<W1, W2>(
22+
path: impl AsRef<Path>,
23+
Context {
24+
out: mut _out,
25+
err: mut _err,
26+
}: Context<W1, W2>,
27+
) -> Result<()>
28+
where
29+
W1: io::Write,
30+
W2: io::Write,
31+
{
32+
// TODO: Handle `path` being objects/info, objects/info/commit-graph,
33+
// or objects/info/commit-graphs/graph-xyz.graph.
34+
let _g = git_commitgraph::Graph::from_info_dir(path).with_context(|| "Could not open commit graph")?;
35+
Err(anyhow::Error::msg("not implemented"))
36+
}

gitoxide-core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ impl FromStr for OutputFormat {
3737
mod protocol;
3838
pub use protocol::Protocol;
3939

40+
pub mod commitgraph;
4041
pub mod pack;
4142
pub mod remote;
4243
pub mod repository;

src/plumbing/lean/main.rs

+12
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,17 @@ pub fn main() -> Result<()> {
140140
)
141141
.map(|_| ())
142142
}
143+
SubCommands::CommitGraphVerify(CommitGraphVerify { path }) => {
144+
use self::core::commitgraph::verify;
145+
146+
verify::graph_or_file(
147+
path,
148+
verify::Context {
149+
out: stdout(),
150+
err: stderr(),
151+
},
152+
)
153+
.map(|_| ())
154+
}
143155
}
144156
}

src/plumbing/lean/options.rs

+9
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub enum SubCommands {
3232
IndexFromPack(IndexFromPack),
3333
RemoteRefList(RemoteRefList),
3434
PackReceive(PackReceive),
35+
CommitGraphVerify(CommitGraphVerify),
3536
}
3637

3738
/// Create an index from a packfile.
@@ -188,3 +189,11 @@ pub struct PackVerify {
188189
#[argh(positional)]
189190
pub path: PathBuf,
190191
}
192+
193+
/// Verify a commit graph
194+
#[derive(FromArgs, PartialEq, Debug)]
195+
#[argh(subcommand, name = "commit-graph-verify")]
196+
pub struct CommitGraphVerify {
197+
#[argh(positional)]
198+
pub path: PathBuf,
199+
}

src/plumbing/pretty/main.rs

+11
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,17 @@ pub fn main() -> Result<()> {
256256
},
257257
)
258258
.map(|_| ()),
259+
Subcommands::CommitGraphVerify { path } => prepare_and_run(
260+
"commit-graph-verify",
261+
verbose,
262+
progress,
263+
progress_keep_open,
264+
None,
265+
move |_progress, out, err| {
266+
core::commitgraph::verify::graph_or_file(path, core::commitgraph::verify::Context { out, err })
267+
},
268+
)
269+
.map(|_| ()),
259270
}?;
260271
Ok(())
261272
}

src/plumbing/pretty/options.rs

+8
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,12 @@ pub enum Subcommands {
186186
#[clap(parse(from_os_str))]
187187
path: PathBuf,
188188
},
189+
/// Verify the integrity of a commit graph
190+
#[clap(setting = AppSettings::ColoredHelp)]
191+
#[clap(setting = AppSettings::DisableVersion)]
192+
CommitGraphVerify {
193+
/// The 'objects/info/' dir, 'objects/info/commit-graphs' dir, or 'objects/info/commit-graph' file to validate.
194+
#[clap(parse(from_os_str))]
195+
path: PathBuf,
196+
},
189197
}

0 commit comments

Comments
 (0)