Skip to content

Commit 3a1dd44

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 c32c076 commit 3a1dd44

File tree

3 files changed

+11
-23
lines changed

3 files changed

+11
-23
lines changed

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

+2-7
Original file line numberDiff line numberDiff line change
@@ -3316,13 +3316,8 @@ impl Config {
33163316
.unwrap()
33173317
.entry(paths.to_vec())
33183318
.or_insert_with(|| {
3319-
check_path_modifications(
3320-
Some(&self.src),
3321-
&self.git_config(),
3322-
paths,
3323-
CiEnv::current(),
3324-
)
3325-
.unwrap()
3319+
check_path_modifications(&self.src, &self.git_config(), paths, CiEnv::current())
3320+
.unwrap()
33263321
})
33273322
.clone()
33283323
}

src/bootstrap/src/utils/tests/git.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ impl GitCtx {
3636
}
3737

3838
pub fn check_modifications(&self, target_paths: &[&str], ci_env: CiEnv) -> PathFreshness {
39-
check_path_modifications(Some(self.dir.path()), &self.git_config(), target_paths, ci_env)
40-
.unwrap()
39+
check_path_modifications(self.dir.path(), &self.git_config(), target_paths, ci_env).unwrap()
4140
}
4241

4342
pub fn create_upstream_merge(&self, modified_files: &[&str]) -> String {

src/build_helper/src/git.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub enum PathFreshness {
5454
/// local git history.
5555
///
5656
/// `target_paths` should be a non-empty slice of paths (git `pathspec`s) relative to `git_dir`
57-
/// or the current working directory whose modifications would invalidate the artifact.
57+
/// whose modifications would invalidate the artifact.
5858
/// Each pathspec can also be a negative match, i.e. `:!foo`. This matches changes outside
5959
/// the `foo` directory.
6060
/// See https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec
@@ -79,7 +79,7 @@ pub enum PathFreshness {
7979
/// In that case we simply take the latest upstream commit, because on CI there is no need to avoid
8080
/// redownloading.
8181
pub fn check_path_modifications(
82-
git_dir: Option<&Path>,
82+
git_dir: &Path,
8383
config: &GitConfig<'_>,
8484
target_paths: &[&str],
8585
ci_env: CiEnv,
@@ -109,7 +109,7 @@ pub fn check_path_modifications(
109109
// Do not include HEAD, as it is never an upstream commit
110110
// If we do not find an upstream commit in CI, something is seriously wrong.
111111
Some(
112-
get_closest_upstream_commit(git_dir, config, ci_env)?
112+
get_closest_upstream_commit(Some(git_dir), config, ci_env)?
113113
.expect("No upstream commit was found on CI"),
114114
)
115115
} else {
@@ -124,7 +124,7 @@ pub fn check_path_modifications(
124124
)?;
125125
match upstream_with_modifications {
126126
Some(sha) => Some(sha),
127-
None => get_closest_upstream_commit(git_dir, config, ci_env)?,
127+
None => get_closest_upstream_commit(Some(git_dir), config, ci_env)?,
128128
}
129129
};
130130

@@ -145,12 +145,9 @@ pub fn check_path_modifications(
145145
}
146146

147147
/// Returns true if any of the passed `paths` have changed since the `base` commit.
148-
pub fn has_changed_since(git_dir: Option<&Path>, base: &str, paths: &[&str]) -> bool {
148+
pub fn has_changed_since(git_dir: &Path, base: &str, paths: &[&str]) -> bool {
149149
let mut git = Command::new("git");
150-
151-
if let Some(git_dir) = git_dir {
152-
git.current_dir(git_dir);
153-
}
150+
git.current_dir(git_dir);
154151

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

@@ -162,15 +159,12 @@ pub fn has_changed_since(git_dir: Option<&Path>, base: &str, paths: &[&str]) ->
162159
/// Returns the latest commit that modified `target_paths`, or `None` if no such commit was found.
163160
/// If `author` is `Some`, only considers commits made by that author.
164161
fn get_latest_commit_that_modified_files(
165-
git_dir: Option<&Path>,
162+
git_dir: &Path,
166163
target_paths: &[&str],
167164
author: &str,
168165
) -> Result<Option<String>, String> {
169166
let mut git = Command::new("git");
170-
171-
if let Some(git_dir) = git_dir {
172-
git.current_dir(git_dir);
173-
}
167+
git.current_dir(git_dir);
174168

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

0 commit comments

Comments
 (0)