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 {
/// 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)
}
}

View file

@ -76,7 +76,7 @@ impl TryFrom<Url> 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);
}