Add parsed URL to PubGrubPackage (#3426)

Avoid reparsing urls by storing the parsed parts across resolution on
`PubGrubPackage`.

Part 1 of #3408
This commit is contained in:
konsti 2024-05-14 02:55:21 +02:00 committed by GitHub
parent 5132c6a6e2
commit 0010954ca7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 194 additions and 79 deletions

View file

@ -155,15 +155,11 @@ pub(crate) async fn resolve_precise(
///
/// This method will only return precise URLs for URLs that have already been resolved via
/// [`resolve_precise`].
pub fn to_precise(url: &Url) -> Option<Url> {
let ParsedGitUrl { url, subdirectory } = ParsedGitUrl::try_from(url.clone()).ok()?;
pub fn git_url_to_precise(url: GitUrl) -> Option<GitUrl> {
let resolved_git_refs = RESOLVED_GIT_REFS.lock().unwrap();
let reference = RepositoryReference::new(&url);
let precise = resolved_git_refs.get(&reference)?;
Some(Url::from(ParsedGitUrl {
url: url.with_precise(*precise),
subdirectory,
}))
Some(url.with_precise(*precise))
}
/// Returns `true` if the URLs refer to the same Git commit.

View file

@ -2,7 +2,7 @@ pub use archive::Archive;
pub use distribution_database::{DistributionDatabase, HttpArchivePointer, LocalArchivePointer};
pub use download::LocalWheel;
pub use error::Error;
pub use git::{is_same_reference, to_precise};
pub use git::{git_url_to_precise, is_same_reference};
pub use index::{BuiltWheelIndex, RegistryWheelIndex};
use pypi_types::{HashDigest, Metadata23};
pub use reporter::Reporter;