Skip to content

Commit

Permalink
'commitgraph' with its own sub-commands (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jan 1, 2022
1 parent 4137327 commit db0251e
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 51 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ Please see _'Development Status'_ for a listing of all crates and their capabili
for consumption by **pack-receive** or _git-receive-pack_
* [x] [index from data](https://asciinema.org/a/352941) - create an index file by streaming a pack file as done during clone
* [ ] support for thin packs (as needed for fetch/pull)
* **commit-graph**
* [x] **verify** - assure that a commit-graph is consistent
* **commitgraph**
* [x] **verify** - assure that a commitgraph is consistent
* [remote-ref-list](https://asciinema.org/a/359320)
* [x] list all (or given) references from a remote at the given URL

Expand Down
42 changes: 22 additions & 20 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use gitoxide_core as core;
use gitoxide_core::pack::verify;

use crate::{
plumbing::options::{Args, Subcommands},
plumbing::options::{commitgraph, Args, Subcommands},
shared::pretty::prepare_and_run,
};

Expand Down Expand Up @@ -307,25 +307,27 @@ pub fn main() -> Result<()> {
},
)
.map(|_| ()),
Subcommands::CommitGraphVerify { path, statistics } => prepare_and_run(
"commit-graph-verify",
verbose,
progress,
progress_keep_open,
None,
move |_progress, out, err| {
let output_statistics = if statistics { Some(format) } else { None };
core::commitgraph::verify::graph_or_file(
path,
core::commitgraph::verify::Context {
err,
out,
output_statistics,
},
)
},
)
.map(|_| ()),
Subcommands::Commitgraph(subcommands) => match subcommands {
commitgraph::Subcommands::Verify { path, statistics } => prepare_and_run(
"commit-graph-verify",
verbose,
progress,
progress_keep_open,
None,
move |_progress, out, err| {
let output_statistics = if statistics { Some(format) } else { None };
core::commitgraph::verify::graph_or_file(
path,
core::commitgraph::verify::Context {
err,
out,
output_statistics,
},
)
},
)
.map(|_| ()),
},
}?;
Ok(())
}
32 changes: 22 additions & 10 deletions src/plumbing/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,26 @@ pub enum Subcommands {
#[clap(parse(from_os_str))]
path: PathBuf,
},
/// Verify the integrity of a commit graph
#[clap(setting = AppSettings::DisableVersionFlag)]
CommitGraphVerify {
/// The path to '.git/objects/info/', '.git/objects/info/commit-graphs/', or '.git/objects/info/commit-graph' to validate.
#[clap(parse(from_os_str))]
path: PathBuf,
/// output statistical information about the pack
#[clap(long, short = 's')]
statistics: bool,
},
/// Subcommands for interacting with commitgraphs
#[clap(subcommand)]
Commitgraph(commitgraph::Subcommands),
}

///
pub mod commitgraph {
use clap::AppSettings;
use std::path::PathBuf;

#[derive(Debug, clap::Parser)]
pub enum Subcommands {
#[clap(setting = AppSettings::DisableVersionFlag)]
Verify {
/// The path to '.git/objects/info/', '.git/objects/info/commit-graphs/', or '.git/objects/info/commit-graph' to validate.
#[clap(parse(from_os_str))]
path: PathBuf,
/// output statistical information about the pack
#[clap(long, short = 's')]
statistics: bool,
},
}
}
44 changes: 25 additions & 19 deletions tests/journey/gix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -493,26 +493,32 @@ title "gix pack-verify"
)
)
)
title "gix commit-graph-verify"
(when "running 'commit-graph-verify'"
snapshot="$snapshot/commit-graph-verify"
(small-repo-in-sandbox
(with "a valid and complete commit-graph file"
git commit-graph write --reachable
(with "statistics"
it "generates the correct output" && {
WITH_SNAPSHOT="$snapshot/statistics-success" \
expect_run $SUCCESSFULLY "$exe_plumbing" commit-graph-verify -s .git/objects/info
}
)
if test "$kind" = "max"; then
(with "statistics --format json"
it "generates the correct output" && {
WITH_SNAPSHOT="$snapshot/statistics-json-success" \
expect_run $SUCCESSFULLY "$exe_plumbing" --format json commit-graph-verify -s .git/objects/info
}

title "gix commitgraph"
(when "running 'commitgraph'"
snapshot="$snapshot/commitgraph"
title "gix commitgraph verify"
(with "the 'verify' sub-command"
snapshot="$snapshot/verify"

(small-repo-in-sandbox
(with "a valid and complete commit-graph file"
git commit-graph write --reachable
(with "statistics"
it "generates the correct output" && {
WITH_SNAPSHOT="$snapshot/statistics-success" \
expect_run $SUCCESSFULLY "$exe_plumbing" commitgraph verify -s .git/objects/info
}
)
if test "$kind" = "max"; then
(with "statistics --format json"
it "generates the correct output" && {
WITH_SNAPSHOT="$snapshot/statistics-json-success" \
expect_run $SUCCESSFULLY "$exe_plumbing" --format json commitgraph verify -s .git/objects/info
}
)
fi
)
fi
)
)
)

0 comments on commit db0251e

Please sign in to comment.