Skip to content

Commit

Permalink
Fix benchsuite issue with newer versions of git (#15069)
Browse files Browse the repository at this point in the history
This fixes a problem introduced with git 2.48.0 where the benchsuite
would fail to run. The problem is that 2.48 changed the behavior so that
HEAD would get changed to follow the remote. crates.io-index's default
branch is "main". The benchsuite uses git to initialize the bare repo
with a HEAD of "refs/heads/master" (the default of
`init.defaultBranch`). Older versions of git would leave HEAD untouched,
but newer versions update it to "refs/heads/main" after fetching to
match the remote. This causes cargo to try to clone a branch called
"main" which is empty.

The solution here is to just force HEAD to be main, and use that as the
branch for our time-travelling snapshot.

Tested with git 2.47.0 and 2.48.1. Test is roughly:

```
rm -rf target/tmp/bench ; cargo test -p benchsuite --all-targets -- cargo && cargo test -p benchsuite --all-targets -- cargo`
```

(Run it twice to verify it can do an incremental fetch.)
  • Loading branch information
weihanglo authored Jan 15, 2025
2 parents 1b77ac6 + 5ac521c commit ac22fd3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions benches/benchsuite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,15 @@ impl Fixtures {
}
} else {
fs::create_dir_all(&index).unwrap();
git("init --bare");
// git 2.48.0 changed the behavior of setting HEAD when doing a
// fetch, so let's just force it to match
// crates.io-index-archive's default branch. This also accounts
// for users who may override init.defaultBranch.
git("init --bare --initial-branch=main");
git("remote add origin https://github.com/rust-lang/crates.io-index-archive");
}
git(&format!("fetch origin {}", CRATES_IO_COMMIT));
git("branch -f master FETCH_HEAD");
git("branch -f main FETCH_HEAD");
}

/// This unpacks the compressed workspace skeletons into tmp/workspaces.
Expand Down

0 comments on commit ac22fd3

Please sign in to comment.