Skip to content

Commit 2abbb1a

Browse files
committed
Simplify code and comments
1 parent 31de9fb commit 2abbb1a

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

gix-path/src/env/auxiliary.rs

+14-19
Original file line numberDiff line numberDiff line change
@@ -62,33 +62,28 @@ fn git_for_windows_root() -> Option<&'static Path> {
6262

6363
/// Shell path fragments to concatenate to the root of a Git for Windows or MSYS2 installation.
6464
///
65-
/// These look like absolute Unix-style paths, but the leading `/` separators are present because
66-
/// they simplify forming paths like `C:/Program Files/Git` obtained by removing trailing
67-
/// components from the output of `git --exec-path`.
68-
const RAW_SH_EXE_PATH_SUFFIXES: &[&str] = &[
69-
"/bin/sh.exe", // Usually a shim, which currently we prefer, if available.
70-
"/usr/bin/sh.exe",
71-
];
72-
65+
/// When appended to the root of a Git for Windows installation, these are locations where `sh.exe`
66+
/// can usually be found. The leading `/` allow these to be used (only) with `raw_join()`.
7367
///
68+
/// These are ordered so that a shim is preferred over a non-shim when they are tried in order.
69+
const RAW_SH_EXE_PATH_SUFFIXES: &[&str] = &["/bin/sh.exe", "/usr/bin/sh.exe"];
70+
71+
/// Concatenate a path by appending a raw suffix, which must contain its own leading separator.
7472
fn raw_join(path: &Path, raw_suffix: &str) -> OsString {
7573
let mut raw_path = OsString::from(path);
7674
raw_path.push(raw_suffix);
7775
raw_path
7876
}
7977

8078
/// Obtain a path to a `sh.exe` on Windows associated with Git, if one can be found.
79+
///
80+
/// The resulting path uses only `/` separators so long as the path obtained from `git --exec-path`
81+
/// does, which is the case unless it is overridden by setting `GIT_EXEC_PATH` to an unusual value.
8182
pub(super) fn find_sh_on_windows() -> Option<OsString> {
82-
git_for_windows_root()
83-
.into_iter()
84-
.flat_map(|git_root| {
85-
// Enumerate locations where `sh.exe` usually is. To avoid breaking scripts that assume the
86-
// shell's own path contains no `\`, and so messages are more readable, append literally
87-
// with `/` separators. The path from `git --exec-path` already uses `/` separators (and no
88-
// trailing `/`) unless explicitly overridden to an unusual value via `GIT_EXEC_PATH`.
89-
RAW_SH_EXE_PATH_SUFFIXES
90-
.iter()
91-
.map(|raw_suffix| raw_join(git_root, raw_suffix))
92-
})
83+
let git_root = git_for_windows_root()?;
84+
85+
RAW_SH_EXE_PATH_SUFFIXES
86+
.iter()
87+
.map(|raw_suffix| raw_join(git_root, raw_suffix))
9388
.find(|raw_path| Path::new(raw_path).is_file())
9489
}

0 commit comments

Comments
 (0)