Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 18, 2020
1 parent 0506fd9 commit 40a6412
Show file tree
Hide file tree
Showing 3 changed files with 253 additions and 252 deletions.
252 changes: 0 additions & 252 deletions src/plumbing/lean.rs

This file was deleted.

113 changes: 113 additions & 0 deletions src/plumbing/lean/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
mod options;

use crate::shared::ProgressRange;
use anyhow::Result;
use git_features::progress;
use gitoxide_core::{self as core, OutputFormat};
use std::io::{self, stderr, stdout};

#[cfg(not(any(feature = "prodash-render-line-crossterm", feature = "prodash-render-line-termion")))]
fn prepare(verbose: bool, name: &str, _: impl Into<Option<ProgressRange>>) -> ((), Option<prodash::progress::Log>) {
super::init_env_logger(verbose);
((), Some(prodash::progress::Log::new(name, Some(1))))
}

#[cfg(any(feature = "prodash-render-line-crossterm", feature = "prodash-render-line-termion"))]
fn prepare(
verbose: bool,
name: &str,
range: impl Into<Option<ProgressRange>>,
) -> (Option<prodash::render::line::JoinHandle>, Option<prodash::tree::Item>) {
use crate::shared::{self, STANDARD_RANGE};
super::init_env_logger(false);

if verbose {
let progress = prodash::Tree::new();
let sub_progress = progress.add_child(name);
let handle = shared::setup_line_renderer_range(progress, range.into().unwrap_or(STANDARD_RANGE), true);
(Some(handle), Some(sub_progress))
} else {
(None, None)
}
}

pub fn main() -> Result<()> {
pub use options::*;
let cli: Args = crate::shared::from_env();
git_features::interrupt::init_handler(std::io::stderr());
let thread_limit = cli.threads;
let verbose = cli.verbose;
match cli.subcommand {
SubCommands::IndexFromPack(IndexFromPack {
iteration_mode,
pack_path,
directory,
}) => {
let (_handle, progress) = prepare(verbose, "pack-explode", core::pack::index::PROGRESS_RANGE);
core::pack::index::from_pack(
pack_path,
directory,
progress::DoOrDiscard::from(progress),
core::pack::index::Context {
thread_limit,
iteration_mode: iteration_mode.unwrap_or_default(),
format: OutputFormat::Human,
out: io::stdout(),
},
)
}
SubCommands::PackExplode(PackExplode {
pack_path,
sink_compress,
object_path,
verify,
check,
delete_pack,
}) => {
let (_handle, progress) = prepare(verbose, "pack-explode", None);
core::pack::explode::pack_or_pack_index(
pack_path,
object_path,
check.unwrap_or_default(),
progress,
core::pack::explode::Context {
thread_limit,
delete_pack,
sink_compress,
verify,
},
)
}
SubCommands::PackVerify(PackVerify {
path,
statistics,
algorithm,
decode,
re_encode,
}) => {
use self::core::pack::verify;
let (_handle, progress) = prepare(verbose, "pack-verify", None);
core::pack::verify::pack_or_pack_index(
path,
progress,
core::pack::verify::Context {
output_statistics: if statistics {
Some(core::OutputFormat::Human)
} else {
None
},
algorithm: algorithm.unwrap_or(verify::Algorithm::LessTime),
thread_limit,
mode: match (decode, re_encode) {
(true, false) => verify::Mode::Sha1CRC32Decode,
(true, true) | (false, true) => verify::Mode::Sha1CRC32DecodeEncode,
(false, false) => verify::Mode::Sha1CRC32,
},
out: stdout(),
err: stderr(),
},
)
.map(|_| ())
}
}
}
Loading

0 comments on commit 40a6412

Please sign in to comment.