From 18b095ce28635ec69637238296be5e932a480018 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sat, 18 May 2024 13:26:15 -0400 Subject: [PATCH] Make `from_rev` take an owned value (#3631) ## Summary We always clone internally, and in most case we're already passing `&String`. --- crates/uv-git/src/git.rs | 12 ++++++------ crates/uv-git/src/lib.rs | 2 +- crates/uv-resolver/src/lock.rs | 2 +- crates/uv-resolver/src/redirect.rs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/uv-git/src/git.rs b/crates/uv-git/src/git.rs index f6002e696..5bc4b8de8 100644 --- a/crates/uv-git/src/git.rs +++ b/crates/uv-git/src/git.rs @@ -54,17 +54,17 @@ enum RefspecStrategy { impl GitReference { /// Creates a [`GitReference`] from an arbitrary revision string, which could represent a /// branch, tag, commit, or named ref. - pub fn from_rev(rev: &str) -> Self { + pub fn from_rev(rev: String) -> Self { if rev.starts_with("refs/") { - Self::NamedRef(rev.to_owned()) - } else if looks_like_commit_hash(rev) { + Self::NamedRef(rev) + } else if looks_like_commit_hash(&rev) { if rev.len() == 40 { - Self::FullCommit(rev.to_owned()) + Self::FullCommit(rev) } else { - Self::BranchOrTagOrCommit(rev.to_owned()) + Self::BranchOrTagOrCommit(rev) } } else { - Self::BranchOrTag(rev.to_owned()) + Self::BranchOrTag(rev) } } diff --git a/crates/uv-git/src/lib.rs b/crates/uv-git/src/lib.rs index dd4168a70..bc7f8d9dc 100644 --- a/crates/uv-git/src/lib.rs +++ b/crates/uv-git/src/lib.rs @@ -76,7 +76,7 @@ impl TryFrom for GitUrl { .rsplit_once('@') .map(|(prefix, suffix)| (prefix.to_string(), suffix.to_string())) { - reference = GitReference::from_rev(&suffix); + reference = GitReference::from_rev(suffix); url.set_path(&prefix); } diff --git a/crates/uv-resolver/src/lock.rs b/crates/uv-resolver/src/lock.rs index f20d73b7a..5cdf84035 100644 --- a/crates/uv-resolver/src/lock.rs +++ b/crates/uv-resolver/src/lock.rs @@ -874,7 +874,7 @@ impl From for GitReference { match value { GitSourceKind::Branch(branch) => GitReference::Branch(branch), GitSourceKind::Tag(tag) => GitReference::Tag(tag), - GitSourceKind::Rev(rev) => GitReference::from_rev(&rev), + GitSourceKind::Rev(rev) => GitReference::from_rev(rev), GitSourceKind::DefaultBranch => GitReference::DefaultBranch, } } diff --git a/crates/uv-resolver/src/redirect.rs b/crates/uv-resolver/src/redirect.rs index 30864bc3e..548377fb0 100644 --- a/crates/uv-resolver/src/redirect.rs +++ b/crates/uv-resolver/src/redirect.rs @@ -53,7 +53,7 @@ pub(crate) fn url_to_precise(url: VerbatimParsedUrl) -> VerbatimParsedUrl { .reference() .as_str() .map_or(GitReference::DefaultBranch, |rev| { - GitReference::from_rev(rev) + GitReference::from_rev(rev.to_string()) }); let git_url = GitUrl::new(git_url.repository().clone(), lowered_git_ref);