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:
Charlie Marsh 2024-07-31 12:16:39 -04:00 committed by GitHub
parent bf8934e3e4
commit f266fb711c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 341 additions and 56 deletions

View file

@ -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),

View file

@ -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.