Remove git2 as a dependency (#267)

This dependency cannot be sent between threads.
Instead use git-config which is a pure rust implementation to read git config files.

Uses the builtin values::Path struct to extract ignore paths.
It takes care of all the corner cases with how git interprets paths.
This commit is contained in:
David Calavera 2022-04-03 16:43:30 -07:00 committed by GitHub
parent e8d3bb964c
commit 20597802ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 134 additions and 148 deletions

214
Cargo.lock generated
View File

@ -292,9 +292,6 @@ name = "cc"
version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
dependencies = [
"jobserver",
]
[[package]]
name = "cfg-if"
@ -490,6 +487,15 @@ dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs"
version = "4.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059"
dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs-sys"
version = "0.3.7"
@ -571,6 +577,28 @@ version = "2.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77f3309417938f28bf8228fcff79a4a37103981e3e186d2ccd19c74b38f4eb71"
[[package]]
name = "failure"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86"
dependencies = [
"backtrace",
"failure_derive",
]
[[package]]
name = "failure_derive"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4"
dependencies = [
"proc-macro2",
"quote",
"syn",
"synstructure",
]
[[package]]
name = "fastrand"
version = "1.7.0"
@ -616,16 +644,6 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "form_urlencoded"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191"
dependencies = [
"matches",
"percent-encoding",
]
[[package]]
name = "fsevent-sys"
version = "4.1.0"
@ -768,16 +786,38 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4"
[[package]]
name = "git2"
version = "0.13.25"
name = "git-config"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f29229cc1b24c0e6062f6e742aa3e256492a5323365e5ed3413599f8a5eff7d6"
checksum = "b21a3fec9a7437ebee54c52f1fcb6795bf8e97a5f058d4bde015fc37ff8193a3"
dependencies = [
"bitflags",
"dirs 4.0.0",
"git-features",
"memchr",
"nom 7.1.1",
"pwd",
"quick-error",
"unicode-bom",
]
[[package]]
name = "git-features"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ebc06d6b83be53d9c7a00937a6baed4566aad7dba12af11ac830ea72c080af0"
dependencies = [
"git-hash",
"libc",
"libgit2-sys",
"log",
"url",
]
[[package]]
name = "git-hash"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "106e7c3a08b97285bf0bca7f109e67d286e7fbf34b222faf742443b021de2bb4"
dependencies = [
"hex",
"quick-error",
]
[[package]]
@ -931,17 +971,6 @@ dependencies = [
"tokio-io-timeout",
]
[[package]]
name = "idna"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8"
dependencies = [
"matches",
"unicode-bidi",
"unicode-normalization",
]
[[package]]
name = "ignore"
version = "0.4.18"
@ -1034,15 +1063,6 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
[[package]]
name = "jobserver"
version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa"
dependencies = [
"libc",
]
[[package]]
name = "kqueue"
version = "1.0.4"
@ -1075,18 +1095,6 @@ version = "0.2.120"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad5c14e80759d0939d013e6ca49930e59fc53dd8e5009132f76240c179380c09"
[[package]]
name = "libgit2-sys"
version = "0.12.26+1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19e1c899248e606fbfe68dcb31d8b0176ebab833b103824af31bddf4b7457494"
dependencies = [
"cc",
"libc",
"libz-sys",
"pkg-config",
]
[[package]]
name = "libmimalloc-sys"
version = "0.1.24"
@ -1096,18 +1104,6 @@ dependencies = [
"cc",
]
[[package]]
name = "libz-sys"
version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f35facd4a5673cb5a48822be2be1d4236c1c99cb4113cab7061ac720d5bf859"
dependencies = [
"cc",
"libc",
"pkg-config",
"vcpkg",
]
[[package]]
name = "linked-hash-map"
version = "0.5.4"
@ -1162,12 +1158,6 @@ dependencies = [
"regex-automata",
]
[[package]]
name = "matches"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
[[package]]
name = "memchr"
version = "2.4.1"
@ -1558,12 +1548,6 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "pkg-config"
version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe"
[[package]]
name = "polling"
version = "2.2.0"
@ -1682,6 +1666,22 @@ dependencies = [
"prost",
]
[[package]]
name = "pwd"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9ca0304857594109dca88140120427c7a65027be6b77d86a5938588e79cb07b"
dependencies = [
"failure",
"libc",
]
[[package]]
name = "quick-error"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"
[[package]]
name = "quote"
version = "1.0.16"
@ -2091,6 +2091,18 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "synstructure"
version = "0.12.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f"
dependencies = [
"proc-macro2",
"quote",
"syn",
"unicode-xid",
]
[[package]]
name = "tempfile"
version = "3.3.0"
@ -2204,21 +2216,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "tinyvec"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c1c1d5a42b6245520c249549ec267180beaffcc0615401ac8e31853d4b6d8d2"
dependencies = [
"tinyvec_macros",
]
[[package]]
name = "tinyvec_macros"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tokio"
version = "1.17.0"
@ -2473,10 +2470,10 @@ dependencies = [
]
[[package]]
name = "unicode-bidi"
version = "0.3.7"
name = "unicode-bom"
version = "1.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f"
checksum = "63ec69f541d875b783ca40184d655f2927c95f0bffd486faa83cd3ac3529ec32"
[[package]]
name = "unicode-linebreak"
@ -2487,15 +2484,6 @@ dependencies = [
"regex",
]
[[package]]
name = "unicode-normalization"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9"
dependencies = [
"tinyvec",
]
[[package]]
name = "unicode-segmentation"
version = "1.9.0"
@ -2514,30 +2502,12 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "url"
version = "2.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c"
dependencies = [
"form_urlencoded",
"idna",
"matches",
"percent-encoding",
]
[[package]]
name = "valuable"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "vcpkg"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "version_check"
version = "0.9.4"
@ -2629,7 +2599,7 @@ dependencies = [
"command-group",
"dunce",
"futures",
"git2",
"git-config",
"globset",
"ignore",
"libc",

View File

@ -22,6 +22,7 @@ atomic-take = "1.0.0"
clearscreen = "1.0.9"
dunce = "1.0.2"
futures = "0.3.16"
git-config = "0.2.0"
globset = "0.4.8"
ignore = "0.4.18"
miette = "3.2.0"
@ -36,10 +37,6 @@ unicase = "2.6.0"
version = "1.0.8"
features = ["with-tokio"]
[dependencies.git2]
version = "0.13.22"
default-features = false
[dependencies.notify]
version = "=5.0.0-pre.14"

View File

@ -1,3 +1,7 @@
use git_config::{
file::{from_paths, GitConfig},
values::Path as GitPath,
};
use std::{
collections::HashSet,
env,
@ -62,18 +66,25 @@ pub async fn from_origin(path: impl AsRef<Path>) -> (Vec<IgnoreFile>, Vec<Error>
match find_file(base.join(".git/config")).await {
Err(err) => errors.push(err),
Ok(None) => {}
Ok(Some(path)) => match git2::Config::open(&path) {
Ok(Some(path)) => match GitConfig::open(&path) {
Err(err) => errors.push(Error::new(ErrorKind::Other, err)),
Ok(config) => {
if let Ok(excludes) = config.get_path("core.excludesFile") {
discover_file(
&mut files,
&mut errors,
None,
Some(ProjectType::Git),
excludes,
)
.await;
if let Ok(excludes) = config.value::<GitPath>("core", None, "excludesFile") {
match excludes.interpolate(None) {
Ok(e) => {
discover_file(
&mut files,
&mut errors,
None,
Some(ProjectType::Git),
e.into(),
)
.await;
}
Err(err) => {
errors.push(Error::new(ErrorKind::Other, err));
}
}
}
}
},
@ -194,20 +205,28 @@ pub async fn from_environment() -> (Vec<IgnoreFile>, Vec<Error>) {
}
let mut found_git_global = false;
match git2::Config::open_default() {
let options = from_paths::Options::default();
match GitConfig::from_env_paths(&options) {
Err(err) => errors.push(Error::new(ErrorKind::Other, err)),
Ok(config) => {
if let Ok(excludes) = config.get_path("core.excludesFile") {
if discover_file(
&mut files,
&mut errors,
None,
Some(ProjectType::Git),
excludes,
)
.await
{
found_git_global = true;
if let Ok(excludes) = config.value::<GitPath>("core", None, "excludesFile") {
match excludes.interpolate(None) {
Ok(e) => {
if discover_file(
&mut files,
&mut errors,
None,
Some(ProjectType::Git),
e.into(),
)
.await
{
found_git_global = true;
}
}
Err(err) => {
errors.push(Error::new(ErrorKind::Other, err));
}
}
}
}