Skip to content

Commit ab0dcc1

Browse files
committed
Refactor for readability; clarify comments
1 parent 8472447 commit ab0dcc1

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

gix-path/src/env/git/mod.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,21 @@ fn exe_info() -> Option<BString> {
109109
fn git_cmd(executable: PathBuf) -> Command {
110110
let mut cmd = Command::new(executable);
111111

112-
#[cfg(windows)]
113-
{
114-
use std::env;
112+
if cfg!(windows) {
115113
use std::os::windows::process::CommandExt;
116114
const CREATE_NO_WINDOW: u32 = 0x08000000;
117115
cmd.creation_flags(CREATE_NO_WINDOW);
118116

119-
cmd.current_dir(
120-
env::var_os("SystemRoot") // Most reliable env var for path to Windows directory.
121-
.or_else(|| env::var_os("windir")) // Less reliable, but some callers are unusual.
122-
.map(PathBuf::from)
123-
.filter(|p| p.is_absolute())
124-
.unwrap_or_else(env::temp_dir),
125-
);
117+
use std::env;
118+
let cwd = env::var_os("SystemRoot") // Usually `C:\Windows`. Not to be confused with `C:\`.
119+
.or_else(|| env::var_os("windir")) // Same. Less reliable, but some callers are unusual.
120+
.map(PathBuf::from)
121+
.filter(|p| p.is_absolute())
122+
.unwrap_or_else(env::temp_dir);
123+
cmd.current_dir(cwd);
124+
} else {
125+
cmd.current_dir("/");
126126
}
127-
#[cfg(not(windows))]
128-
cmd.current_dir("/");
129127

130128
// Git 2.8.0 and higher support --show-origin. The -l, -z, and --name-only options were
131129
// supported even before that. In contrast, --show-scope was introduced later, in Git 2.26.0.
@@ -140,7 +138,7 @@ fn git_cmd(executable: PathBuf) -> Command {
140138
//
141139
cmd.args(["config", "-lz", "--show-origin", "--name-only"])
142140
.env("GIT_DIR", NULL_DEVICE) // Avoid getting local-scope config.
143-
.env("GIT_WORK_TREE", NULL_DEVICE) // Not needed, but clarifies intent.
141+
.env("GIT_WORK_TREE", NULL_DEVICE) // Just to avoid confusion when debugging.
144142
.stdin(Stdio::null())
145143
.stderr(Stdio::null());
146144

gix-path/src/env/git/tests.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ use std::path::{Path, PathBuf};
360360
use gix_testtools::tempfile;
361361
use serial_test::serial;
362362

363-
/// Wrapper for a path to a location kept from accidentally existing, until drop.
363+
/// Wrapper for a valid path to a plausible location, kept from accidentally existing (until drop).
364364
#[derive(Debug)]
365365
struct NonexistentLocation {
366366
_empty: tempfile::TempDir,
@@ -443,8 +443,8 @@ fn exe_info_tolerates_broken_temp() {
443443
#[test]
444444
#[serial]
445445
fn exe_info_tolerates_oversanitized_env() {
446-
// This test runs on all systems, but it is a regression test for Windows.
447-
// Also, having both a broken temp dir and an over-sanitized environment is not supported.
446+
// This test runs on all systems, but it is only checking for a Windows regression. Also, on
447+
// Windows, having both a broken temp dir and an over-sanitized environment is not supported.
448448
let _env = unset_windows_directory_vars();
449449
check_exe_info();
450450
}
@@ -466,7 +466,6 @@ fn exe_info_same_result_with_broken_temp() {
466466
#[test]
467467
#[serial]
468468
fn exe_info_same_result_with_oversanitized_env() {
469-
// See `exe_info_tolerates_oversanitized_env`.
470469
let with_unmodified_env = super::exe_info();
471470

472471
let with_oversanitized_env = {

0 commit comments

Comments
 (0)