Skip to content

Commit

Permalink
support for unicode-precomposition for gix apps (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Mar 4, 2022
1 parent 4b1650b commit e90c123
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 22 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crate-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ See its [README.md](https://github.com/Byron/gitoxide/blob/main/git-lock/README.
* [x] initialize
* [ ] Proper configuration depending on platform (e.g. ignorecase, filemode, …)
* [ ] All mutations are multi-process safe and this is tested and configurable (i.e. abort or wait if lock is encountered)
* support for unicode-precomposition of command-line arguments (needs explicit use in parent application)
* **Easy** (_porcelain_)
* **Id**
* [x] short hashes with detection of ambiguity.
Expand Down
3 changes: 3 additions & 0 deletions git-repository/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ log = "0.4.14"

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]
git-testtools = { path = "../tests/tools" }
anyhow = "1"
Expand Down
23 changes: 23 additions & 0 deletions git-repository/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,26 @@ pub mod discover {
}
}
}

///
pub mod env {
use std::ffi::OsString;

/// 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.
///
/// 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")]
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,
})
}
}
20 changes: 0 additions & 20 deletions git-worktree/src/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,3 @@ pub fn create_symlink(original: &Path, link: &Path) -> io::Result<()> {
symlink_file(original, link)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn io_err_if_symlink_target_is_a_file() {
let dir = tempfile::tempdir().unwrap();
let a = dir.path().join("a");
let b = dir.path().join("b");

std::fs::write(&a, &[]).unwrap();
std::fs::write(&b, &[]).unwrap();

assert_eq!(
create_symlink(&a, &b).unwrap_err().kind(),
std::io::ErrorKind::AlreadyExists
);
}
}
2 changes: 1 addition & 1 deletion src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub mod async_util {
}

pub fn main() -> Result<()> {
let args: Args = Args::parse();
let args: Args = Args::parse_from(git_repository::env::args_os());
let thread_limit = args.threads;
let verbose = args.verbose;
let format = args.format;
Expand Down
2 changes: 1 addition & 1 deletion src/porcelain/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
};

pub fn main() -> Result<()> {
let args: Args = Args::parse();
let args: Args = Args::parse_from(git_repository::env::args_os());
let should_interrupt = Arc::new(AtomicBool::new(false));
git_repository::interrupt::init_handler({
let should_interrupt = Arc::clone(&should_interrupt);
Expand Down

0 comments on commit e90c123

Please sign in to comment.