Skip to content

Commit d240ab3

Browse files
committed
Very rough version of repository verification (#287)
1 parent 53d835a commit d240ab3

File tree

6 files changed

+80
-2
lines changed

6 files changed

+80
-2
lines changed

git-odb/src/store_impls/dynamic/verify.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ pub mod integrity {
1010
use crate::pack;
1111
use std::path::PathBuf;
1212

13+
/// Options for use in [`Store::verify_integrity()`][crate::Store::verify_integrity()].
14+
pub type Options<F> = pack::index::verify::integrity::Options<F>;
15+
1316
/// Returned by [`Store::verify_integrity()`][crate::Store::verify_integrity()].
1417
#[derive(Debug, thiserror::Error)]
1518
#[allow(missing_docs)]
@@ -81,7 +84,7 @@ impl super::Store {
8184
&self,
8285
mut progress: P,
8386
should_interrupt: &AtomicBool,
84-
options: pack::index::verify::integrity::Options<F>,
87+
options: integrity::Options<F>,
8588
) -> Result<integrity::Outcome<P>, integrity::Error>
8689
where
8790
P: Progress,

gitoxide-core/src/repository.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,29 @@ pub fn init(directory: Option<PathBuf>) -> Result<git_repository::Path> {
66
git_repository::path::create::into(directory.unwrap_or_default(), git_repository::Kind::WorkTree)
77
.with_context(|| "Repository initialization failed")
88
}
9+
10+
pub mod verify {
11+
use crate::OutputFormat;
12+
use git_repository::Progress;
13+
use std::path::PathBuf;
14+
use std::sync::atomic::AtomicBool;
15+
16+
pub const PROGRESS_RANGE: std::ops::RangeInclusive<u8> = 1..=4;
17+
18+
pub fn integrity(
19+
repo: PathBuf,
20+
_format: OutputFormat,
21+
_out: impl std::io::Write,
22+
progress: impl Progress,
23+
should_interrupt: &AtomicBool,
24+
) -> anyhow::Result<()> {
25+
let repo = git_repository::open(repo)?;
26+
// TODO: a way to get the pack cache from a handle
27+
repo.objects.verify_integrity(
28+
progress,
29+
should_interrupt,
30+
git_repository::odb::pack::index::verify::integrity::Options::default(),
31+
)?;
32+
Ok(())
33+
}
34+
}

src/plumbing/main.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use gitoxide_core::pack::verify;
1414

1515
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
1616
use crate::plumbing::options::remote;
17+
use crate::plumbing::options::repo;
1718
use crate::{
1819
plumbing::options::{commitgraph, pack, Args, Subcommands},
1920
shared::pretty::prepare_and_run,
@@ -73,6 +74,18 @@ pub fn main() -> Result<()> {
7374
})?;
7475

7576
match cmd {
77+
Subcommands::Repository(subcommands) => match subcommands {
78+
repo::Subcommands::Verify { repository } => prepare_and_run(
79+
"repository-verify",
80+
verbose,
81+
progress,
82+
progress_keep_open,
83+
core::repository::verify::PROGRESS_RANGE,
84+
move |progress, out, _err| {
85+
core::repository::verify::integrity(repository, format, out, progress, &should_interrupt)
86+
},
87+
),
88+
},
7689
Subcommands::Pack(subcommands) => match subcommands {
7790
pack::Subcommands::Create {
7891
repository,

src/plumbing/options.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use gitoxide_core as core;
33

44
#[derive(Debug, clap::Parser)]
55
#[clap(name = "gix-plumbing", about = "The git underworld", version = clap::crate_version!())]
6-
#[clap(setting = AppSettings::SubcommandRequired)]
6+
#[clap(setting = AppSettings::SubcommandRequiredElseHelp)]
77
pub struct Args {
88
#[clap(long, short = 't')]
99
/// The amount of threads to use for some operations.
@@ -56,6 +56,9 @@ pub enum Subcommands {
5656
/// Subcommands for interacting with commit-graphs
5757
#[clap(subcommand)]
5858
CommitGraph(commitgraph::Subcommands),
59+
/// Subcommands for interacting with entire git repositories
60+
#[clap(subcommand)]
61+
Repository(repo::Subcommands),
5962
}
6063

6164
///
@@ -313,6 +316,23 @@ pub mod pack {
313316
}
314317
}
315318

319+
///
320+
pub mod repo {
321+
use clap::AppSettings;
322+
use std::path::PathBuf;
323+
324+
#[derive(Debug, clap::Parser)]
325+
#[clap(alias = "repo")]
326+
pub enum Subcommands {
327+
/// Verify the integrity of the entire repository
328+
#[clap(setting = AppSettings::DisableVersionFlag)]
329+
Verify {
330+
#[clap(short = 'r', long, default_value = ".")]
331+
repository: PathBuf,
332+
},
333+
}
334+
}
335+
316336
///
317337
pub mod commitgraph {
318338
use clap::AppSettings;

tests/journey/gix.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ title "git-tempfile crate"
3939
)
4040
)
4141

42+
title "gix repository"
43+
(when "running 'repository'"
44+
snapshot="$snapshot/repository"
45+
(small-repo-in-sandbox
46+
(with "the 'verify' sub-command"
47+
snapshot="$snapshot/verify"
48+
(with 'human output format'
49+
it "generates correct output" && {
50+
WITH_SNAPSHOT="$snapshot/success-format-human" \
51+
expect_run $SUCCESSFULLY "$exe_plumbing" --format human repo verify
52+
}
53+
)
54+
)
55+
)
56+
)
57+
4258
title "gix pack"
4359
(when "running 'pack'"
4460
snapshot="$snapshot/pack"

tests/snapshots/plumbing/repository/verify/success-format-human

Whitespace-only changes.

0 commit comments

Comments
 (0)