mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-24 13:43:45 +00:00
Use full requirement when serializing receipt (#5494)
## Summary The current receipt doesn't capture quite enough information. For example, it doesn't differentiate between editable and non-editable requirements. This PR instead uses the full `Requirement` type. I think we should use a custom representation like we do in the lockfile, but I'm just using the default representation to demonstrate the idea.
This commit is contained in:
parent
bf8934e3e4
commit
f266fb711c
12 changed files with 341 additions and 56 deletions
|
@ -20,7 +20,9 @@ use crate::sha::GitOid;
|
|||
const CHECKOUT_READY_LOCK: &str = ".ok";
|
||||
|
||||
/// A reference to commit or commit-ish.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
#[derive(
|
||||
Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Serialize, serde::Deserialize,
|
||||
)]
|
||||
pub enum GitReference {
|
||||
/// A specific branch.
|
||||
Branch(String),
|
||||
|
|
|
@ -26,7 +26,7 @@ impl From<GitOid> for GitSha {
|
|||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for GitSha {
|
||||
impl Display for GitSha {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
|
@ -40,6 +40,25 @@ impl FromStr for GitSha {
|
|||
}
|
||||
}
|
||||
|
||||
impl serde::Serialize for GitSha {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
self.0.as_str().serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> serde::Deserialize<'de> for GitSha {
|
||||
fn deserialize<D>(deserializer: D) -> Result<GitSha, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
let value = String::deserialize(deserializer)?;
|
||||
GitSha::from_str(&value).map_err(serde::de::Error::custom)
|
||||
}
|
||||
}
|
||||
|
||||
/// Unique identity of any Git object (commit, tree, blob, tag).
|
||||
///
|
||||
/// Note this type does not validate whether the input is a valid hash.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue