Skip to content

Commit

Permalink
types: support multi-format deserialization for HgId
Browse files Browse the repository at this point in the history
Summary:
Switch from the default tuple deserialization which only understands the tuple
format, to "bytes" deserialization, which understands not only the existing
"tuple" format (therefore compatible with old data), but also "bytes" and "hex"
formats (for CBOR).

This will unblock us from switching to bytes serialization in the future.

Note: This is a breaking change for mincode serialization. Mincode + HgId users
(zsotre, metalog) have switched to explicit tuple serialization so they don't use
the default deserializaiton and remain unaffected.

Reviewed By: kulshrax

Differential Revision: D23966995

fbshipit-source-id: 83dd53f57bd4e6098de054f46a1d47f8b48133d0
  • Loading branch information
quark-zju authored and facebook-github-bot committed Oct 6, 2020
1 parent 9c5d209 commit ab88771
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions eden/scm/lib/types/src/hgid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{
};

use anyhow::Result;
use serde_derive::{Deserialize, Serialize};
use serde::{de::Deserializer, Deserialize, Serialize};
use thiserror::Error;

use crate::parents::Parents;
Expand Down Expand Up @@ -70,19 +70,15 @@ struct HgIdError(String);
///
/// [1]: Depends on actual data of `HgId`.
/// [2]: JSON only supports utf-8 data.
#[derive(
Clone,
Copy,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
Serialize,
Deserialize
)]
#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct HgId([u8; HgId::len()]);

impl<'de> Deserialize<'de> for HgId {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
crate::serde_with::hgid::bytes::deserialize(deserializer)
}
}

/// The nullid (0x00) is used throughout Mercurial to represent "None".
/// (For example, a commit will have a nullid p2, if it has no second parent).
pub const NULL_ID: HgId = HgId([0; HgId::len()]);
Expand Down

0 comments on commit ab88771

Please sign in to comment.