Skip to content

Commit 17e3297

Browse files
committed
feat(test.rs): Lookup the commit with cat-file to avoid re-fetches
1 parent 452ebf5 commit 17e3297

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

build_system/src/test.rs

+24-11
Original file line numberDiff line numberDiff line change
@@ -511,17 +511,30 @@ fn setup_rustc(env: &mut Env, args: &TestArg) -> Result<PathBuf, String> {
511511
Some(commit_hash) => commit_hash,
512512
None => return Err("Couldn't retrieve rustc commit hash".to_string()),
513513
};
514-
run_command_with_output_and_env(
515-
&[
516-
&"git",
517-
&"fetch",
518-
&"https://github.com/rust-lang/rust.git",
519-
&rustc_commit.as_str(),
520-
&"--depth=1",
521-
],
522-
rust_dir,
523-
Some(env),
524-
)?;
514+
let has_commit = {
515+
if let Ok(ty) = run_command_with_env(
516+
&[&"git", &"cat-file", &"-t", &rustc_commit.as_str()],
517+
rust_dir,
518+
Some(env),
519+
) {
520+
String::from_utf8_lossy(&ty.stdout).to_string() == "commit"
521+
} else {
522+
false
523+
}
524+
};
525+
if !has_commit {
526+
run_command_with_output_and_env(
527+
&[
528+
&"git",
529+
&"fetch",
530+
&"https://github.com/rust-lang/rust.git",
531+
&rustc_commit.as_str(),
532+
&"--depth=1",
533+
],
534+
rust_dir,
535+
Some(env),
536+
)?
537+
};
525538
if rustc_commit != "unknown" {
526539
run_command_with_output_and_env(
527540
&[&"git", &"checkout", &rustc_commit],

0 commit comments

Comments
 (0)