Skip to content

Commit 8db5e51

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 8db5e51

File tree

10 files changed

+91
-1
lines changed

10 files changed

+91
-1
lines changed

Cargo.lock

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

Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ doctest = false
2525
[features]
2626
default = ["max"]
2727

28-
max = ["fast", "pretty-cli", "prodash/render-tui-crossterm", "prodash-render-line-crossterm", "http-client-curl"]
28+
max = ["fast", "pretty-cli", "prodash/render-tui-crossterm", "prodash-render-line-crossterm", "http-client-curl", "commitgraph"]
2929
max-termion = ["fast", "pretty-cli", "prodash/render-tui-termion", "prodash-render-line-termion", "http-client-curl"]
3030

3131
lean = ["fast", "lean-cli", "prodash-render-line-crossterm", "git-features/interrupt-handler", "prodash/progress-tree", "http-client-curl"]
@@ -51,6 +51,8 @@ lean-cli = ["argh", "prodash/progress-log", "env_logger"]
5151
prodash-render-line-crossterm = ["prodash-render-line", "prodash/render-line-crossterm", "atty", "crosstermion"]
5252
prodash-render-line-termion = ["prodash-render-line", "prodash/render-line-termion", "atty", "crosstermion"]
5353

54+
commitgraph = ["gitoxide-core/commitgraph"]
55+
5456
# internal
5557
prodash-render-tui = ["prodash/render-tui"]
5658
prodash-render-line = ["prodash/render-line"]

gitoxide-core/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ doctest = false
1212
test = false
1313

1414
[features]
15+
default = ["commitgraph"]
16+
commitgraph = ["git-commitgraph"]
1517
serde1 = ["git-object/serde1", "git-odb/serde1", "git-protocol/serde1", "serde_json", "serde"]
1618

1719
[package.metadata.docs.rs]
@@ -28,3 +30,4 @@ anyhow = "1.0.31"
2830
quick-error = "2.0.0"
2931
bytesize = "1.0.1"
3032
serde_json = { version = "1.0.56", optional = true }
33+
git-commitgraph = { version = "^0.1.2", path = "../git-commitgraph", optional = true }

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

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

40+
#[cfg(feature = "commitgraph")]
41+
pub mod commitgraph;
4042
pub mod pack;
4143
pub mod remote;
4244
pub mod repository;

src/plumbing/lean/main.rs

+13
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,18 @@ pub fn main() -> Result<()> {
140140
)
141141
.map(|_| ())
142142
}
143+
#[cfg(feature = "commitgraph")]
144+
SubCommands::CommitGraphVerify(CommitGraphVerify { path }) => {
145+
use self::core::commitgraph::verify;
146+
147+
verify::graph_or_file(
148+
path,
149+
verify::Context {
150+
out: stdout(),
151+
err: stderr(),
152+
},
153+
)
154+
.map(|_| ())
155+
}
143156
}
144157
}

src/plumbing/lean/options.rs

+11
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ pub enum SubCommands {
3232
IndexFromPack(IndexFromPack),
3333
RemoteRefList(RemoteRefList),
3434
PackReceive(PackReceive),
35+
#[cfg(feature = "commitgraph")]
36+
CommitGraphVerify(CommitGraphVerify),
3537
}
3638

3739
/// Create an index from a packfile.
@@ -188,3 +190,12 @@ pub struct PackVerify {
188190
#[argh(positional)]
189191
pub path: PathBuf,
190192
}
193+
194+
/// Verify a commit graph
195+
#[cfg(feature = "commitgraph")]
196+
#[derive(FromArgs, PartialEq, Debug)]
197+
#[argh(subcommand, name = "commit-graph-verify")]
198+
pub struct CommitGraphVerify {
199+
#[argh(positional)]
200+
pub path: PathBuf,
201+
}

src/plumbing/pretty/main.rs

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

src/plumbing/pretty/options.rs

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

0 commit comments

Comments
 (0)