mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 19:08:04 +00:00
Skip GitHub fast path when full commit is already known (#10800)
## Summary If we have a `GitReference::FullCommit`, we don't need to go to GitHub to resolve the SHA. We already have it!
This commit is contained in:
parent
9552c0a8db
commit
29226b074b
4 changed files with 29 additions and 20 deletions
|
@ -74,11 +74,7 @@ impl GitReference {
|
|||
if rev.starts_with("refs/") {
|
||||
Self::NamedRef(rev)
|
||||
} else if looks_like_commit_hash(&rev) {
|
||||
if rev.len() == 40 {
|
||||
Self::FullCommit(rev)
|
||||
} else {
|
||||
Self::BranchOrTagOrCommit(rev)
|
||||
}
|
||||
Self::BranchOrTagOrCommit(rev)
|
||||
} else {
|
||||
Self::BranchOrTag(rev)
|
||||
}
|
||||
|
@ -729,7 +725,7 @@ fn github_fast_path(
|
|||
GitReference::BranchOrTag(branch_or_tag) => branch_or_tag,
|
||||
GitReference::DefaultBranch => "HEAD",
|
||||
GitReference::NamedRef(rev) => rev,
|
||||
GitReference::FullCommit(rev) | GitReference::BranchOrTagOrCommit(rev) => {
|
||||
GitReference::BranchOrTagOrCommit(rev) => {
|
||||
// `revparse_single` (used by `resolve`) is the only way to turn
|
||||
// short hash -> long hash, but it also parses other things,
|
||||
// like branch and tag names, which might coincidentally be
|
||||
|
@ -754,12 +750,21 @@ fn github_fast_path(
|
|||
}
|
||||
rev
|
||||
}
|
||||
};
|
||||
GitReference::FullCommit(rev) => {
|
||||
debug!("Skipping GitHub fast path; full commit hash provided: {rev}");
|
||||
|
||||
// TODO(charlie): If we _know_ that we have a full commit SHA, there's no need to perform this
|
||||
// request. We can just return `FastPathRev::NeedsFetch`. However, we need to audit all uses of
|
||||
// `GitReference::FullCommit` to ensure that we _know_ it's a SHA, as opposed to (e.g.) a Git
|
||||
// tag that just "looks like" a commit (i.e., a tag composed of 40 hex characters).
|
||||
let rev = GitOid::from_str(rev)?;
|
||||
if let Some(ref local_object) = local_object {
|
||||
if rev == *local_object {
|
||||
return Ok(FastPathRev::UpToDate);
|
||||
}
|
||||
}
|
||||
|
||||
// If we know the reference is a full commit hash, we can just return it without
|
||||
// querying GitHub.
|
||||
return Ok(FastPathRev::NeedsFetch(rev));
|
||||
}
|
||||
};
|
||||
|
||||
let url = format!("https://api.github.com/repos/{owner}/{repo}/commits/{github_branch_name}");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue