summaryrefslogtreecommitdiff
path: root/src/metadata/drop.rs
diff options
context:
space:
mode:
authorKim Altintop <kim@eagain.io>2023-03-29 13:20:08 +0200
committerKim Altintop <kim@eagain.io>2023-03-29 13:20:08 +0200
commita483cc97d56a770c4ccf91dfccf790a8c2d0c9fa (patch)
treeabe1fc1860def1b5f2cceae4c4da003c2f60705d /src/metadata/drop.rs
parenta4d2d6ac8acb34314fba166d5b85ff06c97f0ca3 (diff)
core: version each metadata type separately
It turns out to be preferable to be able to break one type without affecting the other. So instead of the global SpecVersion, use a separate FmtVersion for each type. For compatibility, keep supporting spec_version fields (until next major bump of the respective types' version). Signed-off-by: Kim Altintop <kim@eagain.io>
Diffstat (limited to 'src/metadata/drop.rs')
-rw-r--r--src/metadata/drop.rs54
1 files changed, 48 insertions, 6 deletions
diff --git a/src/metadata/drop.rs b/src/metadata/drop.rs
index d231712..1341f68 100644
--- a/src/metadata/drop.rs
+++ b/src/metadata/drop.rs
@@ -10,6 +10,7 @@ use std::{
},
io,
num::NonZeroUsize,
+ ops::Deref,
};
use log::warn;
@@ -32,7 +33,6 @@ use super::{
Mirrors,
Signature,
Signed,
- SpecVersion,
};
use crate::{
git::Refname,
@@ -40,6 +40,25 @@ use crate::{
str::Varchar,
};
+pub const FMT_VERSION: FmtVersion = FmtVersion(super::FmtVersion::new(0, 2, 0));
+
+#[derive(Clone, Eq, Ord, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)]
+pub struct FmtVersion(super::FmtVersion);
+
+impl Deref for FmtVersion {
+ type Target = super::FmtVersion;
+
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+
+impl Default for FmtVersion {
+ fn default() -> Self {
+ FMT_VERSION
+ }
+}
+
#[derive(Clone, serde::Serialize, serde::Deserialize)]
pub struct Roles {
pub root: Role,
@@ -83,9 +102,10 @@ pub struct Annotated {
pub type Verified = super::Verified<Drop>;
-#[derive(Clone, serde::Serialize, serde::Deserialize)]
+#[derive(Clone, serde::Deserialize)]
pub struct Drop {
- pub spec_version: SpecVersion,
+ #[serde(alias = "spec_version")]
+ pub fmt_version: FmtVersion,
#[serde(default = "Description::new")]
pub description: Description,
pub prev: Option<ContentHash>,
@@ -121,7 +141,7 @@ impl Drop {
{
use error::Verification::*;
- if !crate::SPEC_VERSION.is_compatible(&self.spec_version) {
+ if !FMT_VERSION.is_compatible(&self.fmt_version) {
return Err(IncompatibleSpecVersion);
}
@@ -153,7 +173,7 @@ impl Drop {
return Err(Expired);
}
}
- if !crate::SPEC_VERSION.is_compatible(&mirrors.signed.spec_version) {
+ if !FMT_VERSION.is_compatible(&mirrors.signed.fmt_version) {
return Err(IncompatibleSpecVersion);
}
@@ -177,7 +197,7 @@ impl Drop {
return Err(Expired);
}
}
- if !crate::SPEC_VERSION.is_compatible(&alt.signed.spec_version) {
+ if !FMT_VERSION.is_compatible(&alt.signed.fmt_version) {
return Err(IncompatibleSpecVersion);
}
@@ -203,6 +223,28 @@ impl<'a> From<&'a Drop> for Cow<'a, Drop> {
}
}
+impl serde::Serialize for Drop {
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
+ S: serde::Serializer,
+ {
+ use serde::ser::SerializeStruct;
+
+ let mut s = serializer.serialize_struct("Drop", 5)?;
+ let version_field = if self.fmt_version < FMT_VERSION {
+ "spec_version"
+ } else {
+ "fmt_version"
+ };
+ s.serialize_field(version_field, &self.fmt_version)?;
+ s.serialize_field("description", &self.description)?;
+ s.serialize_field("prev", &self.prev)?;
+ s.serialize_field("roles", &self.roles)?;
+ s.serialize_field("custom", &self.custom)?;
+ s.end()
+ }
+}
+
mod verify {
use super::*;