Skip to content

Commit

Permalink
feat: add env::args_os_opt() which takes an argument to determine i…
Browse files Browse the repository at this point in the history
…nput unicode-decomposition

This allows for the possibility to respect `core.precomposeUnicode` should one already have that value.
  • Loading branch information
Byron committed Jan 16, 2024
1 parent eace8bf commit a7e606b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions gix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,6 @@ parking_lot = "0.12.1"

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

[target.'cfg(target_vendor = "apple")'.dependencies]
unicode-normalization = { version = "0.1.19", default-features = false }

[dev-dependencies]
gix-testtools = { path = "../tests/tools" }
is_ci = "1.1.1"
Expand Down
26 changes: 14 additions & 12 deletions gix/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,23 @@ pub fn agent() -> &'static str {
concat!("oxide-", env!("CARGO_PKG_VERSION"))
}

/// Equivalent to `std::env::args_os()`, but with precomposed unicode on `MacOS` and other apple platforms.
#[cfg(not(target_vendor = "apple"))]
pub fn args_os() -> impl Iterator<Item = OsString> {
std::env::args_os()
}

/// Equivalent to `std::env::args_os()`, but with precomposed unicode on MacOS and other apple platforms.
/// It does not change the input arguments on any other platform.
///
/// Note that this ignores `core.precomposeUnicode` as git-config isn't available yet. It's default enabled in modern git though.
#[cfg(target_vendor = "apple")]
/// Note that this ignores `core.precomposeUnicode` as git-config isn't available yet. It's default enabled in modern git though,
/// and generally decomposed unicode is nothing one would want in a git repository.
pub fn args_os() -> impl Iterator<Item = OsString> {
use unicode_normalization::UnicodeNormalization;
std::env::args_os().map(|arg| match arg.to_str() {
Some(arg) => arg.nfc().collect::<String>().into(),
None => arg,
args_os_opt(cfg!(target_vendor = "apple"))
}

/// Like [`args_os()`], but with the `precompose_unicode` parameter akin to `core.precomposeUnicode` in the Git configuration.
pub fn args_os_opt(precompose_unicode: bool) -> impl Iterator<Item = OsString> {
std::env::args_os().map(move |arg| {
if precompose_unicode {
gix_utils::str::precompose_os_string(arg.into()).into_owned()
} else {
arg
}
})
}

Expand Down

0 comments on commit a7e606b

Please sign in to comment.