Make from_rev take an owned value (#3631)

## Summary

We always clone internally, and in most case we're already passing
`&String`.
This commit is contained in:
Charlie Marsh 2024-05-18 13:26:15 -04:00 committed by GitHub
parent 47f4114a1b
commit 18b095ce28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 9 additions and 9 deletions

View file

@ -54,17 +54,17 @@ enum RefspecStrategy {
impl GitReference { impl GitReference {
/// Creates a [`GitReference`] from an arbitrary revision string, which could represent a /// Creates a [`GitReference`] from an arbitrary revision string, which could represent a
/// branch, tag, commit, or named ref. /// 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/") { if rev.starts_with("refs/") {
Self::NamedRef(rev.to_owned()) Self::NamedRef(rev)
} else if looks_like_commit_hash(rev) { } else if looks_like_commit_hash(&rev) {
if rev.len() == 40 { if rev.len() == 40 {
Self::FullCommit(rev.to_owned()) Self::FullCommit(rev)
} else { } else {
Self::BranchOrTagOrCommit(rev.to_owned()) Self::BranchOrTagOrCommit(rev)
} }
} else { } else {
Self::BranchOrTag(rev.to_owned()) Self::BranchOrTag(rev)
} }
} }

View file

@ -76,7 +76,7 @@ impl TryFrom<Url> for GitUrl {
.rsplit_once('@') .rsplit_once('@')
.map(|(prefix, suffix)| (prefix.to_string(), suffix.to_string())) .map(|(prefix, suffix)| (prefix.to_string(), suffix.to_string()))
{ {
reference = GitReference::from_rev(&suffix); reference = GitReference::from_rev(suffix);
url.set_path(&prefix); url.set_path(&prefix);
} }

View file

@ -874,7 +874,7 @@ impl From<GitSourceKind> for GitReference {
match value { match value {
GitSourceKind::Branch(branch) => GitReference::Branch(branch), GitSourceKind::Branch(branch) => GitReference::Branch(branch),
GitSourceKind::Tag(tag) => GitReference::Tag(tag), GitSourceKind::Tag(tag) => GitReference::Tag(tag),
GitSourceKind::Rev(rev) => GitReference::from_rev(&rev), GitSourceKind::Rev(rev) => GitReference::from_rev(rev),
GitSourceKind::DefaultBranch => GitReference::DefaultBranch, GitSourceKind::DefaultBranch => GitReference::DefaultBranch,
} }
} }

View file

@ -53,7 +53,7 @@ pub(crate) fn url_to_precise(url: VerbatimParsedUrl) -> VerbatimParsedUrl {
.reference() .reference()
.as_str() .as_str()
.map_or(GitReference::DefaultBranch, |rev| { .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); let git_url = GitUrl::new(git_url.repository().clone(), lowered_git_ref);