Skip to content

Commit

Permalink
refactor: both ein and gix now share some code via the gitoxide
Browse files Browse the repository at this point in the history
… library. (#992)

This can slightly improve compile times as well, even though it wasn't measured.
  • Loading branch information
Byron committed Aug 27, 2023
1 parent 773b6e3 commit d3ac691
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 35 deletions.
5 changes: 1 addition & 4 deletions src/ein.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#![deny(rust_2018_idioms, unsafe_code)]

mod porcelain;
mod shared;

use anyhow::Result;

fn main() -> Result<()> {
fn main() -> anyhow::Result<()> {
porcelain::main()
}

Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@
cfg_attr(doc, doc = ::document_features::document_features!())
)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![deny(rust_2018_idioms, missing_docs)]
#![deny(rust_2018_idioms)]
#![allow(missing_docs)]
#![forbid(unsafe_code)]

/// everything in common beteween the `gix` and `ein` binaries.
pub mod shared;
4 changes: 2 additions & 2 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{

#[cfg(feature = "gitoxide-core-async-client")]
pub mod async_util {
use crate::shared::ProgressRange;
use gitoxide::shared::ProgressRange;

#[cfg(not(feature = "prodash-render-line"))]
compile_error!("BUG: Need at least a line renderer in async mode");
Expand All @@ -39,7 +39,7 @@ pub mod async_util {
Option<prodash::render::line::JoinHandle>,
gix_features::progress::DoOrDiscard<prodash::tree::Item>,
) {
use crate::shared::{self, STANDARD_RANGE};
use gitoxide::shared::{self, STANDARD_RANGE};
shared::init_env_logger();

if verbose {
Expand Down
2 changes: 1 addition & 1 deletion src/plumbing/options/free.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub mod index {
#[derive(Debug, clap::Parser)]
pub struct Platform {
/// The object format to assume when reading files that don't inherently know about it, or when writing files.
#[clap(long, default_value_t = gix::hash::Kind::default(), value_parser = crate::shared::AsHashKind)]
#[clap(long, default_value_t = gix::hash::Kind::default(), value_parser = gitoxide::shared::AsHashKind)]
pub object_hash: gix::hash::Kind,

/// The path to the index file.
Expand Down
26 changes: 13 additions & 13 deletions src/plumbing/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct Args {
///
/// For example, if `key` is `core.abbrev`, set configuration like `[core] abbrev = key`,
/// or `remote.origin.url = foo` to set `[remote "origin"] url = foo`.
#[clap(long, short = 'c', value_parser = crate::shared::AsBString)]
#[clap(long, short = 'c', value_parser = gitoxide::shared::AsBString)]
pub config: Vec<BString>,

#[clap(long, short = 't')]
Expand Down Expand Up @@ -63,12 +63,12 @@ pub struct Args {
long,
short = 'f',
default_value = "human",
value_parser = crate::shared::AsOutputFormat
value_parser = gitoxide::shared::AsOutputFormat
)]
pub format: core::OutputFormat,

/// The object format to assume when reading files that don't inherently know about it, or when writing files.
#[clap(long, default_value_t = gix::hash::Kind::default(), value_parser = crate::shared::AsHashKind)]
#[clap(long, default_value_t = gix::hash::Kind::default(), value_parser = gitoxide::shared::AsHashKind)]
pub object_hash: gix::hash::Kind,

#[clap(subcommand)]
Expand Down Expand Up @@ -237,7 +237,7 @@ pub mod config {
///
/// Typical filters are `branch` or `remote.origin` or `remote.or*` - git-style globs are supported
/// and comparisons are case-insensitive.
#[clap(value_parser = crate::shared::AsBString)]
#[clap(value_parser = gitoxide::shared::AsBString)]
pub filter: Vec<BString>,
}
}
Expand Down Expand Up @@ -276,7 +276,7 @@ pub mod fetch {
pub remote: Option<String>,

/// Override the built-in and configured ref-specs with one or more of the given ones.
#[clap(value_parser = crate::shared::AsBString)]
#[clap(value_parser = gitoxide::shared::AsBString)]
pub ref_spec: Vec<gix::bstr::BString>,
}

Expand All @@ -291,11 +291,11 @@ pub mod fetch {
pub deepen: Option<u32>,

/// Cutoff all history past the given date. Can be combined with shallow-exclude.
#[clap(long, help_heading = Some("SHALLOW"), value_parser = crate::shared::AsTime, value_name = "DATE", conflicts_with_all = ["depth", "deepen", "unshallow"])]
#[clap(long, help_heading = Some("SHALLOW"), value_parser = gitoxide::shared::AsTime, value_name = "DATE", conflicts_with_all = ["depth", "deepen", "unshallow"])]
pub shallow_since: Option<gix::date::Time>,

/// Cutoff all history past the tag-name or ref-name. Can be combined with shallow-since.
#[clap(long, help_heading = Some("SHALLOW"), value_parser = crate::shared::AsPartialRefName, value_name = "REF_NAME", conflicts_with_all = ["depth", "deepen", "unshallow"])]
#[clap(long, help_heading = Some("SHALLOW"), value_parser = gitoxide::shared::AsPartialRefName, value_name = "REF_NAME", conflicts_with_all = ["depth", "deepen", "unshallow"])]
pub shallow_exclude: Vec<gix::refs::PartialName>,

/// Remove the shallow boundary and fetch the entire history available on the remote.
Expand Down Expand Up @@ -362,11 +362,11 @@ pub mod clone {
pub depth: Option<NonZeroU32>,

/// Cutoff all history past the given date. Can be combined with shallow-exclude.
#[clap(long, help_heading = Some("SHALLOW"), value_parser = crate::shared::AsTime, value_name = "DATE")]
#[clap(long, help_heading = Some("SHALLOW"), value_parser = gitoxide::shared::AsTime, value_name = "DATE")]
pub shallow_since: Option<gix::date::Time>,

/// Cutoff all history past the tag-name or ref-name. Can be combined with shallow-since.
#[clap(long, help_heading = Some("SHALLOW"), value_parser = crate::shared::AsPartialRefName, value_name = "REF_NAME")]
#[clap(long, help_heading = Some("SHALLOW"), value_parser = gitoxide::shared::AsPartialRefName, value_name = "REF_NAME")]
pub shallow_exclude: Vec<gix::refs::PartialName>,
}

Expand Down Expand Up @@ -418,7 +418,7 @@ pub mod remote {
#[clap(long, short = 'u')]
show_unmapped_remote_refs: bool,
/// Override the built-in and configured ref-specs with one or more of the given ones.
#[clap(value_parser = crate::shared::AsBString)]
#[clap(value_parser = gitoxide::shared::AsBString)]
ref_spec: Vec<gix::bstr::BString>,
},
}
Expand Down Expand Up @@ -594,7 +594,7 @@ pub mod revision {
pub mod attributes {
use gix::bstr::BString;

use crate::shared::CheckPathSpec;
use gitoxide::shared::CheckPathSpec;

#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
Expand Down Expand Up @@ -625,7 +625,7 @@ pub mod exclude {

use gix::bstr::BString;

use crate::shared::CheckPathSpec;
use gitoxide::shared::CheckPathSpec;

#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
Expand Down Expand Up @@ -656,7 +656,7 @@ pub mod index {

use gix::bstr::BString;

use crate::shared::CheckPathSpec;
use gitoxide::shared::CheckPathSpec;

pub mod entries {
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]
Expand Down
16 changes: 7 additions & 9 deletions src/porcelain/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ use anyhow::Result;
use clap::Parser;
use gitoxide_core as core;

use crate::{
porcelain::options::{Args, Subcommands},
shared::pretty::prepare_and_run,
};
use crate::porcelain::options::{Args, Subcommands};
use gitoxide::shared::pretty::prepare_and_run;

pub fn main() -> Result<()> {
let args: Args = Args::parse_from(gix::env::args_os());
Expand Down Expand Up @@ -39,7 +37,7 @@ pub fn main() -> Result<()> {
verbose,
progress,
progress_keep_open,
crate::shared::STANDARD_RANGE,
gitoxide::shared::STANDARD_RANGE,
move |_progress, _out, _err| panic!("something went very wrong"),
),
Subcommands::Init { directory } => core::repository::init(directory).map(|_| ()),
Expand All @@ -59,7 +57,7 @@ pub fn main() -> Result<()> {
verbose,
progress,
progress_keep_open,
crate::shared::STANDARD_RANGE,
gitoxide::shared::STANDARD_RANGE,
move |mut progress, out, mut err| {
let engine = query::prepare(
&repo_dir,
Expand Down Expand Up @@ -99,7 +97,7 @@ pub fn main() -> Result<()> {
verbose,
progress,
progress_keep_open,
crate::shared::STANDARD_RANGE,
gitoxide::shared::STANDARD_RANGE,
move |progress, out, _err| {
hours::estimate(
&working_dir,
Expand All @@ -126,7 +124,7 @@ pub fn main() -> Result<()> {
verbose,
progress,
progress_keep_open,
crate::shared::STANDARD_RANGE,
gitoxide::shared::STANDARD_RANGE,
move |progress, out, _err| {
organize::discover(
root.unwrap_or_else(|| [std::path::Component::CurDir].iter().collect()),
Expand All @@ -150,7 +148,7 @@ pub fn main() -> Result<()> {
verbose,
progress,
progress_keep_open,
crate::shared::STANDARD_RANGE,
gitoxide::shared::STANDARD_RANGE,
move |progress, _out, _err| {
organize::run(
if execute {
Expand Down
4 changes: 2 additions & 2 deletions src/porcelain/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub mod tools {

#[cfg(feature = "gitoxide-core-tools-query")]
pub mod query {
use crate::shared::AsPathSpec;
use gitoxide::shared::AsPathSpec;

#[derive(Debug, clap::Subcommand)]
pub enum Command {
Expand All @@ -143,7 +143,7 @@ pub mod tools {
#[clap(default_value = ".")]
pub working_dir: PathBuf,
/// The name of the revision as spec, like 'HEAD' or 'main' at which to start iterating the commit graph.
#[clap(default_value("HEAD"), value_parser = crate::shared::AsBString)]
#[clap(default_value("HEAD"), value_parser = gitoxide::shared::AsBString)]
pub rev_spec: BString,
/// Ignore github bots which match the `[bot]` search string.
#[clap(short = 'b', long)]
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/panic-behaviour/expected-failure
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
thread 'main' panicked at 'something went very wrong', src/porcelain/main.rs:43:42
thread 'main' panicked at 'something went very wrong', src/porcelain/main.rs:41:42
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
2 changes: 1 addition & 1 deletion tests/snapshots/panic-behaviour/expected-failure-in-thread
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
thread 'main' panicked at 'something went very wrong', src/porcelain/main.rs:43:42
thread 'main' panicked at 'something went very wrong', src/porcelain/main.rs:41:42
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[?1049h[?25lthread '<unnamed>' panicked at 'something went very wrong', src/porcelain/main.rs:43:42
[?1049h[?25lthread '<unnamed>' panicked at 'something went very wrong', src/porcelain/main.rs:41:42
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[?25h[?1049l

0 comments on commit d3ac691

Please sign in to comment.