From db0251e277ee9035bd3b44bf5ec9152fb64ac8c8 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 1 Jan 2022 10:10:14 +0800 Subject: [PATCH] 'commitgraph' with its own sub-commands (#289) --- README.md | 4 +- src/plumbing/main.rs | 42 +++++++++--------- src/plumbing/options.rs | 32 +++++++++----- tests/journey/gix.sh | 44 +++++++++++-------- .../verify}/statistics-json-success | 0 .../verify}/statistics-success | 0 6 files changed, 71 insertions(+), 51 deletions(-) rename tests/snapshots/plumbing/{commit-graph-verify => commitgraph/verify}/statistics-json-success (100%) rename tests/snapshots/plumbing/{commit-graph-verify => commitgraph/verify}/statistics-success (100%) diff --git a/README.md b/README.md index 5bbd52cbe2a..531c5865d81 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/plumbing/main.rs b/src/plumbing/main.rs index 9967edad6cf..71c82408896 100644 --- a/src/plumbing/main.rs +++ b/src/plumbing/main.rs @@ -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, }; @@ -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(()) } diff --git a/src/plumbing/options.rs b/src/plumbing/options.rs index 7c2fb3d02f5..6a7922b8838 100644 --- a/src/plumbing/options.rs +++ b/src/plumbing/options.rs @@ -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, + }, + } } diff --git a/tests/journey/gix.sh b/tests/journey/gix.sh index c34aff7b713..d41724ac066 100644 --- a/tests/journey/gix.sh +++ b/tests/journey/gix.sh @@ -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 ) ) ) diff --git a/tests/snapshots/plumbing/commit-graph-verify/statistics-json-success b/tests/snapshots/plumbing/commitgraph/verify/statistics-json-success similarity index 100% rename from tests/snapshots/plumbing/commit-graph-verify/statistics-json-success rename to tests/snapshots/plumbing/commitgraph/verify/statistics-json-success diff --git a/tests/snapshots/plumbing/commit-graph-verify/statistics-success b/tests/snapshots/plumbing/commitgraph/verify/statistics-success similarity index 100% rename from tests/snapshots/plumbing/commit-graph-verify/statistics-success rename to tests/snapshots/plumbing/commitgraph/verify/statistics-success