Redact Git credentials from pyproject.toml (#6074)

## Summary

We retain them if you use `--raw-sources`, but otherwise they're
removed. We still respect them in the subsequent `uv.lock` via an
in-process store.

Closes #6056.
This commit is contained in:
Charlie Marsh
2024-08-13 21:30:02 -04:00
committed by GitHub
parent 92263108cc
commit 8fac63d4ce
10 changed files with 301 additions and 23 deletions
+15 -3
View File
@@ -1,6 +1,8 @@
//! Git support is derived from Cargo's implementation.
//! Cargo is dual-licensed under either Apache 2.0 or MIT, at the user's choice.
//! Source: <https://github.com/rust-lang/cargo/blob/23eb492cf920ce051abfc56bbaf838514dc8365c/src/cargo/sources/git/source.rs>
use std::borrow::Cow;
use std::path::{Path, PathBuf};
use anyhow::Result;
@@ -11,7 +13,7 @@ use url::Url;
use cache_key::{cache_digest, RepositoryUrl};
use crate::git::GitRemote;
use crate::{GitOid, GitSha, GitUrl};
use crate::{GitOid, GitSha, GitUrl, GIT_STORE};
/// A remote Git source that can be checked out locally.
pub struct GitSource {
@@ -52,11 +54,21 @@ impl GitSource {
/// Fetch the underlying Git repository at the given revision.
#[instrument(skip(self), fields(repository = %self.git.repository, rev = ?self.git.precise))]
pub fn fetch(self) -> Result<Fetch> {
// Compute the canonical URL for the repository.
let canonical = RepositoryUrl::new(&self.git.repository);
// The path to the repo, within the Git database.
let ident = cache_digest(&RepositoryUrl::new(&self.git.repository));
let ident = cache_digest(&canonical);
let db_path = self.cache.join("db").join(&ident);
let remote = GitRemote::new(&self.git.repository);
// Authenticate the URL, if necessary.
let remote = if let Some(credentials) = GIT_STORE.get(&canonical) {
Cow::Owned(credentials.apply(self.git.repository.clone()))
} else {
Cow::Borrowed(&self.git.repository)
};
let remote = GitRemote::new(&remote);
let (db, actual_rev, task) = match (self.git.precise, remote.db_at(&db_path).ok()) {
// If we have a locked revision, and we have a preexisting database
// which has that revision, then no update needs to happen.