diff --git a/src/cargo/sources/git/utils.rs b/src/cargo/sources/git/utils.rs index 878d71f9ac6..d0668fc55a8 100644 --- a/src/cargo/sources/git/utils.rs +++ b/src/cargo/sources/git/utils.rs @@ -1007,7 +1007,7 @@ pub fn fetch( fast_path_rev = true; refspecs.push(format!("+{0}:refs/commit/{0}", oid_to_fetch)); } else if !matches!(shallow, gix::remote::fetch::Shallow::NoChange) - && rev.parse::().is_ok() + && rev_to_oid(rev).is_some() { // There is a specific commit to fetch and we will do so in shallow-mode only // to not disturb the previous logic. @@ -1569,8 +1569,10 @@ fn github_fast_path( if response_code == 304 { debug!("github fast path up-to-date"); Ok(FastPathRev::UpToDate) - } else if response_code == 200 { - let oid_to_fetch = str::from_utf8(&response_body)?.parse::()?; + } else if response_code == 200 + && let Some(oid_to_fetch) = rev_to_oid(str::from_utf8(&response_body)?) + { + // response expected to be a full hash hexstring (40 or 64 chars) debug!("github fast path fetch {oid_to_fetch}"); Ok(FastPathRev::NeedsFetch(oid_to_fetch)) } else {