about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJakub Beránek <berykubik@gmail.com>2025-03-24 09:16:52 +0100
committerJakub Beránek <berykubik@gmail.com>2025-04-20 09:35:42 +0200
commit3a1dd440de00eb26de3f6fe4d0005def24586dc4 (patch)
tree86ff712995ca81167608f8cc2659b47adf1c6087
parentc32c076f346cdc8a4adbd72ac55b64a636b08b45 (diff)
Make `git_dir` required in several git functions
It was always called with `Some`, so no need to complicate it with `Option`.
-rw-r--r--src/bootstrap/src/core/config/config.rs9
-rw-r--r--src/bootstrap/src/utils/tests/git.rs3
-rw-r--r--src/build_helper/src/git.rs22
3 files changed, 11 insertions, 23 deletions
diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs
index ddafddaae1c..419976c83b1 100644
--- a/src/bootstrap/src/core/config/config.rs
+++ b/src/bootstrap/src/core/config/config.rs
@@ -3316,13 +3316,8 @@ impl Config {
             .unwrap()
             .entry(paths.to_vec())
             .or_insert_with(|| {
-                check_path_modifications(
-                    Some(&self.src),
-                    &self.git_config(),
-                    paths,
-                    CiEnv::current(),
-                )
-                .unwrap()
+                check_path_modifications(&self.src, &self.git_config(), paths, CiEnv::current())
+                    .unwrap()
             })
             .clone()
     }
diff --git a/src/bootstrap/src/utils/tests/git.rs b/src/bootstrap/src/utils/tests/git.rs
index f14af5f17fd..735dafb3f29 100644
--- a/src/bootstrap/src/utils/tests/git.rs
+++ b/src/bootstrap/src/utils/tests/git.rs
@@ -36,8 +36,7 @@ impl GitCtx {
     }
 
     pub fn check_modifications(&self, target_paths: &[&str], ci_env: CiEnv) -> PathFreshness {
-        check_path_modifications(Some(self.dir.path()), &self.git_config(), target_paths, ci_env)
-            .unwrap()
+        check_path_modifications(self.dir.path(), &self.git_config(), target_paths, ci_env).unwrap()
     }
 
     pub fn create_upstream_merge(&self, modified_files: &[&str]) -> String {
diff --git a/src/build_helper/src/git.rs b/src/build_helper/src/git.rs
index 8b019c5929a..ec16607fd00 100644
--- a/src/build_helper/src/git.rs
+++ b/src/build_helper/src/git.rs
@@ -54,7 +54,7 @@ pub enum PathFreshness {
 /// local git history.
 ///
 /// `target_paths` should be a non-empty slice of paths (git `pathspec`s) relative to `git_dir`
-/// or the current working directory whose modifications would invalidate the artifact.
+/// whose modifications would invalidate the artifact.
 /// Each pathspec can also be a negative match, i.e. `:!foo`. This matches changes outside
 /// the `foo` directory.
 /// See https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec
@@ -79,7 +79,7 @@ pub enum PathFreshness {
 /// In that case we simply take the latest upstream commit, because on CI there is no need to avoid
 /// redownloading.
 pub fn check_path_modifications(
-    git_dir: Option<&Path>,
+    git_dir: &Path,
     config: &GitConfig<'_>,
     target_paths: &[&str],
     ci_env: CiEnv,
@@ -109,7 +109,7 @@ pub fn check_path_modifications(
         // Do not include HEAD, as it is never an upstream commit
         // If we do not find an upstream commit in CI, something is seriously wrong.
         Some(
-            get_closest_upstream_commit(git_dir, config, ci_env)?
+            get_closest_upstream_commit(Some(git_dir), config, ci_env)?
                 .expect("No upstream commit was found on CI"),
         )
     } else {
@@ -124,7 +124,7 @@ pub fn check_path_modifications(
         )?;
         match upstream_with_modifications {
             Some(sha) => Some(sha),
-            None => get_closest_upstream_commit(git_dir, config, ci_env)?,
+            None => get_closest_upstream_commit(Some(git_dir), config, ci_env)?,
         }
     };
 
@@ -145,12 +145,9 @@ pub fn check_path_modifications(
 }
 
 /// Returns true if any of the passed `paths` have changed since the `base` commit.
-pub fn has_changed_since(git_dir: Option<&Path>, base: &str, paths: &[&str]) -> bool {
+pub fn has_changed_since(git_dir: &Path, base: &str, paths: &[&str]) -> bool {
     let mut git = Command::new("git");
-
-    if let Some(git_dir) = git_dir {
-        git.current_dir(git_dir);
-    }
+    git.current_dir(git_dir);
 
     git.args(["diff-index", "--quiet", base, "--"]).args(paths);
 
@@ -162,15 +159,12 @@ pub fn has_changed_since(git_dir: Option<&Path>, base: &str, paths: &[&str]) ->
 /// Returns the latest commit that modified `target_paths`, or `None` if no such commit was found.
 /// If `author` is `Some`, only considers commits made by that author.
 fn get_latest_commit_that_modified_files(
-    git_dir: Option<&Path>,
+    git_dir: &Path,
     target_paths: &[&str],
     author: &str,
 ) -> Result<Option<String>, String> {
     let mut git = Command::new("git");
-
-    if let Some(git_dir) = git_dir {
-        git.current_dir(git_dir);
-    }
+    git.current_dir(git_dir);
 
     git.args(["rev-list", "-n1", "--first-parent", "HEAD", "--author", author]);