From 7cd20bba2ccb8224b25eeb6a579c6130d0c9ce2e Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sat, 31 Aug 2024 06:28:02 -0400 Subject: [PATCH 1/6] Fix indentation nit --- gix-path/src/env/git/tests.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gix-path/src/env/git/tests.rs b/gix-path/src/env/git/tests.rs index e7cf48310bc..a9c2e83e36b 100644 --- a/gix-path/src/env/git/tests.rs +++ b/gix-path/src/env/git/tests.rs @@ -551,9 +551,9 @@ mod exe_info { let maybe_path = exe_info(); assert_eq!( - maybe_path, None, - "Should find no config path if the config would be local even in a `/tmp`-like dir (suppressed system config)" - ); + maybe_path, None, + "Should find no config path if the config would be local even in a `/tmp`-like dir (suppressed system config)" + ); } } From 57e9a6fa1d354eb9a29e6e6fd2a1d09190292804 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sat, 31 Aug 2024 06:29:01 -0400 Subject: [PATCH 2/6] Put `first_file_from_config_with_origin` test with related ones This moves the `first_file_from_config_with_origin` test into the nested `exe_info` module, because like the other functions tested there, `first_file_from_config_with_origin` is a helper function for `EXE_INFO` that is separate largely to facilitate testing. --- gix-path/src/env/git/tests.rs | 60 +++++++++++++++++------------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/gix-path/src/env/git/tests.rs b/gix-path/src/env/git/tests.rs index a9c2e83e36b..ff38c7e13fc 100644 --- a/gix-path/src/env/git/tests.rs +++ b/gix-path/src/env/git/tests.rs @@ -555,37 +555,37 @@ mod exe_info { "Should find no config path if the config would be local even in a `/tmp`-like dir (suppressed system config)" ); } -} -#[test] -fn first_file_from_config_with_origin() { - let macos = - "file:/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig\0credential.helper\0file:/Users/byron/.gitconfig\0push.default\0"; - let win_msys = "file:C:/git-sdk-64/etc/gitconfig\0core.symlinks\0file:C:/git-sdk-64/etc/gitconfig\0core.autocrlf\0"; - let win_cmd = - "file:C:/Program Files/Git/etc/gitconfig\0diff.astextplain.textconv\0file:C:/Program Files/Git/etc/gitconfig\0filter.lfs.clean\0"; - let win_msys_old = - "file:C:\\ProgramData/Git/config\0diff.astextplain.textconv\0file:C:\\ProgramData/Git/config\0filter.lfs.clean\0"; - let linux = "file:/home/parallels/.gitconfig\0core.excludesfile\0"; - let bogus = "something unexpected"; - let empty = ""; - - for (source, expected) in [ - ( - macos, - Some("/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig"), - ), - (win_msys, Some("C:/git-sdk-64/etc/gitconfig")), - (win_msys_old, Some("C:\\ProgramData/Git/config")), - (win_cmd, Some("C:/Program Files/Git/etc/gitconfig")), - (linux, Some("/home/parallels/.gitconfig")), - (bogus, None), - (empty, None), - ] { - assert_eq!( - super::first_file_from_config_with_origin(source.into()), - expected.map(Into::into) - ); + #[test] + fn first_file_from_config_with_origin() { + let macos = + "file:/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig\0credential.helper\0file:/Users/byron/.gitconfig\0push.default\0"; + let win_msys = "file:C:/git-sdk-64/etc/gitconfig\0core.symlinks\0file:C:/git-sdk-64/etc/gitconfig\0core.autocrlf\0"; + let win_cmd = + "file:C:/Program Files/Git/etc/gitconfig\0diff.astextplain.textconv\0file:C:/Program Files/Git/etc/gitconfig\0filter.lfs.clean\0"; + let win_msys_old = + "file:C:\\ProgramData/Git/config\0diff.astextplain.textconv\0file:C:\\ProgramData/Git/config\0filter.lfs.clean\0"; + let linux = "file:/home/parallels/.gitconfig\0core.excludesfile\0"; + let bogus = "something unexpected"; + let empty = ""; + + for (source, expected) in [ + ( + macos, + Some("/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig"), + ), + (win_msys, Some("C:/git-sdk-64/etc/gitconfig")), + (win_msys_old, Some("C:\\ProgramData/Git/config")), + (win_cmd, Some("C:/Program Files/Git/etc/gitconfig")), + (linux, Some("/home/parallels/.gitconfig")), + (bogus, None), + (empty, None), + ] { + assert_eq!( + crate::env::git::first_file_from_config_with_origin(source.into()), + expected.map(Into::into) + ); + } } } From 9917d4719ed32fd34628594aaea6d4ca816448e3 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sat, 31 Aug 2024 06:36:23 -0400 Subject: [PATCH 3/6] Make `NULL_DEVICE` a `const`, rather than a `static` item In `gix_path::env::git`. --- gix-path/src/env/git/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gix-path/src/env/git/mod.rs b/gix-path/src/env/git/mod.rs index 04cc376f8a9..ab45731d0f8 100644 --- a/gix-path/src/env/git/mod.rs +++ b/gix-path/src/env/git/mod.rs @@ -83,9 +83,9 @@ pub(super) static EXE_NAME: &str = "git"; pub(super) static EXE_INFO: Lazy> = Lazy::new(exe_info); #[cfg(windows)] -static NULL_DEVICE: &str = "NUL"; +const NULL_DEVICE: &str = "NUL"; #[cfg(not(windows))] -static NULL_DEVICE: &str = "/dev/null"; +const NULL_DEVICE: &str = "/dev/null"; fn exe_info() -> Option { let mut cmd = git_cmd(EXE_NAME.into()); From fb0b6d8823354b50f3bd2eb3a8eb6ea3da56b5b6 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sat, 31 Aug 2024 06:40:53 -0400 Subject: [PATCH 4/6] Make `EXE_NAME` a `const` too The `gix_path::env::git::EXE_NAME` static item, while more visible than `NULL_DEVICE`, was crate-internal via `pub(super)`. So making it a `const` instead, as done here, is not a breaking nor otherwise user-facing change. --- gix-path/src/env/git/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gix-path/src/env/git/mod.rs b/gix-path/src/env/git/mod.rs index ab45731d0f8..7014a4b7154 100644 --- a/gix-path/src/env/git/mod.rs +++ b/gix-path/src/env/git/mod.rs @@ -73,9 +73,9 @@ where } #[cfg(windows)] -pub(super) static EXE_NAME: &str = "git.exe"; +pub(super) const EXE_NAME: &str = "git.exe"; #[cfg(not(windows))] -pub(super) static EXE_NAME: &str = "git"; +pub(super) const EXE_NAME: &str = "git"; /// Invoke the git executable to obtain the origin configuration, which is cached and returned. /// From b11f7db7d16c06c040619cf0fb5feab85734bc06 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sat, 31 Aug 2024 06:44:33 -0400 Subject: [PATCH 5/6] Run `cargo fmt` --- gix-path/src/env/git/tests.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gix-path/src/env/git/tests.rs b/gix-path/src/env/git/tests.rs index ff38c7e13fc..e02fdb349f0 100644 --- a/gix-path/src/env/git/tests.rs +++ b/gix-path/src/env/git/tests.rs @@ -560,7 +560,8 @@ mod exe_info { fn first_file_from_config_with_origin() { let macos = "file:/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig\0credential.helper\0file:/Users/byron/.gitconfig\0push.default\0"; - let win_msys = "file:C:/git-sdk-64/etc/gitconfig\0core.symlinks\0file:C:/git-sdk-64/etc/gitconfig\0core.autocrlf\0"; + let win_msys = + "file:C:/git-sdk-64/etc/gitconfig\0core.symlinks\0file:C:/git-sdk-64/etc/gitconfig\0core.autocrlf\0"; let win_cmd = "file:C:/Program Files/Git/etc/gitconfig\0diff.astextplain.textconv\0file:C:/Program Files/Git/etc/gitconfig\0filter.lfs.clean\0"; let win_msys_old = From dd2d6665981425f5878318d5469216f27c3ac278 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 31 Aug 2024 13:18:58 +0200 Subject: [PATCH 6/6] Rename `EXE_INFO` to something that probably captures its contents better. --- gix-path/src/env/git/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gix-path/src/env/git/mod.rs b/gix-path/src/env/git/mod.rs index 7014a4b7154..c138773d9c6 100644 --- a/gix-path/src/env/git/mod.rs +++ b/gix-path/src/env/git/mod.rs @@ -80,7 +80,7 @@ pub(super) const EXE_NAME: &str = "git"; /// Invoke the git executable to obtain the origin configuration, which is cached and returned. /// /// The git executable is the one found in PATH or an alternative location. -pub(super) static EXE_INFO: Lazy> = Lazy::new(exe_info); +pub(super) static GIT_HIGHEST_PRIORITY_CONFIG_PATH: Lazy> = Lazy::new(exe_info); #[cfg(windows)] const NULL_DEVICE: &str = "NUL"; @@ -171,7 +171,7 @@ pub(super) fn install_config_path() -> Option<&'static BStr> { exec_path.push("gitconfig"); return crate::os_string_into_bstring(exec_path.into()).ok(); } - EXE_INFO.clone() + GIT_HIGHEST_PRIORITY_CONFIG_PATH.clone() }); PATH.as_ref().map(AsRef::as_ref) }