Skip to content

Commit

Permalink
Don't include registry hashes for URL distributions (#7086)
Browse files Browse the repository at this point in the history
The opposite _can_ be true.
  • Loading branch information
charliermarsh authored Sep 5, 2024
1 parent 567e213 commit d91f7dd
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions crates/uv-resolver/src/resolution/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ impl ResolutionGraph {
// Map the package to a distribution.
let (dist, hashes, metadata) = Self::parse_dist(
name,
url,
url.as_ref(),
version,
pins,
diagnostics,
Expand Down Expand Up @@ -420,7 +420,7 @@ impl ResolutionGraph {

fn parse_dist(
name: &PackageName,
url: &Option<VerbatimParsedUrl>,
url: Option<&VerbatimParsedUrl>,
version: &Version,
pins: &FilePins,
diagnostics: &mut Vec<ResolutionDiagnostic>,
Expand All @@ -435,7 +435,8 @@ impl ResolutionGraph {
let version_id = VersionId::from_url(&url.verbatim);

// Extract the hashes.
let hashes = Self::get_hashes(&version_id, name, version, preferences, index);
let hashes =
Self::get_hashes(name, Some(url), &version_id, version, preferences, index);

// Extract the metadata.
let metadata = {
Expand Down Expand Up @@ -477,7 +478,7 @@ impl ResolutionGraph {
}

// Extract the hashes.
let hashes = Self::get_hashes(&version_id, name, version, preferences, index);
let hashes = Self::get_hashes(name, None, &version_id, version, preferences, index);

// Extract the metadata.
let metadata = {
Expand All @@ -499,8 +500,9 @@ impl ResolutionGraph {
/// Identify the hashes for the [`VersionId`], preserving any hashes that were provided by the
/// lockfile.
fn get_hashes(
version_id: &VersionId,
name: &PackageName,
url: Option<&VerbatimParsedUrl>,
version_id: &VersionId,
version: &Version,
preferences: &Preferences,
index: &InMemoryIndex,
Expand All @@ -524,18 +526,20 @@ impl ResolutionGraph {
}

// 3. Look for hashes from the registry, which are served at the package level.
if let Some(versions_response) = index.packages().get(name) {
if let VersionsResponse::Found(ref version_maps) = *versions_response {
if let Some(digests) = version_maps
.iter()
.find_map(|version_map| version_map.hashes(version))
.map(|mut digests| {
digests.sort_unstable();
digests
})
{
if !digests.is_empty() {
return digests;
if url.is_none() {
if let Some(versions_response) = index.packages().get(name) {
if let VersionsResponse::Found(ref version_maps) = *versions_response {
if let Some(digests) = version_maps
.iter()
.find_map(|version_map| version_map.hashes(version))
.map(|mut digests| {
digests.sort_unstable();
digests
})
{
if !digests.is_empty() {
return digests;
}
}
}
}
Expand Down

0 comments on commit d91f7dd

Please sign in to comment.