@@ -115,9 +115,14 @@ fn git_cmd(executable: PathBuf) -> Command {
115
115
const CREATE_NO_WINDOW : u32 = 0x08000000 ;
116
116
cmd. creation_flags ( CREATE_NO_WINDOW ) ;
117
117
}
118
+ // We will try to run `git` from a location fairly high in the filesystem. This can be faster
119
+ // than running it from our CWD, if we are deeply nested or on network storage. We try to pick
120
+ // a place that exists, is unlikely to be a repo, and forbids unprivileged users from putting a
121
+ // `.git` dir or other entries inside (so not `C:\` on Windows). But we will also be setting
122
+ // `GIT_DIR` to a location `git` can't read config from, so this is mostly for performance.
118
123
let cwd = if cfg ! ( windows) {
119
124
env:: var_os ( "SystemRoot" ) // Usually `C:\Windows`. Not to be confused with `C:\`.
120
- . or_else ( || env:: var_os ( "windir" ) ) // Same, in case our parent filtered out SystemRoot.
125
+ . or_else ( || env:: var_os ( "windir" ) ) // Same. In case our parent filtered out SystemRoot.
121
126
. map ( PathBuf :: from)
122
127
. filter ( |p| p. is_absolute ( ) )
123
128
. unwrap_or_else ( env:: temp_dir)
@@ -126,19 +131,18 @@ fn git_cmd(executable: PathBuf) -> Command {
126
131
} ;
127
132
// Git 2.8.0 and higher support --show-origin. The -l, -z, and --name-only options were
128
133
// supported even before that. In contrast, --show-scope was introduced later, in Git 2.26.0.
129
- // Low versions of git are still sometimes used, and this is sometimes reasonable because
134
+ // Low versions of Git are still sometimes used, and this is sometimes reasonable because
130
135
// downstream distributions often backport security patches without adding most new features.
131
136
// So for now, we forgo the convenience of --show-scope for greater backward compatibility.
132
137
//
133
138
// Separately from that, we can't use --system here, because scopes treated higher than the
134
139
// system scope are possible. This commonly happens on macOS with Apple Git, where the config
135
- // file under /Library is shown as an "unknown" scope but takes precedence over the system
136
- // scope. Although GIT_CONFIG_NOSYSTEM will suppress this as well, passing --system omits it.
137
- //
140
+ // file under `/Library` is shown as an "unknown" scope but takes precedence over the system
141
+ // scope. Although `GIT_CONFIG_NOSYSTEM` will suppress this as well, passing --system omits it.
138
142
cmd. args ( [ "config" , "-lz" , "--show-origin" , "--name-only" ] )
139
143
. current_dir ( cwd)
140
144
. env ( "GIT_DIR" , NULL_DEVICE ) // Avoid getting local-scope config.
141
- . env ( "GIT_WORK_TREE" , NULL_DEVICE ) // Just to avoid confusion when debugging.
145
+ . env ( "GIT_WORK_TREE" , NULL_DEVICE ) // This is just to avoid confusion when debugging.
142
146
. stdin ( Stdio :: null ( ) )
143
147
. stderr ( Stdio :: null ( ) ) ;
144
148
cmd
0 commit comments