Skip to content

Commit 65f706b

Browse files
committed
Revise gix_path::env docstrings for clarity
1 parent b7029f8 commit 65f706b

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

gix-path/src/env/mod.rs

+21-18
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,16 @@ pub fn shell() -> &'static OsStr {
6767
}
6868

6969
/// Return the name of the Git executable to invoke it.
70+
///
7071
/// If it's in the `PATH`, it will always be a short name.
7172
///
7273
/// Note that on Windows, we will find the executable in the `PATH` if it exists there, or search it
7374
/// in alternative locations which when found yields the full path to it.
7475
pub fn exe_invocation() -> &'static Path {
7576
if cfg!(windows) {
76-
/// The path to the Git executable as located in the `PATH` or in other locations that it's known to be installed to.
77-
/// It's `None` if environment variables couldn't be read or if no executable could be found.
77+
/// The path to the Git executable as located in the `PATH` or in other locations that it's
78+
/// known to be installed to. It's `None` if environment variables couldn't be read or if
79+
/// no executable could be found.
7880
static EXECUTABLE_PATH: Lazy<Option<PathBuf>> = Lazy::new(|| {
7981
std::env::split_paths(&std::env::var_os("PATH")?)
8082
.chain(git::ALTERNATIVE_LOCATIONS.iter().map(Into::into))
@@ -99,11 +101,11 @@ pub fn exe_invocation() -> &'static Path {
99101
}
100102
}
101103

102-
/// Returns the fully qualified path in the *xdg-home* directory (or equivalent in the home dir) to `file`,
103-
/// accessing `env_var(<name>)` to learn where these bases are.
104+
/// Returns the fully qualified path in the *xdg-home* directory (or equivalent in the home dir) to
105+
/// `file`, accessing `env_var(<name>)` to learn where these bases are.
104106
///
105-
/// Note that the `HOME` directory should ultimately come from [`home_dir()`] as it handles windows correctly.
106-
/// The same can be achieved by using [`var()`] as `env_var`.
107+
/// Note that the `HOME` directory should ultimately come from [`home_dir()`] as it handles Windows
108+
/// correctly. The same can be achieved by using [`var()`] as `env_var`.
107109
pub fn xdg_config(file: &str, env_var: &mut dyn FnMut(&str) -> Option<OsString>) -> Option<PathBuf> {
108110
env_var("XDG_CONFIG_HOME")
109111
.map(|home| {
@@ -153,17 +155,17 @@ pub fn core_dir() -> Option<&'static Path> {
153155
GIT_CORE_DIR.as_deref()
154156
}
155157

156-
/// Returns the platform dependent system prefix or `None` if it cannot be found (right now only on windows).
158+
/// Returns the platform dependent system prefix or `None` if it cannot be found (right now only on Windows).
157159
///
158160
/// ### Performance
159161
///
160-
/// On windows, the slowest part is the launch of the Git executable in the PATH, which only happens when launched
161-
/// from outside of the `msys2` shell.
162+
/// On Windows, the slowest part is the launch of the Git executable in the PATH. This is often
163+
/// avoided by inspecting the environment, when launched from inside a Git Bash MSYS2 shell.
162164
///
163165
/// ### When `None` is returned
164166
///
165-
/// This happens only windows if the git binary can't be found at all for obtaining its executable path, or if the git binary
166-
/// wasn't built with a well-known directory structure or environment.
167+
/// This happens only Windows if the git binary can't be found at all for obtaining its executable
168+
/// path, or if the git binary wasn't built with a well-known directory structure or environment.
167169
pub fn system_prefix() -> Option<&'static Path> {
168170
if cfg!(windows) {
169171
static PREFIX: Lazy<Option<PathBuf>> = Lazy::new(|| {
@@ -194,19 +196,20 @@ pub fn home_dir() -> Option<PathBuf> {
194196
std::env::var("HOME").map(PathBuf::from).ok()
195197
}
196198

197-
/// Tries to obtain the home directory from `HOME` on all platforms, but falls back to [`home::home_dir()`] for
198-
/// more complex ways of obtaining a home directory, particularly useful on Windows.
199+
/// Tries to obtain the home directory from `HOME` on all platforms, but falls back to
200+
/// [`home::home_dir()`] for more complex ways of obtaining a home directory, particularly useful
201+
/// on Windows.
199202
///
200-
/// The reason `HOME` is tried first is to allow Windows users to have a custom location for their linux-style
201-
/// home, as otherwise they would have to accumulate dot files in a directory these are inconvenient and perceived
202-
/// as clutter.
203+
/// The reason `HOME` is tried first is to allow Windows users to have a custom location for their
204+
/// linux-style home, as otherwise they would have to accumulate dot files in a directory these are
205+
/// inconvenient and perceived as clutter.
203206
#[cfg(not(target_family = "wasm"))]
204207
pub fn home_dir() -> Option<PathBuf> {
205208
std::env::var_os("HOME").map(Into::into).or_else(home::home_dir)
206209
}
207210

208-
/// Returns the contents of an environment variable of `name` with some special handling
209-
/// for certain environment variables (like `HOME`) for platform compatibility.
211+
/// Returns the contents of an environment variable of `name` with some special handling for
212+
/// certain environment variables (like `HOME`) for platform compatibility.
210213
pub fn var(name: &str) -> Option<OsString> {
211214
if name == "HOME" {
212215
home_dir().map(PathBuf::into_os_string)

0 commit comments

Comments
 (0)