mirror of
				https://github.com/astral-sh/uv.git
				synced 2025-11-03 21:23:54 +00:00 
			
		
		
		
	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:
		
							parent
							
								
									47f4114a1b
								
							
						
					
					
						commit
						18b095ce28
					
				
					 4 changed files with 9 additions and 9 deletions
				
			
		| 
						 | 
				
			
			@ -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)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -874,7 +874,7 @@ impl From<GitSourceKind> 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,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue