Skip to content

Commit bb30e52

Browse files
authored
Merge pull request #1384 from NobodyXu/feat/easier-to-compile-gix-as-dynlib
Refactor: Make it easier to compile gitoxide as dynlib
2 parents 8da55a3 + bf5a111 commit bb30e52

File tree

9 files changed

+36
-43
lines changed

9 files changed

+36
-43
lines changed

src/ein.rs

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

3-
mod porcelain;
4-
53
fn main() -> anyhow::Result<()> {
6-
porcelain::main()
4+
gitoxide::porcelain::main()
75
}
86

97
#[cfg(not(feature = "pretty-cli"))]

src/gix.rs

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

3-
mod plumbing;
4-
5-
use anyhow::Result;
6-
73
#[cfg(feature = "pretty-cli")]
8-
fn main() -> Result<()> {
9-
plumbing::main()
4+
fn main() -> anyhow::Result<()> {
5+
gitoxide::plumbing::main()
106
}
117

128
#[cfg(not(feature = "pretty-cli"))]

src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
#![cfg_attr(all(doc, feature = "document-features"), feature(doc_cfg, doc_auto_cfg))]
2323
#![deny(rust_2018_idioms)]
2424
#![allow(missing_docs)]
25-
#![forbid(unsafe_code)]
25+
#![deny(unsafe_code)]
2626

27+
pub mod plumbing;
28+
pub mod porcelain;
2729
/// everything in common between the `gix` and `ein` binaries.
2830
pub mod shared;

src/plumbing/main.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use std::{
77
},
88
};
99

10+
use crate::shared::pretty::prepare_and_run;
1011
use anyhow::{anyhow, Context, Result};
1112
use clap::{CommandFactory, Parser};
12-
use gitoxide::shared::pretty::prepare_and_run;
1313
use gitoxide_core as core;
1414
use gitoxide_core::{pack::verify, repository::PathsOrPatterns};
1515
use gix::bstr::{io::BufReadExt, BString};
@@ -24,7 +24,7 @@ use crate::plumbing::{
2424

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

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

4444
if verbose {
@@ -732,7 +732,7 @@ pub fn main() -> Result<()> {
732732
&url,
733733
directory,
734734
refs_directory,
735-
refs.into_iter().map(|s| s.into()).collect(),
735+
refs.into_iter().map(Into::into).collect(),
736736
progress,
737737
core::pack::receive::Context {
738738
thread_limit,

src/plumbing/options/free.rs

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

4848
/// The path to the index file.

src/plumbing/options/mod.rs

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

2323
#[clap(long, short = 't')]
@@ -64,12 +64,12 @@ pub struct Args {
6464
long,
6565
short = 'f',
6666
default_value = "human",
67-
value_parser = gitoxide::shared::AsOutputFormat
67+
value_parser = crate::shared::AsOutputFormat
6868
)]
6969
pub format: core::OutputFormat,
7070

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

7575
#[clap(subcommand)]
@@ -201,7 +201,7 @@ pub mod archive {
201201
}
202202

203203
pub mod status {
204-
use gitoxide::shared::{CheckPathSpec, ParseRenameFraction};
204+
use crate::shared::{CheckPathSpec, ParseRenameFraction};
205205
use gix::bstr::BString;
206206

207207
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]
@@ -320,7 +320,7 @@ pub mod config {
320320
///
321321
/// Typical filters are `branch` or `remote.origin` or `remote.or*` - git-style globs are supported
322322
/// and comparisons are case-insensitive.
323-
#[clap(value_parser = gitoxide::shared::AsBString)]
323+
#[clap(value_parser = crate::shared::AsBString)]
324324
pub filter: Vec<BString>,
325325
}
326326
}
@@ -359,7 +359,7 @@ pub mod fetch {
359359
pub remote: Option<String>,
360360

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

@@ -374,11 +374,11 @@ pub mod fetch {
374374
pub deepen: Option<u32>,
375375

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

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

384384
/// Remove the shallow boundary and fetch the entire history available on the remote.
@@ -445,11 +445,11 @@ pub mod clone {
445445
pub depth: Option<NonZeroU32>,
446446

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

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

@@ -501,7 +501,7 @@ pub mod remote {
501501
#[clap(long, short = 'u')]
502502
show_unmapped_remote_refs: bool,
503503
/// Override the built-in and configured ref-specs with one or more of the given ones.
504-
#[clap(value_parser = gitoxide::shared::AsBString)]
504+
#[clap(value_parser = crate::shared::AsBString)]
505505
ref_spec: Vec<gix::bstr::BString>,
506506
},
507507
}
@@ -517,7 +517,7 @@ pub mod mailmap {
517517

518518
#[cfg(feature = "gitoxide-core-tools-clean")]
519519
pub mod clean {
520-
use gitoxide::shared::CheckPathSpec;
520+
use crate::shared::CheckPathSpec;
521521
use gix::bstr::BString;
522522

523523
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]
@@ -787,7 +787,7 @@ pub mod revision {
787787
}
788788

789789
pub mod attributes {
790-
use gitoxide::shared::CheckPathSpec;
790+
use crate::shared::CheckPathSpec;
791791
use gix::bstr::BString;
792792

793793
#[derive(Debug, clap::Subcommand)]
@@ -817,7 +817,7 @@ pub mod attributes {
817817
pub mod exclude {
818818
use std::ffi::OsString;
819819

820-
use gitoxide::shared::CheckPathSpec;
820+
use crate::shared::CheckPathSpec;
821821
use gix::bstr::BString;
822822

823823
#[derive(Debug, clap::Subcommand)]
@@ -847,7 +847,7 @@ pub mod exclude {
847847
pub mod index {
848848
use std::path::PathBuf;
849849

850-
use gitoxide::shared::CheckPathSpec;
850+
use crate::shared::CheckPathSpec;
851851
use gix::bstr::BString;
852852

853853
pub mod entries {

src/porcelain/main.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use std::sync::{
33
Arc,
44
};
55

6+
use crate::shared::pretty::prepare_and_run;
67
use anyhow::{anyhow, Result};
78
use clap::{CommandFactory, Parser};
8-
use gitoxide::shared::pretty::prepare_and_run;
99
use gitoxide_core as core;
1010

1111
use crate::porcelain::options::{Args, Subcommands};
@@ -41,7 +41,7 @@ pub fn main() -> Result<()> {
4141
verbose,
4242
progress,
4343
progress_keep_open,
44-
gitoxide::shared::STANDARD_RANGE,
44+
crate::shared::STANDARD_RANGE,
4545
move |_progress, _out, _err| panic!("something went very wrong"),
4646
),
4747
Subcommands::Init { directory } => core::repository::init(directory).map(|_| ()),
@@ -61,7 +61,7 @@ pub fn main() -> Result<()> {
6161
verbose,
6262
progress,
6363
progress_keep_open,
64-
gitoxide::shared::STANDARD_RANGE,
64+
crate::shared::STANDARD_RANGE,
6565
move |mut progress, out, mut err| {
6666
let engine = query::prepare(
6767
&repo_dir,
@@ -101,7 +101,7 @@ pub fn main() -> Result<()> {
101101
verbose,
102102
progress,
103103
progress_keep_open,
104-
gitoxide::shared::STANDARD_RANGE,
104+
crate::shared::STANDARD_RANGE,
105105
move |progress, out, _err| {
106106
hours::estimate(
107107
&working_dir,
@@ -128,7 +128,7 @@ pub fn main() -> Result<()> {
128128
verbose,
129129
progress,
130130
progress_keep_open,
131-
gitoxide::shared::STANDARD_RANGE,
131+
crate::shared::STANDARD_RANGE,
132132
move |progress, out, _err| {
133133
organize::discover(
134134
root.unwrap_or_else(|| [std::path::Component::CurDir].iter().collect()),
@@ -152,7 +152,7 @@ pub fn main() -> Result<()> {
152152
verbose,
153153
progress,
154154
progress_keep_open,
155-
gitoxide::shared::STANDARD_RANGE,
155+
crate::shared::STANDARD_RANGE,
156156
move |progress, _out, _err| {
157157
organize::run(
158158
if execute {

src/porcelain/options.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ pub mod tools {
126126

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

131131
#[derive(Debug, clap::Subcommand)]
132132
pub enum Command {
@@ -153,7 +153,7 @@ pub mod tools {
153153
#[clap(default_value = ".")]
154154
pub working_dir: PathBuf,
155155
/// The name of the revision as spec, like 'HEAD' or 'main' at which to start iterating the commit graph.
156-
#[clap(default_value("HEAD"), value_parser = gitoxide::shared::AsBString)]
156+
#[clap(default_value("HEAD"), value_parser = crate::shared::AsBString)]
157157
pub rev_spec: BString,
158158
/// Ignore github bots which match the `[bot]` search string.
159159
#[clap(short = 'b', long)]

src/uni.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,15 @@
88

99
use anyhow::{bail, Result};
1010

11-
mod plumbing;
12-
mod porcelain;
13-
1411
#[cfg(feature = "pretty-cli")]
1512
fn main() -> Result<()> {
1613
match std::env::current_exe()?
1714
.file_stem()
1815
.and_then(|stem| stem.to_str())
1916
.unwrap_or("gix")
2017
{
21-
"gix" => plumbing::main(),
22-
"ein" => porcelain::main(),
18+
"gix" => crate::plumbing::main(),
19+
"ein" => crate::porcelain::main(),
2320
unknown => bail!("Executable named '{unknown}' cannot be launched. Exe must be named either `gix` or `ein`."),
2421
}
2522
}

0 commit comments

Comments
 (0)