@@ -67,14 +67,16 @@ pub fn shell() -> &'static OsStr {
67
67
}
68
68
69
69
/// Return the name of the Git executable to invoke it.
70
+ ///
70
71
/// If it's in the `PATH`, it will always be a short name.
71
72
///
72
73
/// Note that on Windows, we will find the executable in the `PATH` if it exists there, or search it
73
74
/// in alternative locations which when found yields the full path to it.
74
75
pub fn exe_invocation ( ) -> & ' static Path {
75
76
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.
78
80
static EXECUTABLE_PATH : Lazy < Option < PathBuf > > = Lazy :: new ( || {
79
81
std:: env:: split_paths ( & std:: env:: var_os ( "PATH" ) ?)
80
82
. chain ( git:: ALTERNATIVE_LOCATIONS . iter ( ) . map ( Into :: into) )
@@ -99,11 +101,11 @@ pub fn exe_invocation() -> &'static Path {
99
101
}
100
102
}
101
103
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.
104
106
///
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`.
107
109
pub fn xdg_config ( file : & str , env_var : & mut dyn FnMut ( & str ) -> Option < OsString > ) -> Option < PathBuf > {
108
110
env_var ( "XDG_CONFIG_HOME" )
109
111
. map ( |home| {
@@ -153,17 +155,17 @@ pub fn core_dir() -> Option<&'static Path> {
153
155
GIT_CORE_DIR . as_deref ( )
154
156
}
155
157
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 ).
157
159
///
158
160
/// ### Performance
159
161
///
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.
162
164
///
163
165
/// ### When `None` is returned
164
166
///
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.
167
169
pub fn system_prefix ( ) -> Option < & ' static Path > {
168
170
if cfg ! ( windows) {
169
171
static PREFIX : Lazy < Option < PathBuf > > = Lazy :: new ( || {
@@ -194,19 +196,20 @@ pub fn home_dir() -> Option<PathBuf> {
194
196
std:: env:: var ( "HOME" ) . map ( PathBuf :: from) . ok ( )
195
197
}
196
198
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.
199
202
///
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.
203
206
#[ cfg( not( target_family = "wasm" ) ) ]
204
207
pub fn home_dir ( ) -> Option < PathBuf > {
205
208
std:: env:: var_os ( "HOME" ) . map ( Into :: into) . or_else ( home:: home_dir)
206
209
}
207
210
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.
210
213
pub fn var ( name : & str ) -> Option < OsString > {
211
214
if name == "HOME" {
212
215
home_dir ( ) . map ( PathBuf :: into_os_string)
0 commit comments