mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 10:58:28 +00:00
Remove allocation in Git SHA truncation (#10801)
This commit is contained in:
parent
154fd6bd23
commit
44d2bfeb65
3 changed files with 11 additions and 6 deletions
|
@ -170,7 +170,7 @@ impl<'a> BuiltWheelIndex<'a> {
|
||||||
|
|
||||||
let cache_shard = self.cache.shard(
|
let cache_shard = self.cache.shard(
|
||||||
CacheBucket::SourceDistributions,
|
CacheBucket::SourceDistributions,
|
||||||
WheelCache::Git(&source_dist.url, &git_sha.to_short_string()).root(),
|
WheelCache::Git(&source_dist.url, git_sha.as_short_str()).root(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// If there are build settings, we need to scope to a cache shard.
|
// If there are build settings, we need to scope to a cache shard.
|
||||||
|
|
|
@ -1426,7 +1426,7 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
|
||||||
let git_sha = fetch.git().precise().expect("Exact commit after checkout");
|
let git_sha = fetch.git().precise().expect("Exact commit after checkout");
|
||||||
let cache_shard = self.build_context.cache().shard(
|
let cache_shard = self.build_context.cache().shard(
|
||||||
CacheBucket::SourceDistributions,
|
CacheBucket::SourceDistributions,
|
||||||
WheelCache::Git(resource.url, &git_sha.to_short_string()).root(),
|
WheelCache::Git(resource.url, git_sha.as_short_str()).root(),
|
||||||
);
|
);
|
||||||
let metadata_entry = cache_shard.entry(METADATA);
|
let metadata_entry = cache_shard.entry(METADATA);
|
||||||
|
|
||||||
|
@ -1564,7 +1564,7 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
|
||||||
let git_sha = fetch.git().precise().expect("Exact commit after checkout");
|
let git_sha = fetch.git().precise().expect("Exact commit after checkout");
|
||||||
let cache_shard = self.build_context.cache().shard(
|
let cache_shard = self.build_context.cache().shard(
|
||||||
CacheBucket::SourceDistributions,
|
CacheBucket::SourceDistributions,
|
||||||
WheelCache::Git(resource.url, &git_sha.to_short_string()).root(),
|
WheelCache::Git(resource.url, git_sha.as_short_str()).root(),
|
||||||
);
|
);
|
||||||
let metadata_entry = cache_shard.entry(METADATA);
|
let metadata_entry = cache_shard.entry(METADATA);
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,14 @@ use thiserror::Error;
|
||||||
pub struct GitSha(GitOid);
|
pub struct GitSha(GitOid);
|
||||||
|
|
||||||
impl GitSha {
|
impl GitSha {
|
||||||
/// Convert the SHA to a truncated representation, i.e., the first 16 characters of the SHA.
|
/// Return the Git SHA as a string.
|
||||||
pub fn to_short_string(&self) -> String {
|
pub fn as_str(&self) -> &str {
|
||||||
self.0.to_string()[0..16].to_string()
|
self.0.as_str()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return a truncated representation, i.e., the first 16 characters of the SHA.
|
||||||
|
pub fn as_short_str(&self) -> &str {
|
||||||
|
&self.0.as_str()[..16]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue