Skip to content

Commit

Permalink
basic tests and CLI args for explode pack
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 25, 2020
1 parent ec8c48a commit f932256
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 11 deletions.
1 change: 1 addition & 0 deletions gitoxide-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ impl FromStr for OutputFormat {
}
}

pub mod pack;
pub mod repository;
pub mod verify;
12 changes: 12 additions & 0 deletions gitoxide-core/src/pack.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pub mod explode {
use anyhow::Result;
use git_features::progress::Progress;
use std::path::Path;

pub fn pack_or_pack_index<P>(_path: impl AsRef<Path>, _progress: Option<P>, _delete_pack: bool) -> Result<()>
where
P: Progress,
{
Ok(())
}
}
34 changes: 31 additions & 3 deletions src/plumbing/lean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,29 @@ mod options {
#[argh(subcommand)]
pub enum SubCommands {
PackVerify(PackVerify),
PackExplode(PackExplode),
}
/// Explode a pack into loose objects.
///
/// This can be useful in case of partially invalidated packs to extract as much information as possible,
/// or because working with loose objects is easier with custom tooling.
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "pack-explode")]
pub struct PackExplode {
/// delete the pack and index file after the operation is successful
#[argh(switch)]
pub delete_pack: bool,

/// Initialize the repository in the current directory.
/// display verbose messages and progress information
#[argh(switch, short = 'v')]
pub verbose: bool,

/// the '.pack' or '.idx' file to explode into loose objects
#[argh(positional)]
pub path: PathBuf,
}

/// Verify a pack
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "pack-verify")]
pub struct PackVerify {
Expand Down Expand Up @@ -56,10 +76,10 @@ mod options {
/// output statistical information about the pack
#[argh(switch, short = 's')]
pub statistics: bool,
/// verbose progress messages are printed line by line
/// display verbose messages and progress information
#[argh(switch, short = 'v')]
pub verbose: bool,
/// the '.pack' or '.idx' data whose checksum to validate.
/// the '.pack' or '.idx' file whose checksum to validate.
#[argh(positional)]
pub path: PathBuf,
}
Expand Down Expand Up @@ -100,6 +120,14 @@ pub fn main() -> Result<()> {
let cli: Args = crate::shared::from_env();
let thread_limit = cli.threads;
match cli.subcommand {
SubCommands::PackExplode(PackExplode {
path,
verbose,
delete_pack,
}) => {
let (_handle, progress) = prepare(verbose, "pack-explode");
core::pack::explode::pack_or_pack_index(path, progress, delete_pack)
}
SubCommands::PackVerify(PackVerify {
path,
verbose,
Expand Down
50 changes: 44 additions & 6 deletions src/plumbing/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,31 @@ mod options {

#[derive(Debug, StructOpt)]
pub enum Subcommands {
/// Verify the integrity of a pack or index file
#[structopt(setting = AppSettings::ColoredHelp)]
PackExplode {
/// Delete the pack and index file after the operation is successful
#[structopt(long)]
delete_pack: bool,

/// Display verbose messages and progress information
#[structopt(long, short = "v")]
verbose: bool,

/// Bring up a terminal user interface displaying progress visually
#[structopt(long, conflicts_with("verbose"))]
progress: bool,

/// The progress TUI will stay up even though the work is already completed.
///
/// Use this to be able to read progress messages or additional information visible in the TUI log pane.
#[structopt(long, conflicts_with("verbose"), requires("progress"))]
progress_keep_open: bool,

/// The '.pack' or '.idx' file to explode into loose objects
#[structopt(parse(from_os_str))]
path: PathBuf,
},
/// Verify the integrity of a pack or index file
#[structopt(setting = AppSettings::ColoredHelp)]
PackVerify {
Expand All @@ -50,37 +75,37 @@ mod options {
)]
algorithm: core::verify::Algorithm,

/// verbose progress messages are printed line by line
/// Display verbose messages and progress information
#[structopt(long, short = "v")]
verbose: bool,

/// bring up a terminal user interface displaying progress visually
/// Bring up a terminal user interface displaying progress visually
#[structopt(long, conflicts_with("verbose"))]
progress: bool,

#[structopt(long, conflicts_with("re-encode"))]
/// decode and parse tags, commits and trees to validate their correctness beyond hashing correctly.
/// Decode and parse tags, commits and trees to validate their correctness beyond hashing correctly.
///
/// Malformed objects should not usually occur, but could be injected on purpose or accident.
/// This will reduce overall performance.
decode: bool,

#[structopt(long)]
/// decode and parse tags, commits and trees to validate their correctness, and re-encode them.
/// Decode and parse tags, commits and trees to validate their correctness, and re-encode them.
///
/// This flag is primarily to test the implementation of encoding, and requires to decode the object first.
/// Encoding an object after decoding it should yield exactly the same bytes.
/// This will reduce overall performance even more, as re-encoding requires to transform zero-copy objects into
/// owned objects, causing plenty of allocation to occour.
re_encode: bool,

/// the progress TUI will stay up even though the work is already completed.
/// The progress TUI will stay up even though the work is already completed.
///
/// Use this to be able to read progress messages or additional information visible in the TUI log pane.
#[structopt(long, conflicts_with("verbose"), requires("progress"))]
progress_keep_open: bool,

/// The '.pack' or '.idx' data whose checksum to validate.
/// The '.pack' or '.idx' file whose checksum to validate.
#[structopt(parse(from_os_str))]
path: PathBuf,
},
Expand Down Expand Up @@ -180,6 +205,19 @@ pub fn main() -> Result<()> {
let args = Args::from_args();
let thread_limit = args.threads;
match args.cmd {
Subcommands::PackExplode {
verbose,
progress,
progress_keep_open,
delete_pack,
path,
} => prepare_and_run(
"pack-explode",
verbose,
progress,
progress_keep_open,
move |progress, _out, _err| core::pack::explode::pack_or_pack_index(path, progress, delete_pack),
),
Subcommands::PackVerify {
path,
algorithm,
Expand Down
5 changes: 3 additions & 2 deletions tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
* [x] Deflate stream
* [x] disk - with decent errors
* [x] size as u64 (properly)
* [ ] generalize pack reading algorithm
* [ ] write loose object to memory
* **cli**
* [ ] generalize pack reading algorithm
* [ ] write objects from pack (multi-threaded comes for free)
* [ ] to sink
* [ ] to disk
* [ ] progress
* [ ] statistics

Expand Down
Empty file.
Empty file.
36 changes: 36 additions & 0 deletions tests/stateless-journey.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,42 @@ title "CLI ${kind}"
)
)

(when "running 'plumbing pack-explode"
PACK_FILE="$fixtures/packs/pack-11fdfa9e156ab73caae3b6da867192221f2089c2"
(with "no directory specified"
it "explodes the pack successfully and with desired output" && {
WITH_SNAPSHOT="$snapshot/plumbing-pack-explode-to-sink-success" \
expect_run $SUCCESSFULLY "$exe_plumbing" pack-explode "${PACK_FILE}.idx"
}

(when "using the --delete-pack flag"
(sandbox
cp ${PACK_FILE}.idx ${PACK_FILE}.pack .
PACK_FILE="${PACK_FILE##*/}"
(with "a valid pack"
it "explodes the pack successfully and deletes the original pack and index" && {
WITH_SNAPSHOT="$snapshot/plumbing-pack-explode-to-sink-delete-pack-success" \
expect_run $SUCCESSFULLY "$exe_plumbing" pack-explode --delete-pack "${PACK_FILE}.pack"
}
it "removes the original files" && {
expect_run $WITH_FAILURE ls ${PACK_FILE}.pack
expect_run $WITH_FAILURE ls ${PACK_FILE}.idx
}
)
(with "TODO(how to write into the middle of a file in bash): an invalid pack"

)
)
)
)
(with "a non-existing directory specified"

)
(with "an existing directory specified"

)
)

(when "running 'plumbing pack-verify"
(with "a valid pack file"
PACK_FILE="$fixtures/packs/pack-11fdfa9e156ab73caae3b6da867192221f2089c2.pack"
Expand Down

0 comments on commit f932256

Please sign in to comment.