Skip to content

Commit b45e597

Browse files
committed
Make git_dir required in several git functions
It was always called with `Some`, so no need to complicate it with `Option`.
1 parent 6303b05 commit b45e597

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

src/bootstrap/src/core/config/config.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3181,13 +3181,8 @@ impl Config {
31813181
.unwrap()
31823182
.entry(paths.to_vec())
31833183
.or_insert_with(|| {
3184-
check_path_modifications(
3185-
Some(&self.src),
3186-
&self.git_config(),
3187-
paths,
3188-
CiEnv::current(),
3189-
)
3190-
.unwrap()
3184+
check_path_modifications(&self.src, &self.git_config(), paths, CiEnv::current())
3185+
.unwrap()
31913186
})
31923187
.clone()
31933188
}

src/build_helper/src/git.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub enum PathFreshness {
7575
/// PR made modifications to `target_paths`. If not, then we simply take the latest upstream
7676
/// commit, because on CI there is no need to avoid redownloading.
7777
pub fn check_path_modifications(
78-
git_dir: Option<&Path>,
78+
git_dir: &Path,
7979
config: &GitConfig<'_>,
8080
target_paths: &[&str],
8181
ci_env: CiEnv,
@@ -105,7 +105,7 @@ pub fn check_path_modifications(
105105
// Do not include HEAD, as it is never an upstream commit
106106
// If we do not find an upstream commit in CI, something is seriously wrong.
107107
Some(
108-
get_closest_upstream_commit(git_dir, config, ci_env)?
108+
get_closest_upstream_commit(Some(git_dir), config, ci_env)?
109109
.expect("No upstream commit was found on CI"),
110110
)
111111
} else {
@@ -120,7 +120,7 @@ pub fn check_path_modifications(
120120
)?;
121121
match upstream_with_modifications {
122122
Some(sha) => Some(sha),
123-
None => get_closest_upstream_commit(git_dir, config, ci_env)?,
123+
None => get_closest_upstream_commit(Some(git_dir), config, ci_env)?,
124124
}
125125
};
126126

@@ -141,12 +141,9 @@ pub fn check_path_modifications(
141141
}
142142

143143
/// Returns true if any of the passed `paths` have changed since the `base` commit.
144-
pub fn has_changed_since(git_dir: Option<&Path>, base: &str, paths: &[&str]) -> bool {
144+
pub fn has_changed_since(git_dir: &Path, base: &str, paths: &[&str]) -> bool {
145145
let mut git = Command::new("git");
146-
147-
if let Some(git_dir) = git_dir {
148-
git.current_dir(git_dir);
149-
}
146+
git.current_dir(git_dir);
150147

151148
git.args(["diff-index", "--quiet", base, "--"]).args(paths);
152149

@@ -158,15 +155,12 @@ pub fn has_changed_since(git_dir: Option<&Path>, base: &str, paths: &[&str]) ->
158155
/// Returns the latest commit that modified `target_paths`, or `None` if no such commit was found.
159156
/// If `author` is `Some`, only considers commits made by that author.
160157
fn get_latest_commit_that_modified_files(
161-
git_dir: Option<&Path>,
158+
git_dir: &Path,
162159
target_paths: &[&str],
163160
author: &str,
164161
) -> Result<Option<String>, String> {
165162
let mut git = Command::new("git");
166-
167-
if let Some(git_dir) = git_dir {
168-
git.current_dir(git_dir);
169-
}
163+
git.current_dir(git_dir);
170164

171165
git.args(["rev-list", "-n1", "--first-parent", "HEAD", "--author", author]);
172166

0 commit comments

Comments
 (0)