Add Git resolver in lieu of static hash map (#3954)

## Summary

This PR removes the static resolver map:

```rust
static RESOLVED_GIT_REFS: Lazy<Mutex<FxHashMap<RepositoryReference, GitSha>>> =
    Lazy::new(Mutex::default);
```

With a `GitResolver` struct that we now pass around on the
`BuildContext`. There should be no behavior changes here; it's purely an
internal refactor with an eye towards making it cleaner for us to
"pre-populate" the list of resolved SHAs.
This commit is contained in:
Charlie Marsh 2024-05-31 22:44:42 -04:00 committed by GitHub
parent a0652921fc
commit b7d77c04cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
31 changed files with 475 additions and 384 deletions

View file

@ -36,8 +36,8 @@ use uv_types::{BuildContext, SourceBuildTrait};
use crate::distribution_database::ManagedClient;
use crate::error::Error;
use crate::git::{fetch_git_archive, resolve_precise};
use crate::metadata::{ArchiveMetadata, Metadata};
use crate::reporter::Facade;
use crate::source::built_wheel_metadata::BuiltWheelMetadata;
use crate::source::revision::Revision;
use crate::Reporter;
@ -1040,12 +1040,15 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
}
// Resolve to a precise Git SHA.
let url = if let Some(url) = resolve_precise(
resource.git,
self.build_context.cache(),
self.reporter.as_ref(),
)
.await?
let url = if let Some(url) = self
.build_context
.git()
.resolve(
resource.git,
self.build_context.cache().bucket(CacheBucket::Git),
self.reporter.clone().map(Facade::from),
)
.await?
{
Cow::Owned(url)
} else {
@ -1053,8 +1056,15 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
};
// Fetch the Git repository.
let fetch =
fetch_git_archive(&url, self.build_context.cache(), self.reporter.as_ref()).await?;
let fetch = self
.build_context
.git()
.fetch(
&url,
self.build_context.cache().bucket(CacheBucket::Git),
self.reporter.clone().map(Facade::from),
)
.await?;
let git_sha = fetch.git().precise().expect("Exact commit after checkout");
let cache_shard = self.build_context.cache().shard(
@ -1114,12 +1124,15 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
}
// Resolve to a precise Git SHA.
let url = if let Some(url) = resolve_precise(
resource.git,
self.build_context.cache(),
self.reporter.as_ref(),
)
.await?
let url = if let Some(url) = self
.build_context
.git()
.resolve(
resource.git,
self.build_context.cache().bucket(CacheBucket::Git),
self.reporter.clone().map(Facade::from),
)
.await?
{
Cow::Owned(url)
} else {
@ -1127,8 +1140,15 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
};
// Fetch the Git repository.
let fetch =
fetch_git_archive(&url, self.build_context.cache(), self.reporter.as_ref()).await?;
let fetch = self
.build_context
.git()
.fetch(
&url,
self.build_context.cache().bucket(CacheBucket::Git),
self.reporter.clone().map(Facade::from),
)
.await?;
let git_sha = fetch.git().precise().expect("Exact commit after checkout");
let cache_shard = self.build_context.cache().shard(