Skip to content

Commit d3ac691

Browse files
committed
refactor: both ein and gix now share some code via the gitoxide library. (#992)
This can slightly improve compile times as well, even though it wasn't measured.
1 parent 773b6e3 commit d3ac691

File tree

10 files changed

+34
-35
lines changed

10 files changed

+34
-35
lines changed

Diff for: src/ein.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
#![deny(rust_2018_idioms, unsafe_code)]
22

33
mod porcelain;
4-
mod shared;
54

6-
use anyhow::Result;
7-
8-
fn main() -> Result<()> {
5+
fn main() -> anyhow::Result<()> {
96
porcelain::main()
107
}
118

Diff for: src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,9 @@
2020
cfg_attr(doc, doc = ::document_features::document_features!())
2121
)]
2222
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
23-
#![deny(rust_2018_idioms, missing_docs)]
23+
#![deny(rust_2018_idioms)]
24+
#![allow(missing_docs)]
2425
#![forbid(unsafe_code)]
26+
27+
/// everything in common beteween the `gix` and `ein` binaries.
28+
pub mod shared;

Diff for: src/plumbing/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::{
2626

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

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

4545
if verbose {

Diff for: src/plumbing/options/free.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub mod index {
3939
#[derive(Debug, clap::Parser)]
4040
pub struct Platform {
4141
/// The object format to assume when reading files that don't inherently know about it, or when writing files.
42-
#[clap(long, default_value_t = gix::hash::Kind::default(), value_parser = crate::shared::AsHashKind)]
42+
#[clap(long, default_value_t = gix::hash::Kind::default(), value_parser = gitoxide::shared::AsHashKind)]
4343
pub object_hash: gix::hash::Kind,
4444

4545
/// The path to the index file.

Diff for: src/plumbing/options/mod.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub struct Args {
1616
///
1717
/// For example, if `key` is `core.abbrev`, set configuration like `[core] abbrev = key`,
1818
/// or `remote.origin.url = foo` to set `[remote "origin"] url = foo`.
19-
#[clap(long, short = 'c', value_parser = crate::shared::AsBString)]
19+
#[clap(long, short = 'c', value_parser = gitoxide::shared::AsBString)]
2020
pub config: Vec<BString>,
2121

2222
#[clap(long, short = 't')]
@@ -63,12 +63,12 @@ pub struct Args {
6363
long,
6464
short = 'f',
6565
default_value = "human",
66-
value_parser = crate::shared::AsOutputFormat
66+
value_parser = gitoxide::shared::AsOutputFormat
6767
)]
6868
pub format: core::OutputFormat,
6969

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

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

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

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

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

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

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

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

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

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

597-
use crate::shared::CheckPathSpec;
597+
use gitoxide::shared::CheckPathSpec;
598598

599599
#[derive(Debug, clap::Subcommand)]
600600
pub enum Subcommands {
@@ -625,7 +625,7 @@ pub mod exclude {
625625

626626
use gix::bstr::BString;
627627

628-
use crate::shared::CheckPathSpec;
628+
use gitoxide::shared::CheckPathSpec;
629629

630630
#[derive(Debug, clap::Subcommand)]
631631
pub enum Subcommands {
@@ -656,7 +656,7 @@ pub mod index {
656656

657657
use gix::bstr::BString;
658658

659-
use crate::shared::CheckPathSpec;
659+
use gitoxide::shared::CheckPathSpec;
660660

661661
pub mod entries {
662662
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]

Diff for: src/porcelain/main.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ use anyhow::Result;
77
use clap::Parser;
88
use gitoxide_core as core;
99

10-
use crate::{
11-
porcelain::options::{Args, Subcommands},
12-
shared::pretty::prepare_and_run,
13-
};
10+
use crate::porcelain::options::{Args, Subcommands};
11+
use gitoxide::shared::pretty::prepare_and_run;
1412

1513
pub fn main() -> Result<()> {
1614
let args: Args = Args::parse_from(gix::env::args_os());
@@ -39,7 +37,7 @@ pub fn main() -> Result<()> {
3937
verbose,
4038
progress,
4139
progress_keep_open,
42-
crate::shared::STANDARD_RANGE,
40+
gitoxide::shared::STANDARD_RANGE,
4341
move |_progress, _out, _err| panic!("something went very wrong"),
4442
),
4543
Subcommands::Init { directory } => core::repository::init(directory).map(|_| ()),
@@ -59,7 +57,7 @@ pub fn main() -> Result<()> {
5957
verbose,
6058
progress,
6159
progress_keep_open,
62-
crate::shared::STANDARD_RANGE,
60+
gitoxide::shared::STANDARD_RANGE,
6361
move |mut progress, out, mut err| {
6462
let engine = query::prepare(
6563
&repo_dir,
@@ -99,7 +97,7 @@ pub fn main() -> Result<()> {
9997
verbose,
10098
progress,
10199
progress_keep_open,
102-
crate::shared::STANDARD_RANGE,
100+
gitoxide::shared::STANDARD_RANGE,
103101
move |progress, out, _err| {
104102
hours::estimate(
105103
&working_dir,
@@ -126,7 +124,7 @@ pub fn main() -> Result<()> {
126124
verbose,
127125
progress,
128126
progress_keep_open,
129-
crate::shared::STANDARD_RANGE,
127+
gitoxide::shared::STANDARD_RANGE,
130128
move |progress, out, _err| {
131129
organize::discover(
132130
root.unwrap_or_else(|| [std::path::Component::CurDir].iter().collect()),
@@ -150,7 +148,7 @@ pub fn main() -> Result<()> {
150148
verbose,
151149
progress,
152150
progress_keep_open,
153-
crate::shared::STANDARD_RANGE,
151+
gitoxide::shared::STANDARD_RANGE,
154152
move |progress, _out, _err| {
155153
organize::run(
156154
if execute {

Diff for: src/porcelain/options.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub mod tools {
116116

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

121121
#[derive(Debug, clap::Subcommand)]
122122
pub enum Command {
@@ -143,7 +143,7 @@ pub mod tools {
143143
#[clap(default_value = ".")]
144144
pub working_dir: PathBuf,
145145
/// The name of the revision as spec, like 'HEAD' or 'main' at which to start iterating the commit graph.
146-
#[clap(default_value("HEAD"), value_parser = crate::shared::AsBString)]
146+
#[clap(default_value("HEAD"), value_parser = gitoxide::shared::AsBString)]
147147
pub rev_spec: BString,
148148
/// Ignore github bots which match the `[bot]` search string.
149149
#[clap(short = 'b', long)]

Diff for: tests/snapshots/panic-behaviour/expected-failure

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
thread 'main' panicked at 'something went very wrong', src/porcelain/main.rs:43:42
1+
thread 'main' panicked at 'something went very wrong', src/porcelain/main.rs:41:42
22
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
thread 'main' panicked at 'something went very wrong', src/porcelain/main.rs:43:42
1+
thread 'main' panicked at 'something went very wrong', src/porcelain/main.rs:41:42
22
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
33

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

0 commit comments

Comments
 (0)