History

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.

Sebastian Thiel committed 2 years ago

Commit a7e606b1 parent eace8bf3 files · +14 −16Browse files

Unified · Split

3 files
  1. Cargo.lock +0 −1
  2. gix/Cargo.toml +0 −3
  3. gix/src/env.rs +14 −12
Cargo.lock+0−1
@@ -1392,7 +1392,6 @@ dependencies = [ · 1391 unmodified lines
13921392 "signal-hook",
13931393 "smallvec",
13941394 "thiserror",
1395− "unicode-normalization",
13961395 "walkdir",
13971396 ]
13981397
gix/Cargo.toml+0−3
@@ -300,9 +300,6 @@ parking_lot = "0.12.1" · 299 unmodified lines
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+14−12
@@ -12,21 +12,23 @@ pub fn agent() -> &'static str { · 11 unmodified lines
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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t