Skip to content

Commit a7e606b

Browse files
committed
feat: add env::args_os_opt() which takes an argument to determine input unicode-decomposition
This allows for the possibility to respect `core.precomposeUnicode` should one already have that value.
1 parent eace8bf commit a7e606b

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gix/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,6 @@ parking_lot = "0.12.1"
300300

301301
document-features = { version = "0.2.0", optional = true }
302302

303-
[target.'cfg(target_vendor = "apple")'.dependencies]
304-
unicode-normalization = { version = "0.1.19", default-features = false }
305-
306303
[dev-dependencies]
307304
gix-testtools = { path = "../tests/tools" }
308305
is_ci = "1.1.1"

gix/src/env.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,23 @@ pub fn agent() -> &'static str {
1212
concat!("oxide-", env!("CARGO_PKG_VERSION"))
1313
}
1414

15-
/// Equivalent to `std::env::args_os()`, but with precomposed unicode on `MacOS` and other apple platforms.
16-
#[cfg(not(target_vendor = "apple"))]
17-
pub fn args_os() -> impl Iterator<Item = OsString> {
18-
std::env::args_os()
19-
}
20-
2115
/// Equivalent to `std::env::args_os()`, but with precomposed unicode on MacOS and other apple platforms.
16+
/// It does not change the input arguments on any other platform.
2217
///
23-
/// Note that this ignores `core.precomposeUnicode` as git-config isn't available yet. It's default enabled in modern git though.
24-
#[cfg(target_vendor = "apple")]
18+
/// Note that this ignores `core.precomposeUnicode` as git-config isn't available yet. It's default enabled in modern git though,
19+
/// and generally decomposed unicode is nothing one would want in a git repository.
2520
pub fn args_os() -> impl Iterator<Item = OsString> {
26-
use unicode_normalization::UnicodeNormalization;
27-
std::env::args_os().map(|arg| match arg.to_str() {
28-
Some(arg) => arg.nfc().collect::<String>().into(),
29-
None => arg,
21+
args_os_opt(cfg!(target_vendor = "apple"))
22+
}
23+
24+
/// Like [`args_os()`], but with the `precompose_unicode` parameter akin to `core.precomposeUnicode` in the Git configuration.
25+
pub fn args_os_opt(precompose_unicode: bool) -> impl Iterator<Item = OsString> {
26+
std::env::args_os().map(move |arg| {
27+
if precompose_unicode {
28+
gix_utils::str::precompose_os_string(arg.into()).into_owned()
29+
} else {
30+
arg
31+
}
3032
})
3133
}
3234

0 commit comments

Comments
 (0)