Use auto_wire on all api objects where it's possible

Summary:
This diff uses the helper proc macro added on the previous diff to simplify the code for dozens of api objects.

Over 1000 lines deleted :)

Examples of structs that couldn't be migrated:
- Wire structs that didn't rename the fields to numbers. (e.g. WireHistoryRequest) (would need some extra migration)
- enums  (not currently supported by the proc macro)
- Wire structs that didn't map directly to their non-wire counterparts (e.g. WireSnapshotState)

I added some comments with possible future improvements, but didn't pursue them right now as they are significantly less useful than this diff itself, which covers most of the cases.

Reviewed By: ahornby

Differential Revision: D31057140

fbshipit-source-id: 88a867ba2cdfedf6a96a8ca3718508073822b962
This commit is contained in:
Yan Soares Couto 2021-10-05 16:30:05 -07:00 committed by Facebook GitHub Bot
parent 1e461b5028
commit 0cd8e64c51
24 changed files with 417 additions and 1696 deletions

View File

@ -13,6 +13,15 @@ use syn::spanned::Spanned;
use syn::*;
/// Derive a default implementation for a wire type for this type
// TODO: Future improvements
// - Support enums
// - Need to add the unknown variant, implementations are slightly different
// - Support fields that do not implement Default on Api obj
// - add "no_default" attribute to field. Wire impl will wrap it in Option,
// and fail when deserializing if it's not present
// - Support generics in type
// - Might be possible to make it work with some adaptation, at least for
// simple "wrapper" types that just have one generic T.
#[proc_macro_attribute]
pub fn auto_wire(
attr: proc_macro::TokenStream,

View File

@ -9,9 +9,10 @@ use std::num::NonZeroU64;
use crate::{AnyFileContentId, UploadToken};
#[cfg(any(test, feature = "for-tests"))]
use quickcheck::Arbitrary;
use quickcheck::{Arbitrary, Gen};
#[cfg(any(test, feature = "for-tests"))]
use serde_derive::{Deserialize, Serialize};
use type_macros::auto_wire;
use types::HgId;
blake2_hash!(BonsaiChangesetId);
@ -31,15 +32,21 @@ impl Default for AnyId {
}
}
#[auto_wire]
#[derive(Clone, Default, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct LookupRequest {
#[id(1)]
pub id: AnyId,
#[id(2)]
pub bubble_id: Option<NonZeroU64>,
}
#[derive(Clone, Default, Debug, Serialize, Deserialize, Eq, PartialEq)]
#[auto_wire]
#[derive(Clone, Serialize, Deserialize, Default, Debug, Eq, PartialEq)]
pub struct LookupResponse {
#[id(1)]
pub index: usize,
#[id(2)]
pub token: Option<UploadToken>,
}
@ -69,3 +76,13 @@ impl Arbitrary for LookupRequest {
}
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for LookupResponse {
fn arbitrary(g: &mut Gen) -> Self {
Self {
index: Arbitrary::arbitrary(g),
token: Arbitrary::arbitrary(g),
}
}
}

View File

@ -8,11 +8,14 @@
#[cfg(any(test, feature = "for-tests"))]
use quickcheck::Arbitrary;
use serde_derive::{Deserialize, Serialize};
use type_macros::auto_wire;
use types::hgid::HgId;
#[auto_wire]
#[derive(Clone, Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct BookmarkRequest {
#[id(0)]
pub bookmarks: Vec<String>,
}
@ -25,10 +28,13 @@ impl Arbitrary for BookmarkRequest {
}
}
#[auto_wire]
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
#[derive(Serialize, Deserialize)]
pub struct BookmarkEntry {
#[id(1)]
pub bookmark: String,
#[id(2)]
pub hgid: Option<HgId>,
}

View File

@ -13,6 +13,7 @@ use quickcheck::{Arbitrary, Gen};
use serde_derive::{Deserialize, Serialize};
use std::iter;
use std::num::NonZeroU64;
use type_macros::auto_wire;
use types::{hgid::HgId, Parents, RepoPathBuf};
use crate::{BonsaiChangesetId, FileType, ServerError, UploadToken};
@ -31,24 +32,33 @@ use crate::{BonsaiChangesetId, FileType, ServerError, UploadToken};
/// count: 2,
/// }
/// => [b, a]
#[auto_wire]
#[derive(Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive(Serialize, Deserialize)]
pub struct CommitLocationToHashRequest {
#[id(1)]
pub location: Location<HgId>,
#[id(2)]
pub count: u64,
}
#[auto_wire]
#[derive(Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive(Serialize, Deserialize)]
pub struct CommitLocationToHashResponse {
#[id(1)]
pub location: Location<HgId>,
#[id(2)]
pub count: u64,
#[id(3)]
pub hgids: Vec<HgId>,
}
#[auto_wire]
#[derive(Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive(Serialize, Deserialize)]
pub struct CommitLocationToHashRequestBatch {
#[id(1)]
pub requests: Vec<CommitLocationToHashRequest>,
}
@ -107,17 +117,23 @@ pub struct CommitKnownResponse {
pub known: Result<bool, ServerError>,
}
#[auto_wire]
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[derive(Serialize)]
pub struct CommitGraphEntry {
#[id(1)]
pub hgid: HgId,
#[id(2)]
pub parents: Vec<HgId>,
}
#[auto_wire]
#[derive(Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive(Serialize, Deserialize)]
pub struct CommitGraphRequest {
#[id(1)]
pub common: Vec<HgId>,
#[id(2)]
pub heads: Vec<HgId>,
}
@ -246,53 +262,145 @@ impl Arbitrary for CommitHashLookupResponse {
}
}
#[auto_wire]
#[derive(Clone, Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct Extra {
#[id(1)]
pub key: Vec<u8>,
#[id(2)]
pub value: Vec<u8>,
}
#[auto_wire]
#[derive(Clone, Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct HgChangesetContent {
#[id(1)]
pub parents: Parents,
#[id(2)]
pub manifestid: HgId,
#[id(3)]
pub user: Vec<u8>,
#[id(4)]
pub time: i64,
#[id(5)]
pub tz: i32,
#[id(6)]
pub extras: Vec<Extra>,
#[id(7)]
pub files: Vec<RepoPathBuf>,
#[id(8)]
pub message: Vec<u8>,
}
#[auto_wire]
#[derive(Clone, Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct UploadHgChangeset {
#[id(1)]
pub node_id: HgId,
#[id(2)]
pub changeset_content: HgChangesetContent,
}
#[auto_wire]
#[derive(Clone, Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct HgMutationEntryContent {
#[id(1)]
pub successor: HgId,
#[id(2)]
pub predecessors: Vec<HgId>,
#[id(3)]
pub split: Vec<HgId>,
#[id(4)]
pub op: String,
#[id(5)]
pub user: Vec<u8>,
#[id(6)]
pub time: i64,
#[id(7)]
pub tz: i32,
#[id(8)]
pub extras: Vec<Extra>,
}
#[auto_wire]
#[derive(Clone, Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct UploadHgChangesetsRequest {
/// list of changesets to upload, changesets must be sorted topologically (use dag.sort)
#[id(1)]
pub changesets: Vec<UploadHgChangeset>,
/// list of mutation entries for the uploading changesets
#[id(2)]
pub mutations: Vec<HgMutationEntryContent>,
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for HgMutationEntryContent {
fn arbitrary(g: &mut Gen) -> Self {
Self {
successor: Arbitrary::arbitrary(g),
predecessors: Arbitrary::arbitrary(g),
split: Arbitrary::arbitrary(g),
op: Arbitrary::arbitrary(g),
user: Arbitrary::arbitrary(g),
time: Arbitrary::arbitrary(g),
tz: Arbitrary::arbitrary(g),
extras: Arbitrary::arbitrary(g),
}
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for UploadHgChangesetsRequest {
fn arbitrary(g: &mut Gen) -> Self {
Self {
changesets: Arbitrary::arbitrary(g),
mutations: Arbitrary::arbitrary(g),
}
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for UploadHgChangeset {
fn arbitrary(g: &mut Gen) -> Self {
Self {
node_id: Arbitrary::arbitrary(g),
changeset_content: Arbitrary::arbitrary(g),
}
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for HgChangesetContent {
fn arbitrary(g: &mut Gen) -> Self {
Self {
parents: Arbitrary::arbitrary(g),
manifestid: Arbitrary::arbitrary(g),
user: Arbitrary::arbitrary(g),
time: Arbitrary::arbitrary(g),
tz: Arbitrary::arbitrary(g),
extras: Arbitrary::arbitrary(g),
files: Arbitrary::arbitrary(g),
message: Arbitrary::arbitrary(g),
}
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for Extra {
fn arbitrary(g: &mut Gen) -> Self {
Self {
key: Arbitrary::arbitrary(g),
value: Arbitrary::arbitrary(g),
}
}
}
#[auto_wire]
#[derive(Clone, Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct BonsaiExtra {
#[id(1)]
pub key: String,
#[id(2)]
pub value: Vec<u8>,
}
@ -323,12 +431,39 @@ pub struct BonsaiChangesetContent {
pub is_snapshot: bool,
}
#[auto_wire]
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct UploadBonsaiChangesetRequest {
/// changeset to upload
#[id(1)]
pub changeset: BonsaiChangesetContent,
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for BonsaiChangesetContent {
fn arbitrary(g: &mut Gen) -> Self {
Self {
hg_parents: Arbitrary::arbitrary(g),
author: Arbitrary::arbitrary(g),
time: Arbitrary::arbitrary(g),
tz: Arbitrary::arbitrary(g),
extra: Arbitrary::arbitrary(g),
file_changes: Arbitrary::arbitrary(g),
message: Arbitrary::arbitrary(g),
is_snapshot: Arbitrary::arbitrary(g),
}
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for UploadBonsaiChangesetRequest {
fn arbitrary(g: &mut Gen) -> Self {
Self {
changeset: Arbitrary::arbitrary(g),
}
}
}
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct SnapshotRawFiles {
/// Absolute root of the repository, where all files are
@ -355,14 +490,19 @@ pub struct SnapshotRawData {
pub author: String,
}
#[auto_wire]
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct FetchSnapshotRequest {
#[id(1)]
pub cs_id: BonsaiChangesetId,
}
#[auto_wire]
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct FetchSnapshotResponse {
#[id(1)]
pub hg_parents: Parents,
#[id(2)]
pub file_changes: Vec<(RepoPathBuf, BonsaiFileChange)>,
}
@ -371,6 +511,7 @@ pub struct UploadSnapshotResponse {
pub changeset_token: UploadToken,
}
#[auto_wire]
#[derive(Clone, Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct EphemeralPrepareRequest {}
@ -395,6 +536,16 @@ impl Arbitrary for EphemeralPrepareResponse {
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for BonsaiExtra {
fn arbitrary(g: &mut Gen) -> Self {
Self {
key: Arbitrary::arbitrary(g),
value: Arbitrary::arbitrary(g),
}
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for BonsaiFileChange {
fn arbitrary(g: &mut Gen) -> Self {

View File

@ -7,6 +7,7 @@
use serde_derive::{Deserialize, Serialize};
use type_macros::auto_wire;
use types::{hgid::HgId, path::RepoPathBuf};
/// Struct reprenting the arguments to a "gettreepack" operation, which
@ -19,11 +20,16 @@ use types::{hgid::HgId, path::RepoPathBuf};
/// containing the keys of the desired tree nodes.
///
/// In all cases, trees will be returned in a `TreeResponse`.
#[auto_wire]
#[derive(Clone, Debug, Eq, Deserialize, Serialize, PartialEq)]
pub struct CompleteTreeRequest {
#[id(0)]
pub rootdir: RepoPathBuf,
#[id(1)]
pub mfnodes: Vec<HgId>,
#[id(2)]
pub basemfnodes: Vec<HgId>,
#[id(3)]
pub depth: Option<usize>,
}

View File

@ -211,9 +211,12 @@ impl Arbitrary for FileEntry {
}
}
#[derive(Clone, Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[auto_wire]
#[derive(Clone, Default, Debug, Eq, PartialEq)]
pub struct FileAttributes {
#[id(0)]
pub content: bool,
#[id(1)]
pub aux_data: bool,
}
@ -227,9 +230,12 @@ impl Arbitrary for FileAttributes {
}
}
#[derive(Clone, Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[auto_wire]
#[derive(Clone, Default, Debug, Eq, PartialEq)]
pub struct FileSpec {
#[id(0)]
pub key: Key,
#[id(1)]
pub attrs: FileAttributes,
}
@ -243,10 +249,13 @@ impl Arbitrary for FileSpec {
}
}
#[derive(Clone, Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[auto_wire]
#[derive(Clone, Default, Debug, Eq, PartialEq)]
pub struct FileRequest {
// TODO(meyer): Deprecate keys field
#[id(0)]
pub keys: Vec<Key>,
#[id(1)]
pub reqs: Vec<FileSpec>,
}
@ -283,22 +292,32 @@ impl Arbitrary for FileContent {
}
}
#[derive(Clone, Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[auto_wire]
#[derive(Clone, Default, Debug, Eq, PartialEq)]
pub struct HgFilenodeData {
#[id(0)]
pub node_id: HgId,
#[id(1)]
pub parents: Parents,
#[id(2)]
pub file_content_upload_token: UploadToken,
#[id(3)]
pub metadata: Vec<u8>,
}
#[derive(Clone, Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[auto_wire]
#[derive(Clone, Default, Debug, Eq, PartialEq)]
pub struct UploadHgFilenodeRequest {
#[id(0)]
pub data: HgFilenodeData,
}
#[derive(Clone, Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[auto_wire]
#[derive(Clone, Default, Serialize, Deserialize, Debug, Eq, PartialEq)]
pub struct UploadTokensResponse {
#[id(1)]
pub index: usize,
#[id(2)]
pub token: UploadToken,
}

View File

@ -13,50 +13,83 @@ use std::str::FromStr;
#[cfg(any(test, feature = "for-tests"))]
use quickcheck::Arbitrary;
use serde_derive::{Deserialize, Serialize};
use type_macros::auto_wire;
/// Directory entry metadata
#[auto_wire]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct DirectoryMetadata {
#[id(0)]
pub fsnode_id: Option<FsnodeId>,
#[id(1)]
pub simple_format_sha1: Option<Sha1>,
#[id(2)]
pub simple_format_sha256: Option<Sha256>,
#[id(3)]
pub child_files_count: Option<u64>,
#[id(4)]
pub child_files_total_size: Option<u64>,
#[id(5)]
pub child_dirs_count: Option<u64>,
#[id(6)]
pub descendant_files_count: Option<u64>,
#[id(7)]
pub descendant_files_total_size: Option<u64>,
}
#[auto_wire]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct DirectoryMetadataRequest {
#[id(0)]
pub with_fsnode_id: bool,
#[id(1)]
pub with_simple_format_sha1: bool,
#[id(2)]
pub with_simple_format_sha256: bool,
#[id(3)]
pub with_child_files_count: bool,
#[id(4)]
pub with_child_files_total_size: bool,
#[id(5)]
pub with_child_dirs_count: bool,
#[id(6)]
pub with_descendant_files_count: bool,
#[id(7)]
pub with_descendant_files_total_size: bool,
}
/// File entry metadata
#[auto_wire]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct FileMetadata {
#[id(0)]
pub revisionstore_flags: Option<u64>,
#[id(1)]
pub content_id: Option<ContentId>,
#[id(2)]
pub file_type: Option<FileType>,
#[id(3)]
pub size: Option<u64>,
#[id(4)]
pub content_sha1: Option<Sha1>,
#[id(5)]
pub content_sha256: Option<Sha256>,
}
#[auto_wire]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct FileMetadataRequest {
#[id(0)]
pub with_revisionstore_flags: bool,
#[id(1)]
pub with_content_id: bool,
#[id(2)]
pub with_file_type: bool,
#[id(3)]
pub with_size: bool,
#[id(4)]
pub with_content_sha1: bool,
#[id(5)]
pub with_content_sha256: bool,
}

View File

@ -9,12 +9,15 @@ use std::num::NonZeroU64;
use crate::AnyId;
#[cfg(any(test, feature = "for-tests"))]
use quickcheck::Arbitrary;
use quickcheck::{Arbitrary, Gen};
use serde_derive::{Deserialize, Serialize};
use type_macros::auto_wire;
#[auto_wire]
/// Token metadata for file content token type.
#[derive(Clone, Default, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct FileContentTokenMetadata {
#[id(1)]
pub content_size: u64,
}
@ -31,22 +34,31 @@ impl From<FileContentTokenMetadata> for UploadTokenMetadata {
}
}
#[auto_wire]
#[derive(Clone, Default, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct UploadTokenData {
#[id(1)]
pub id: AnyId,
#[id(3)]
pub bubble_id: Option<NonZeroU64>,
#[id(2)]
pub metadata: Option<UploadTokenMetadata>,
// TODO: add other data (like expiration time).
}
#[auto_wire]
#[derive(Clone, Default, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct UploadTokenSignature {
#[id(1)]
pub signature: Vec<u8>,
}
#[auto_wire]
#[derive(Clone, Default, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct UploadToken {
#[id(1)]
pub data: UploadTokenData,
#[id(2)]
pub signature: UploadTokenSignature,
}
@ -104,6 +116,22 @@ impl Arbitrary for UploadTokenData {
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for UploadTokenMetadata {
fn arbitrary(g: &mut Gen) -> Self {
Self::FileContentTokenMetadata(Arbitrary::arbitrary(g))
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for FileContentTokenMetadata {
fn arbitrary(g: &mut Gen) -> Self {
Self {
content_size: Arbitrary::arbitrary(g),
}
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for UploadTokenSignature {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {

View File

@ -15,6 +15,7 @@ use quickcheck::{Arbitrary, Gen};
use types::{hgid::HgId, key::Key, parents::Parents};
use crate::{DirectoryMetadata, EdenApiServerError, FileMetadata, InvalidHgId, UploadToken};
use type_macros::auto_wire;
#[derive(Debug, Error)]
pub enum TreeError {
@ -260,21 +261,30 @@ impl Arbitrary for TreeRequest {
}
}
#[auto_wire]
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
pub struct UploadTreeEntry {
#[id(0)]
pub node_id: HgId,
#[id(1)]
pub data: Vec<u8>,
#[id(2)]
pub parents: Parents,
}
#[auto_wire]
#[derive(Clone, Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct UploadTreeRequest {
#[id(0)]
pub entry: UploadTreeEntry,
}
#[auto_wire]
#[derive(Clone, Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct UploadTreeResponse {
#[id(0)]
pub index: usize,
#[id(1)]
pub token: UploadToken,
}
@ -287,3 +297,23 @@ impl Arbitrary for UploadTreeResponse {
}
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for UploadTreeEntry {
fn arbitrary(g: &mut Gen) -> Self {
Self {
node_id: Arbitrary::arbitrary(g),
data: Arbitrary::arbitrary(g),
parents: Arbitrary::arbitrary(g),
}
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for UploadTreeRequest {
fn arbitrary(g: &mut Gen) -> Self {
Self {
entry: Arbitrary::arbitrary(g),
}
}
}

View File

@ -5,18 +5,15 @@
* GNU General Public License version 2.
*/
use std::num::NonZeroU64;
#[cfg(any(test, feature = "for-tests"))]
use quickcheck::Arbitrary;
#[cfg(any(test, feature = "for-tests"))]
use serde_derive::{Deserialize, Serialize};
use crate::anyid::{AnyId, BonsaiChangesetId, LookupRequest, LookupResponse};
use crate::wire::{
is_default, ToApi, ToWire, WireAnyFileContentId, WireHgId, WireToApiConversionError,
WireUploadToken,
};
use crate::anyid::{AnyId, BonsaiChangesetId};
use crate::wire::{ToApi, ToWire, WireAnyFileContentId, WireHgId, WireToApiConversionError};
pub use crate::anyid::{WireLookupRequest, WireLookupResponse};
wire_hash! {
wire => WireBonsaiChangesetId,
@ -87,70 +84,6 @@ impl ToApi for WireAnyId {
}
}
#[derive(Clone, Default, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireLookupRequest {
#[serde(rename = "1", default, skip_serializing_if = "is_default")]
pub id: WireAnyId,
#[serde(rename = "2", default, skip_serializing_if = "is_default")]
pub bubble_id: Option<NonZeroU64>,
}
impl ToWire for LookupRequest {
type Wire = WireLookupRequest;
fn to_wire(self) -> Self::Wire {
WireLookupRequest {
id: self.id.to_wire(),
bubble_id: self.bubble_id,
}
}
}
impl ToApi for WireLookupRequest {
type Api = LookupRequest;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(LookupRequest {
id: self.id.to_api()?,
bubble_id: self.bubble_id,
})
}
}
#[derive(Clone, Default, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireLookupResponse {
#[serde(rename = "1")]
pub index: usize,
#[serde(rename = "2")]
pub token: Option<WireUploadToken>,
}
impl ToWire for LookupResponse {
type Wire = WireLookupResponse;
fn to_wire(self) -> Self::Wire {
WireLookupResponse {
index: self.index,
token: self.token.to_wire(),
}
}
}
impl ToApi for WireLookupResponse {
type Api = LookupResponse;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(LookupResponse {
index: self.index,
token: self.token.to_api()?,
})
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireAnyId {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
@ -168,21 +101,11 @@ impl Arbitrary for WireAnyId {
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireLookupRequest {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
id: Arbitrary::arbitrary(g),
bubble_id: Arbitrary::arbitrary(g),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::wire::tests::auto_wire_tests;
auto_wire_tests!(WireAnyId, WireLookupRequest);
auto_wire_tests!(WireAnyId, WireLookupRequest, WireLookupResponse);
}

View File

@ -5,86 +5,7 @@
* GNU General Public License version 2.
*/
#[cfg(any(test, feature = "for-tests"))]
use quickcheck::Arbitrary;
use serde_derive::{Deserialize, Serialize};
use crate::bookmark::{BookmarkEntry, BookmarkRequest};
use crate::wire::{is_default, ToApi, ToWire, WireHgId, WireToApiConversionError};
#[derive(Clone, Default, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireBookmarkRequest {
#[serde(rename = "0", default, skip_serializing_if = "is_default")]
pub bookmarks: Vec<String>,
}
impl ToWire for BookmarkRequest {
type Wire = WireBookmarkRequest;
fn to_wire(self) -> Self::Wire {
WireBookmarkRequest {
bookmarks: self.bookmarks,
}
}
}
impl ToApi for WireBookmarkRequest {
type Api = BookmarkRequest;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(BookmarkRequest {
bookmarks: self.bookmarks,
})
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireBookmarkRequest {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
BookmarkRequest::arbitrary(g).to_wire()
}
}
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireBookmarkEntry {
#[serde(rename = "1")]
pub bookmark: String,
#[serde(rename = "2")]
pub hgid: Option<WireHgId>,
}
impl ToWire for BookmarkEntry {
type Wire = WireBookmarkEntry;
fn to_wire(self) -> Self::Wire {
Self::Wire {
bookmark: self.bookmark,
hgid: self.hgid.to_wire(),
}
}
}
impl ToApi for WireBookmarkEntry {
type Api = BookmarkEntry;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
let api = Self::Api {
bookmark: self.bookmark,
hgid: self.hgid.to_api()?,
};
Ok(api)
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireBookmarkEntry {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
BookmarkEntry::arbitrary(g).to_wire()
}
}
pub use crate::bookmark::{WireBookmarkEntry, WireBookmarkRequest};
#[cfg(test)]
mod tests {

View File

@ -6,7 +6,7 @@
*/
#[cfg(any(test, feature = "for-tests"))]
use quickcheck::{Arbitrary, Gen};
use quickcheck::Arbitrary;
use serde_derive::{Deserialize, Serialize};
use std::num::NonZeroU64;
@ -14,19 +14,23 @@ use dag_types::Location;
use types::HgId;
use crate::commit::{
BonsaiChangesetContent, BonsaiExtra, BonsaiFileChange, CommitGraphEntry, CommitGraphRequest,
CommitHashLookupRequest, CommitHashLookupResponse, CommitHashToLocationRequestBatch,
CommitHashToLocationResponse, CommitLocationToHashRequest, CommitLocationToHashRequestBatch,
CommitLocationToHashResponse, EphemeralPrepareRequest, EphemeralPrepareResponse, Extra,
FetchSnapshotRequest, FetchSnapshotResponse, HgChangesetContent, HgMutationEntryContent,
UploadBonsaiChangesetRequest, UploadHgChangeset, UploadHgChangesetsRequest,
BonsaiChangesetContent, BonsaiFileChange, CommitHashLookupRequest, CommitHashLookupResponse,
CommitHashToLocationRequestBatch, CommitHashToLocationResponse, EphemeralPrepareResponse,
};
use crate::wire::{
anyid::WireBonsaiChangesetId, is_default, ToApi, ToWire, WireFileType, WireHgId, WireParents,
WireRepoPathBuf, WireResult, WireToApiConversionError, WireUploadToken,
is_default, ToApi, ToWire, WireFileType, WireHgId, WireParents, WireRepoPathBuf, WireResult,
WireToApiConversionError, WireUploadToken,
};
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub use crate::commit::{
WireBonsaiExtra, WireCommitGraphEntry, WireCommitGraphRequest, WireCommitLocationToHashRequest,
WireCommitLocationToHashRequestBatch, WireCommitLocationToHashResponse,
WireEphemeralPrepareRequest, WireExtra, WireFetchSnapshotRequest, WireFetchSnapshotResponse,
WireHgChangesetContent, WireHgMutationEntryContent, WireUploadBonsaiChangesetRequest,
WireUploadHgChangeset, WireUploadHgChangesetsRequest,
};
#[derive(Clone, Default, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireCommitLocation {
#[serde(rename = "1")]
pub descendant: WireHgId,
@ -34,46 +38,6 @@ pub struct WireCommitLocation {
pub distance: u64,
}
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireCommitLocationToHashRequest {
#[serde(rename = "1")]
pub location: WireCommitLocation,
#[serde(rename = "2")]
pub count: u64,
}
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireCommitLocationToHashResponse {
#[serde(rename = "1")]
pub location: WireCommitLocation,
#[serde(rename = "2")]
pub count: u64,
#[serde(rename = "3")]
pub hgids: Vec<WireHgId>,
}
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireCommitLocationToHashRequestBatch {
#[serde(rename = "1")]
pub requests: Vec<WireCommitLocationToHashRequest>,
}
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireCommitGraphRequest {
#[serde(rename = "1")]
pub common: Vec<WireHgId>,
#[serde(rename = "2")]
pub heads: Vec<WireHgId>,
}
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireCommitGraphEntry {
#[serde(rename = "1")]
pub hgid: WireHgId,
#[serde(rename = "2")]
pub parents: Vec<WireHgId>,
}
impl ToWire for Location<HgId> {
type Wire = WireCommitLocation;
@ -105,154 +69,6 @@ impl Arbitrary for WireCommitLocation {
}
}
impl ToWire for CommitLocationToHashRequest {
type Wire = WireCommitLocationToHashRequest;
fn to_wire(self) -> Self::Wire {
Self::Wire {
location: self.location.to_wire(),
count: self.count,
}
}
}
impl ToApi for WireCommitLocationToHashRequest {
type Api = CommitLocationToHashRequest;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
let api = Self::Api {
location: self.location.to_api()?,
count: self.count,
};
Ok(api)
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireCommitLocationToHashRequest {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
CommitLocationToHashRequest::arbitrary(g).to_wire()
}
}
impl ToWire for CommitLocationToHashResponse {
type Wire = WireCommitLocationToHashResponse;
fn to_wire(self) -> Self::Wire {
Self::Wire {
location: self.location.to_wire(),
count: self.count,
hgids: self.hgids.to_wire(),
}
}
}
impl ToApi for WireCommitLocationToHashResponse {
type Api = CommitLocationToHashResponse;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
let api = Self::Api {
location: self.location.to_api()?,
count: self.count,
hgids: self.hgids.to_api()?,
};
Ok(api)
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireCommitLocationToHashResponse {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
CommitLocationToHashResponse::arbitrary(g).to_wire()
}
}
impl ToWire for CommitLocationToHashRequestBatch {
type Wire = WireCommitLocationToHashRequestBatch;
fn to_wire(self) -> Self::Wire {
Self::Wire {
requests: self.requests.to_wire(),
}
}
}
impl ToApi for WireCommitLocationToHashRequestBatch {
type Api = CommitLocationToHashRequestBatch;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
let api = Self::Api {
requests: self.requests.to_api()?,
};
Ok(api)
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireCommitLocationToHashRequestBatch {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
CommitLocationToHashRequestBatch::arbitrary(g).to_wire()
}
}
impl ToWire for CommitGraphRequest {
type Wire = WireCommitGraphRequest;
fn to_wire(self) -> Self::Wire {
Self::Wire {
common: self.common.to_wire(),
heads: self.heads.to_wire(),
}
}
}
impl ToApi for WireCommitGraphRequest {
type Api = CommitGraphRequest;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
let api = Self::Api {
common: self.common.to_api()?,
heads: self.heads.to_api()?,
};
Ok(api)
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireCommitGraphRequest {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
CommitGraphRequest::arbitrary(g).to_wire()
}
}
impl ToWire for CommitGraphEntry {
type Wire = WireCommitGraphEntry;
fn to_wire(self) -> Self::Wire {
Self::Wire {
hgid: self.hgid.to_wire(),
parents: self.parents.to_wire(),
}
}
}
impl ToApi for WireCommitGraphEntry {
type Api = CommitGraphEntry;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
let api = Self::Api {
hgid: self.hgid.to_api()?,
parents: self.parents.to_api()?,
};
Ok(api)
}
}
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireCommitHashToLocationRequestBatch {
#[serde(rename = "1")]
@ -449,237 +265,6 @@ impl Arbitrary for WireCommitHashLookupResponse {
}
}
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireExtra {
#[serde(rename = "1")]
pub key: Vec<u8>,
#[serde(rename = "2")]
pub value: Vec<u8>,
}
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireHgChangesetContent {
#[serde(rename = "1")]
pub parents: WireParents,
#[serde(rename = "2")]
pub manifestid: WireHgId,
#[serde(rename = "3")]
pub user: Vec<u8>,
#[serde(rename = "4")]
pub time: i64,
#[serde(rename = "5")]
pub tz: i32,
#[serde(rename = "6")]
pub extras: Vec<WireExtra>,
#[serde(rename = "7")]
pub files: Vec<WireRepoPathBuf>,
#[serde(rename = "8")]
pub message: Vec<u8>,
}
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireUploadHgChangeset {
#[serde(rename = "1")]
pub node_id: WireHgId,
#[serde(rename = "2")]
pub changeset_content: WireHgChangesetContent,
}
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireHgMutationEntryContent {
#[serde(rename = "1")]
pub successor: WireHgId,
#[serde(rename = "2")]
pub predecessors: Vec<WireHgId>,
#[serde(rename = "3")]
pub split: Vec<WireHgId>,
#[serde(rename = "4")]
pub op: String,
#[serde(rename = "5")]
pub user: Vec<u8>,
#[serde(rename = "6")]
pub time: i64,
#[serde(rename = "7")]
pub tz: i32,
#[serde(rename = "8")]
pub extras: Vec<WireExtra>,
}
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireUploadHgChangesetsRequest {
/// list of changesets to upload, changesets must be sorted topologically (use dag.sort)
#[serde(rename = "1")]
pub changesets: Vec<WireUploadHgChangeset>,
/// list of mutation entries for the uploading changesets
#[serde(rename = "2")]
pub mutations: Vec<WireHgMutationEntryContent>,
}
impl ToWire for Extra {
type Wire = WireExtra;
fn to_wire(self) -> Self::Wire {
WireExtra {
key: self.key.to_wire(),
value: self.value.to_wire(),
}
}
}
impl ToApi for WireExtra {
type Api = Extra;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(Extra {
key: self.key.to_api()?,
value: self.value.to_api()?,
})
}
}
impl ToWire for HgChangesetContent {
type Wire = WireHgChangesetContent;
fn to_wire(self) -> Self::Wire {
WireHgChangesetContent {
parents: self.parents.to_wire(),
manifestid: self.manifestid.to_wire(),
user: self.user.to_wire(),
time: self.time,
tz: self.tz,
extras: self.extras.to_wire(),
files: self.files.to_wire(),
message: self.message.to_wire(),
}
}
}
impl ToApi for WireHgChangesetContent {
type Api = HgChangesetContent;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(HgChangesetContent {
parents: self.parents.to_api()?,
manifestid: self.manifestid.to_api()?,
user: self.user.to_api()?,
time: self.time,
tz: self.tz,
extras: self.extras.to_api()?,
files: self.files.to_api()?,
message: self.message.to_api()?,
})
}
}
impl ToWire for HgMutationEntryContent {
type Wire = WireHgMutationEntryContent;
fn to_wire(self) -> Self::Wire {
WireHgMutationEntryContent {
successor: self.successor.to_wire(),
predecessors: self.predecessors.to_wire(),
split: self.split.to_wire(),
op: self.op,
user: self.user.to_wire(),
time: self.time,
tz: self.tz,
extras: self.extras.to_wire(),
}
}
}
impl ToApi for WireHgMutationEntryContent {
type Api = HgMutationEntryContent;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(HgMutationEntryContent {
successor: self.successor.to_api()?,
predecessors: self.predecessors.to_api()?,
split: self.split.to_api()?,
op: self.op,
user: self.user.to_api()?,
time: self.time,
tz: self.tz,
extras: self.extras.to_api()?,
})
}
}
impl ToWire for UploadHgChangeset {
type Wire = WireUploadHgChangeset;
fn to_wire(self) -> Self::Wire {
WireUploadHgChangeset {
node_id: self.node_id.to_wire(),
changeset_content: self.changeset_content.to_wire(),
}
}
}
impl ToApi for WireUploadHgChangeset {
type Api = UploadHgChangeset;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(UploadHgChangeset {
node_id: self.node_id.to_api()?,
changeset_content: self.changeset_content.to_api()?,
})
}
}
impl ToWire for UploadHgChangesetsRequest {
type Wire = WireUploadHgChangesetsRequest;
fn to_wire(self) -> Self::Wire {
WireUploadHgChangesetsRequest {
changesets: self.changesets.to_wire(),
mutations: self.mutations.to_wire(),
}
}
}
impl ToApi for WireUploadHgChangesetsRequest {
type Api = UploadHgChangesetsRequest;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(UploadHgChangesetsRequest {
changesets: self.changesets.to_api()?,
mutations: self.mutations.to_api()?,
})
}
}
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireBonsaiExtra {
#[serde(rename = "1")]
pub key: String,
#[serde(rename = "2")]
pub value: Vec<u8>,
}
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub enum WireBonsaiFileChange {
#[serde(rename = "1")]
@ -701,7 +286,7 @@ pub enum WireBonsaiFileChange {
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireSnapshotState {}
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
#[derive(Clone, Default, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireBonsaiChangesetContent {
#[serde(rename = "1")]
pub hg_parents: WireParents,
@ -728,24 +313,6 @@ pub struct WireBonsaiChangesetContent {
pub snapshot_state: Option<WireSnapshotState>,
}
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireUploadBonsaiChangesetRequest {
/// changeset to upload
#[serde(rename = "1")]
pub changeset: WireBonsaiChangesetContent,
}
impl ToWire for BonsaiExtra {
type Wire = WireBonsaiExtra;
fn to_wire(self) -> Self::Wire {
WireBonsaiExtra {
key: self.key,
value: self.value,
}
}
}
impl ToWire for BonsaiFileChange {
type Wire = WireBonsaiFileChange;
fn to_wire(self) -> Self::Wire {
@ -785,18 +352,6 @@ impl ToWire for BonsaiChangesetContent {
}
}
impl ToApi for WireBonsaiExtra {
type Api = BonsaiExtra;
type Error = std::convert::Infallible;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(BonsaiExtra {
key: self.key,
value: self.value,
})
}
}
impl ToApi for WireBonsaiFileChange {
type Api = BonsaiFileChange;
type Error = WireToApiConversionError;
@ -844,60 +399,12 @@ impl ToApi for WireBonsaiChangesetContent {
}
}
impl ToWire for UploadBonsaiChangesetRequest {
type Wire = WireUploadBonsaiChangesetRequest;
fn to_wire(self) -> Self::Wire {
WireUploadBonsaiChangesetRequest {
changeset: self.changeset.to_wire(),
}
}
}
impl ToApi for WireUploadBonsaiChangesetRequest {
type Api = UploadBonsaiChangesetRequest;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(UploadBonsaiChangesetRequest {
changeset: self.changeset.to_api()?,
})
}
}
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireEphemeralPrepareRequest {}
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireEphemeralPrepareResponse {
#[serde(rename = "1")]
pub bubble_id: Option<NonZeroU64>,
}
impl ToWire for EphemeralPrepareRequest {
type Wire = WireEphemeralPrepareRequest;
fn to_wire(self) -> Self::Wire {
Self::Wire {}
}
}
impl ToApi for WireEphemeralPrepareRequest {
type Api = EphemeralPrepareRequest;
type Error = std::convert::Infallible;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(Self::Api {})
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireEphemeralPrepareRequest {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
EphemeralPrepareRequest::arbitrary(g).to_wire()
}
}
impl ToWire for EphemeralPrepareResponse {
type Wire = WireEphemeralPrepareResponse;
@ -928,78 +435,6 @@ impl Arbitrary for WireEphemeralPrepareResponse {
}
}
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct WireFetchSnapshotRequest {
#[serde(rename = "1")]
pub cs_id: WireBonsaiChangesetId,
}
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct WireFetchSnapshotResponse {
#[serde(rename = "1", default, skip_serializing_if = "is_default")]
pub hg_parents: WireParents,
#[serde(rename = "2")]
pub file_changes: Vec<(WireRepoPathBuf, WireBonsaiFileChange)>,
}
impl ToWire for FetchSnapshotRequest {
type Wire = WireFetchSnapshotRequest;
fn to_wire(self) -> Self::Wire {
WireFetchSnapshotRequest {
cs_id: self.cs_id.to_wire(),
}
}
}
impl ToApi for WireFetchSnapshotRequest {
type Api = FetchSnapshotRequest;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(FetchSnapshotRequest {
cs_id: self.cs_id.to_api()?,
})
}
}
impl ToWire for FetchSnapshotResponse {
type Wire = WireFetchSnapshotResponse;
fn to_wire(self) -> Self::Wire {
WireFetchSnapshotResponse {
hg_parents: self.hg_parents.to_wire(),
file_changes: self.file_changes.to_wire(),
}
}
}
impl ToApi for WireFetchSnapshotResponse {
type Api = FetchSnapshotResponse;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(FetchSnapshotResponse {
hg_parents: self.hg_parents.to_api()?,
file_changes: self.file_changes.to_api()?,
})
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireFetchSnapshotRequest {
fn arbitrary(g: &mut Gen) -> Self {
FetchSnapshotRequest::arbitrary(g).to_wire()
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireFetchSnapshotResponse {
fn arbitrary(g: &mut Gen) -> Self {
FetchSnapshotResponse::arbitrary(g).to_wire()
}
}
#[cfg(test)]
mod tests {
use super::*;
@ -1018,6 +453,8 @@ mod tests {
WireEphemeralPrepareRequest,
WireEphemeralPrepareResponse,
WireCommitGraphRequest,
WireUploadHgChangeset,
WireUploadHgChangesetsRequest,
WireFetchSnapshotRequest,
WireFetchSnapshotResponse,
);

View File

@ -5,79 +5,7 @@
* GNU General Public License version 2.
*/
use serde_derive::{Deserialize, Serialize};
use crate::{
wire::{is_default, ToApi, ToWire, WireHgId, WireRepoPathBuf, WireToApiConversionError},
CompleteTreeRequest,
};
/// Struct reprenting the arguments to a "gettreepack" operation, which
/// is used by Mercurial to prefetch treemanifests. This struct is intended
/// to provide a way to support requests compatible with Mercurial's existing
/// gettreepack wire protocol command.
///
/// In the future, we'd like to migrate away from requesting trees in this way.
/// In general, trees can be requested from the API server using a `TreeRequest`
/// containing the keys of the desired tree nodes.
///
/// In all cases, trees will be returned in a `TreeResponse`.
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireCompleteTreeRequest {
#[serde(rename = "0", default, skip_serializing_if = "is_default")]
pub rootdir: WireRepoPathBuf,
#[serde(rename = "1", default, skip_serializing_if = "is_default")]
pub mfnodes: Vec<WireHgId>,
#[serde(rename = "2", default, skip_serializing_if = "is_default")]
pub basemfnodes: Vec<WireHgId>,
#[serde(rename = "3", default, skip_serializing_if = "is_default")]
pub depth: Option<usize>,
}
impl ToWire for CompleteTreeRequest {
type Wire = WireCompleteTreeRequest;
fn to_wire(self) -> Self::Wire {
WireCompleteTreeRequest {
rootdir: self.rootdir.to_wire(),
mfnodes: self.mfnodes.to_wire(),
basemfnodes: self.basemfnodes.to_wire(),
depth: self.depth,
}
}
}
impl ToApi for WireCompleteTreeRequest {
type Api = CompleteTreeRequest;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(CompleteTreeRequest {
rootdir: self.rootdir.to_api()?,
mfnodes: self.mfnodes.to_api()?,
basemfnodes: self.basemfnodes.to_api()?,
depth: self.depth,
})
}
}
#[cfg(any(test, feature = "for-tests"))]
use quickcheck::Arbitrary;
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireCompleteTreeRequest {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
rootdir: Arbitrary::arbitrary(g),
mfnodes: Arbitrary::arbitrary(g),
basemfnodes: Arbitrary::arbitrary(g),
depth: Arbitrary::arbitrary(g),
}
}
}
pub use crate::complete_tree::WireCompleteTreeRequest;
#[cfg(test)]
mod tests {

View File

@ -7,20 +7,22 @@
use bytes::Bytes;
#[cfg(any(test, feature = "for-tests"))]
use quickcheck::{Arbitrary, Gen};
use quickcheck::Arbitrary;
use serde_derive::{Deserialize, Serialize};
use crate::{
file::{
FileAttributes, FileContent, FileEntry, FileRequest, FileSpec, HgFilenodeData,
UploadHgFilenodeRequest, UploadTokensResponse,
},
file::{FileContent, FileEntry},
wire::{
is_default, ToApi, ToWire, WireHgId, WireKey, WireParents, WireRevisionstoreMetadata,
WireToApiConversionError, WireUploadToken,
is_default, ToApi, ToWire, WireKey, WireParents, WireRevisionstoreMetadata,
WireToApiConversionError,
},
};
pub use crate::file::{
WireFileAttributes, WireFileAuxData, WireFileRequest, WireFileSpec, WireHgFilenodeData,
WireUploadHgFilenodeRequest, WireUploadTokensResponse,
};
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
pub struct WireFileEntry {
#[serde(rename = "0", default, skip_serializing_if = "is_default")]
@ -85,225 +87,6 @@ impl ToApi for WireFileEntry {
}
}
pub use crate::file::WireFileAuxData;
#[derive(Clone, Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct WireFileAttributes {
#[serde(rename = "0", default, skip_serializing_if = "is_default")]
pub content: bool,
#[serde(rename = "1", default, skip_serializing_if = "is_default")]
pub aux_data: bool,
}
impl ToWire for FileAttributes {
type Wire = WireFileAttributes;
fn to_wire(self) -> Self::Wire {
WireFileAttributes {
content: self.content,
aux_data: self.aux_data,
}
}
}
impl ToApi for WireFileAttributes {
type Api = FileAttributes;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(FileAttributes {
content: self.content,
aux_data: self.aux_data,
})
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireFileAttributes {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
content: Arbitrary::arbitrary(g),
aux_data: Arbitrary::arbitrary(g),
}
}
}
#[derive(Clone, Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct WireFileSpec {
#[serde(rename = "0", default, skip_serializing_if = "is_default")]
pub key: WireKey,
#[serde(rename = "1", default, skip_serializing_if = "is_default")]
pub attrs: WireFileAttributes,
}
impl ToWire for FileSpec {
type Wire = WireFileSpec;
fn to_wire(self) -> Self::Wire {
WireFileSpec {
key: self.key.to_wire(),
attrs: self.attrs.to_wire(),
}
}
}
impl ToApi for WireFileSpec {
type Api = FileSpec;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(FileSpec {
key: self.key.to_api()?,
attrs: self.attrs.to_api()?,
})
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireFileSpec {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
key: Arbitrary::arbitrary(g),
attrs: Arbitrary::arbitrary(g),
}
}
}
#[derive(Clone, Default, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireFileRequest {
#[serde(rename = "0", default, skip_serializing_if = "is_default")]
pub keys: Vec<WireKey>,
#[serde(rename = "1", default, skip_serializing_if = "is_default")]
pub reqs: Vec<WireFileSpec>,
}
impl ToWire for FileRequest {
type Wire = WireFileRequest;
fn to_wire(self) -> Self::Wire {
WireFileRequest {
keys: self.keys.to_wire(),
reqs: self.reqs.to_wire(),
}
}
}
impl ToApi for WireFileRequest {
type Api = FileRequest;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(FileRequest {
keys: self.keys.to_api()?,
reqs: self.reqs.to_api()?,
})
}
}
#[derive(Clone, Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct WireHgFilenodeData {
#[serde(rename = "0", default, skip_serializing_if = "is_default")]
pub node_id: WireHgId,
#[serde(rename = "1", default, skip_serializing_if = "is_default")]
pub parents: WireParents,
#[serde(rename = "2", default, skip_serializing_if = "is_default")]
pub file_content_upload_token: WireUploadToken,
#[serde(rename = "3", default, skip_serializing_if = "is_default")]
pub metadata: Vec<u8>,
}
#[derive(Clone, Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct WireUploadHgFilenodeRequest {
#[serde(rename = "0", default, skip_serializing_if = "is_default")]
pub data: WireHgFilenodeData,
}
#[derive(Clone, Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct WireUploadTokensResponse {
#[serde(rename = "1")]
pub index: usize,
#[serde(rename = "2", default, skip_serializing_if = "is_default")]
pub token: WireUploadToken,
}
impl ToWire for HgFilenodeData {
type Wire = WireHgFilenodeData;
fn to_wire(self) -> Self::Wire {
WireHgFilenodeData {
node_id: self.node_id.to_wire(),
parents: self.parents.to_wire(),
file_content_upload_token: self.file_content_upload_token.to_wire(),
metadata: self.metadata.to_wire(),
}
}
}
impl ToApi for WireHgFilenodeData {
type Api = HgFilenodeData;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(HgFilenodeData {
node_id: self.node_id.to_api()?,
parents: self.parents.to_api()?,
file_content_upload_token: self.file_content_upload_token.to_api()?,
metadata: self.metadata.to_api()?,
})
}
}
impl ToWire for UploadTokensResponse {
type Wire = WireUploadTokensResponse;
fn to_wire(self) -> Self::Wire {
WireUploadTokensResponse {
index: self.index,
token: self.token.to_wire(),
}
}
}
impl ToApi for WireUploadTokensResponse {
type Api = UploadTokensResponse;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(UploadTokensResponse {
index: self.index,
token: self.token.to_api()?,
})
}
}
impl ToWire for UploadHgFilenodeRequest {
type Wire = WireUploadHgFilenodeRequest;
fn to_wire(self) -> Self::Wire {
WireUploadHgFilenodeRequest {
data: self.data.to_wire(),
}
}
}
impl ToApi for WireUploadHgFilenodeRequest {
type Api = UploadHgFilenodeRequest;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(UploadHgFilenodeRequest {
data: self.data.to_api()?,
})
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireFileEntry {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
@ -318,47 +101,6 @@ impl Arbitrary for WireFileEntry {
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireFileRequest {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
keys: Arbitrary::arbitrary(g),
reqs: Arbitrary::arbitrary(g),
}
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireUploadHgFilenodeRequest {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
data: Arbitrary::arbitrary(g),
}
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireHgFilenodeData {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
node_id: Arbitrary::arbitrary(g),
parents: Arbitrary::arbitrary(g),
file_content_upload_token: Arbitrary::arbitrary(g),
metadata: Arbitrary::arbitrary(g),
}
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireUploadTokensResponse {
fn arbitrary(g: &mut Gen) -> Self {
Self {
index: Arbitrary::arbitrary(g),
token: Arbitrary::arbitrary(g),
}
}
}
#[cfg(test)]
mod tests {
use super::*;

View File

@ -16,6 +16,7 @@ use crate::{
HistoryRequest, HistoryResponseChunk, WireHistoryEntry,
};
// TODO: attributes in this file aren't renamed to 0, 1, ...
#[derive(Clone, Default, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct WireHistoryRequest {
keys: Vec<WireKey>,

View File

@ -5,247 +5,18 @@
* GNU General Public License version 2.
*/
use std::convert::Infallible;
#[cfg(any(test, feature = "for-tests"))]
use quickcheck::Arbitrary;
use serde_derive::{Deserialize, Serialize};
use crate::{
wire::is_default, AnyFileContentId, ContentId, DirectoryMetadata, DirectoryMetadataRequest,
FileMetadata, FileMetadataRequest, FileType, FsnodeId, Sha1, Sha256, ToApi, ToWire,
AnyFileContentId, ContentId, FileType, FsnodeId, Sha1, Sha256, ToApi, ToWire,
WireToApiConversionError,
};
/// Directory entry metadata
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct WireDirectoryMetadata {
#[serde(rename = "0", default, skip_serializing_if = "is_default")]
fsnode_id: Option<WireFsnodeId>,
#[serde(rename = "1", default, skip_serializing_if = "is_default")]
simple_format_sha1: Option<WireSha1>,
#[serde(rename = "2", default, skip_serializing_if = "is_default")]
simple_format_sha256: Option<WireSha256>,
#[serde(rename = "3", default, skip_serializing_if = "is_default")]
child_files_count: Option<u64>,
#[serde(rename = "4", default, skip_serializing_if = "is_default")]
child_files_total_size: Option<u64>,
#[serde(rename = "5", default, skip_serializing_if = "is_default")]
child_dirs_count: Option<u64>,
#[serde(rename = "6", default, skip_serializing_if = "is_default")]
descendant_files_count: Option<u64>,
#[serde(rename = "7", default, skip_serializing_if = "is_default")]
descendant_files_total_size: Option<u64>,
}
impl ToWire for DirectoryMetadata {
type Wire = WireDirectoryMetadata;
fn to_wire(self) -> Self::Wire {
WireDirectoryMetadata {
fsnode_id: self.fsnode_id.to_wire(),
simple_format_sha1: self.simple_format_sha1.to_wire(),
simple_format_sha256: self.simple_format_sha256.to_wire(),
child_files_count: self.child_files_count,
child_files_total_size: self.child_files_total_size,
child_dirs_count: self.child_dirs_count,
descendant_files_count: self.descendant_files_count,
descendant_files_total_size: self.descendant_files_total_size,
}
}
}
impl ToApi for WireDirectoryMetadata {
type Api = DirectoryMetadata;
type Error = Infallible;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(DirectoryMetadata {
fsnode_id: self.fsnode_id.to_api()?,
simple_format_sha1: self.simple_format_sha1.to_api()?,
simple_format_sha256: self.simple_format_sha256.to_api()?,
child_files_count: self.child_files_count,
child_files_total_size: self.child_files_total_size,
child_dirs_count: self.child_dirs_count,
descendant_files_count: self.descendant_files_count,
descendant_files_total_size: self.descendant_files_total_size,
})
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct WireDirectoryMetadataRequest {
#[serde(rename = "0", default, skip_serializing_if = "is_default")]
with_fsnode_id: bool,
#[serde(rename = "1", default, skip_serializing_if = "is_default")]
with_simple_format_sha1: bool,
#[serde(rename = "2", default, skip_serializing_if = "is_default")]
with_simple_format_sha256: bool,
#[serde(rename = "3", default, skip_serializing_if = "is_default")]
with_child_files_count: bool,
#[serde(rename = "4", default, skip_serializing_if = "is_default")]
with_child_files_total_size: bool,
#[serde(rename = "5", default, skip_serializing_if = "is_default")]
with_child_dirs_count: bool,
#[serde(rename = "6", default, skip_serializing_if = "is_default")]
with_descendant_files_count: bool,
#[serde(rename = "7", default, skip_serializing_if = "is_default")]
with_descendant_files_total_size: bool,
}
impl ToWire for DirectoryMetadataRequest {
type Wire = WireDirectoryMetadataRequest;
fn to_wire(self) -> Self::Wire {
WireDirectoryMetadataRequest {
with_fsnode_id: self.with_fsnode_id,
with_simple_format_sha1: self.with_simple_format_sha1,
with_simple_format_sha256: self.with_simple_format_sha256,
with_child_files_count: self.with_child_files_count,
with_child_files_total_size: self.with_child_files_total_size,
with_child_dirs_count: self.with_child_dirs_count,
with_descendant_files_count: self.with_descendant_files_count,
with_descendant_files_total_size: self.with_descendant_files_total_size,
}
}
}
impl ToApi for WireDirectoryMetadataRequest {
type Api = DirectoryMetadataRequest;
type Error = Infallible;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(DirectoryMetadataRequest {
with_fsnode_id: self.with_fsnode_id,
with_simple_format_sha1: self.with_simple_format_sha1,
with_simple_format_sha256: self.with_simple_format_sha256,
with_child_files_count: self.with_child_files_count,
with_child_files_total_size: self.with_child_files_total_size,
with_child_dirs_count: self.with_child_dirs_count,
with_descendant_files_count: self.with_descendant_files_count,
with_descendant_files_total_size: self.with_descendant_files_total_size,
})
}
}
/// File entry metadata
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct WireFileMetadata {
#[serde(rename = "0", default, skip_serializing_if = "is_default")]
revisionstore_flags: Option<u64>,
#[serde(rename = "1", default, skip_serializing_if = "is_default")]
content_id: Option<WireContentId>,
#[serde(rename = "2", default, skip_serializing_if = "is_default")]
file_type: Option<WireFileType>,
#[serde(rename = "3", default, skip_serializing_if = "is_default")]
size: Option<u64>,
#[serde(rename = "4", default, skip_serializing_if = "is_default")]
content_sha1: Option<WireSha1>,
#[serde(rename = "5", default, skip_serializing_if = "is_default")]
content_sha256: Option<WireSha256>,
}
impl ToWire for FileMetadata {
type Wire = WireFileMetadata;
fn to_wire(self) -> Self::Wire {
WireFileMetadata {
revisionstore_flags: self.revisionstore_flags,
content_id: self.content_id.to_wire(),
file_type: self.file_type.to_wire(),
size: self.size,
content_sha1: self.content_sha1.to_wire(),
content_sha256: self.content_sha256.to_wire(),
}
}
}
impl ToApi for WireFileMetadata {
type Api = FileMetadata;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(FileMetadata {
revisionstore_flags: self.revisionstore_flags,
content_id: self.content_id.to_api()?,
file_type: self.file_type.to_api()?,
size: self.size,
content_sha1: self.content_sha1.to_api()?,
content_sha256: self.content_sha256.to_api()?,
})
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct WireFileMetadataRequest {
#[serde(rename = "0", default, skip_serializing_if = "is_default")]
with_revisionstore_flags: bool,
#[serde(rename = "1", default, skip_serializing_if = "is_default")]
with_content_id: bool,
#[serde(rename = "2", default, skip_serializing_if = "is_default")]
with_file_type: bool,
#[serde(rename = "3", default, skip_serializing_if = "is_default")]
with_size: bool,
#[serde(rename = "4", default, skip_serializing_if = "is_default")]
with_content_sha1: bool,
#[serde(rename = "5", default, skip_serializing_if = "is_default")]
with_content_sha256: bool,
}
impl ToWire for FileMetadataRequest {
type Wire = WireFileMetadataRequest;
fn to_wire(self) -> Self::Wire {
WireFileMetadataRequest {
with_revisionstore_flags: self.with_revisionstore_flags,
with_content_id: self.with_content_id,
with_file_type: self.with_file_type,
with_size: self.with_size,
with_content_sha1: self.with_content_sha1,
with_content_sha256: self.with_content_sha256,
}
}
}
impl ToApi for WireFileMetadataRequest {
type Api = FileMetadataRequest;
type Error = Infallible;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(FileMetadataRequest {
with_revisionstore_flags: self.with_revisionstore_flags,
with_content_id: self.with_content_id,
with_file_type: self.with_file_type,
with_size: self.with_size,
with_content_sha1: self.with_content_sha1,
with_content_sha256: self.with_content_sha256,
})
}
}
pub use crate::metadata::{
WireDirectoryMetadata, WireDirectoryMetadataRequest, WireFileMetadata, WireFileMetadataRequest,
};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum WireFileType {
@ -371,65 +142,6 @@ impl ToApi for WireAnyFileContentId {
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireDirectoryMetadata {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
fsnode_id: Arbitrary::arbitrary(g),
simple_format_sha1: Arbitrary::arbitrary(g),
simple_format_sha256: Arbitrary::arbitrary(g),
child_files_count: Arbitrary::arbitrary(g),
child_files_total_size: Arbitrary::arbitrary(g),
child_dirs_count: Arbitrary::arbitrary(g),
descendant_files_count: Arbitrary::arbitrary(g),
descendant_files_total_size: Arbitrary::arbitrary(g),
}
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireDirectoryMetadataRequest {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
with_fsnode_id: Arbitrary::arbitrary(g),
with_simple_format_sha1: Arbitrary::arbitrary(g),
with_simple_format_sha256: Arbitrary::arbitrary(g),
with_child_files_count: Arbitrary::arbitrary(g),
with_child_files_total_size: Arbitrary::arbitrary(g),
with_child_dirs_count: Arbitrary::arbitrary(g),
with_descendant_files_count: Arbitrary::arbitrary(g),
with_descendant_files_total_size: Arbitrary::arbitrary(g),
}
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireFileMetadata {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
revisionstore_flags: Arbitrary::arbitrary(g),
content_id: Arbitrary::arbitrary(g),
file_type: Arbitrary::arbitrary(g),
size: Arbitrary::arbitrary(g),
content_sha1: Arbitrary::arbitrary(g),
content_sha256: Arbitrary::arbitrary(g),
}
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireFileMetadataRequest {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
with_revisionstore_flags: Arbitrary::arbitrary(g),
with_content_id: Arbitrary::arbitrary(g),
with_file_type: Arbitrary::arbitrary(g),
with_size: Arbitrary::arbitrary(g),
with_content_sha1: Arbitrary::arbitrary(g),
with_content_sha256: Arbitrary::arbitrary(g),
}
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireFileType {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {

View File

@ -98,6 +98,7 @@ pub use crate::wire::{
use std::convert::Infallible;
use std::fmt;
use std::num::NonZeroU64;
#[cfg(any(test, feature = "for-tests"))]
use quickcheck::Arbitrary;
@ -218,7 +219,7 @@ impl<W: ToApi> ToApi for Option<W> {
// Only use it for very simple objects which serializations don't
// incur extra costs
macro_rules! transparent_wire {
( $($name: ty),* ) => {
( $($name: ty),* $(,)? ) => {
$(
impl ToWire for $name {
type Wire = $name;
@ -240,7 +241,42 @@ macro_rules! transparent_wire {
}
}
transparent_wire!(bool, u8, i8, u16, i16, u32, i32, u64, i64, bytes::Bytes);
transparent_wire!(
bool,
u8,
i8,
u16,
i16,
u32,
i32,
u64,
i64,
usize,
isize,
bytes::Bytes,
String,
);
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(transparent)]
pub struct WrapNonZero<T>(T);
impl ToWire for Option<NonZeroU64> {
type Wire = WrapNonZero<u64>;
fn to_wire(self) -> Self::Wire {
WrapNonZero(self.map_or(0, |x| x.get()))
}
}
impl ToApi for WrapNonZero<u64> {
type Api = Option<NonZeroU64>;
type Error = Infallible;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(NonZeroU64::new(self.0))
}
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum WireEdenApiServerError {

View File

@ -7,56 +7,19 @@
#[cfg(any(test, feature = "for-tests"))]
use quickcheck::Arbitrary;
use serde_derive::{Deserialize, Serialize};
use type_macros::auto_wire;
use types::HgId;
use crate::wire::{ToApi, ToWire, WireHgId, WireToApiConversionError};
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WirePullFastForwardRequest {
#[serde(rename = "1")]
pub old_master: WireHgId,
#[serde(rename = "2")]
pub new_master: WireHgId,
}
#[auto_wire]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct PullFastForwardRequest {
#[id(1)]
pub old_master: HgId,
#[id(2)]
pub new_master: HgId,
}
impl ToWire for PullFastForwardRequest {
type Wire = WirePullFastForwardRequest;
fn to_wire(self) -> Self::Wire {
WirePullFastForwardRequest {
old_master: self.old_master.to_wire(),
new_master: self.new_master.to_wire(),
}
}
}
impl ToApi for WirePullFastForwardRequest {
type Api = PullFastForwardRequest;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(PullFastForwardRequest {
old_master: self.old_master.to_api()?,
new_master: self.new_master.to_api()?,
})
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WirePullFastForwardRequest {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
PullFastForwardRequest::arbitrary(g).to_wire()
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for PullFastForwardRequest {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {

View File

@ -5,25 +5,13 @@
* GNU General Public License version 2.
*/
use std::num::NonZeroU64;
use crate::token::UploadTokenMetadata;
use crate::wire::{ToApi, ToWire, WireToApiConversionError};
use serde::{Deserialize, Serialize};
#[cfg(any(test, feature = "for-tests"))]
use quickcheck::Arbitrary;
#[cfg(any(test, feature = "for-tests"))]
use serde_derive::{Deserialize, Serialize};
use crate::token::{
FileContentTokenMetadata, UploadToken, UploadTokenData, UploadTokenMetadata,
UploadTokenSignature,
pub use crate::token::{
WireFileContentTokenMetadata, WireUploadToken, WireUploadTokenData, WireUploadTokenSignature,
};
use crate::wire::{is_default, ToApi, ToWire, WireAnyId, WireToApiConversionError};
/// Token metadata for file content token type.
#[derive(Clone, Default, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireFileContentTokenMetadata {
#[serde(rename = "1", default, skip_serializing_if = "is_default")]
pub content_size: u64,
}
/// Token metadata. Could be different for different token types.
/// A signed token guarantee the metadata has been verified.
@ -33,101 +21,6 @@ pub enum WireUploadTokenMetadata {
WireFileContentTokenMetadata(WireFileContentTokenMetadata),
}
#[derive(Clone, Default, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireUploadTokenData {
#[serde(rename = "1", default, skip_serializing_if = "is_default")]
pub id: WireAnyId,
#[serde(rename = "2", default, skip_serializing_if = "is_default")]
pub metadata: Option<WireUploadTokenMetadata>,
#[serde(rename = "3", default, skip_serializing_if = "is_default")]
pub bubble_id: Option<NonZeroU64>,
// other data to be added ...
}
#[derive(Clone, Default, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireUploadTokenSignature {
#[serde(rename = "1", default, skip_serializing_if = "is_default")]
pub signature: Vec<u8>,
}
#[derive(Clone, Default, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct WireUploadToken {
#[serde(rename = "1", default, skip_serializing_if = "is_default")]
pub data: WireUploadTokenData,
#[serde(rename = "2", default, skip_serializing_if = "is_default")]
pub signature: WireUploadTokenSignature,
}
impl ToWire for UploadToken {
type Wire = WireUploadToken;
fn to_wire(self) -> Self::Wire {
WireUploadToken {
data: self.data.to_wire(),
signature: self.signature.to_wire(),
}
}
}
impl ToApi for WireUploadToken {
type Api = UploadToken;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(UploadToken {
data: self.data.to_api()?,
signature: self.signature.to_api()?,
})
}
}
impl ToWire for UploadTokenSignature {
type Wire = WireUploadTokenSignature;
fn to_wire(self) -> Self::Wire {
Self::Wire {
signature: self.signature.to_wire(),
}
}
}
impl ToApi for WireUploadTokenSignature {
type Api = UploadTokenSignature;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
let api = Self::Api {
signature: self.signature.to_api()?,
};
Ok(api)
}
}
impl ToWire for UploadTokenData {
type Wire = WireUploadTokenData;
fn to_wire(self) -> Self::Wire {
WireUploadTokenData {
id: self.id.to_wire(),
bubble_id: self.bubble_id,
metadata: self.metadata.to_wire(),
}
}
}
impl ToApi for WireUploadTokenData {
type Api = UploadTokenData;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(UploadTokenData {
id: self.id.to_api()?,
bubble_id: self.bubble_id,
metadata: self.metadata.to_api()?,
})
}
}
impl ToWire for UploadTokenMetadata {
type Wire = WireUploadTokenMetadata;
@ -155,57 +48,6 @@ impl ToApi for WireUploadTokenMetadata {
}
}
impl ToWire for FileContentTokenMetadata {
type Wire = WireFileContentTokenMetadata;
fn to_wire(self) -> Self::Wire {
WireFileContentTokenMetadata {
content_size: self.content_size,
}
}
}
impl ToApi for WireFileContentTokenMetadata {
type Api = FileContentTokenMetadata;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(FileContentTokenMetadata {
content_size: self.content_size,
})
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireUploadToken {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
data: Arbitrary::arbitrary(g),
signature: Arbitrary::arbitrary(g),
}
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireUploadTokenData {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
id: Arbitrary::arbitrary(g),
bubble_id: Arbitrary::arbitrary(g),
metadata: None,
}
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireUploadTokenSignature {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
signature: Arbitrary::arbitrary(g),
}
}
}
#[cfg(test)]
mod tests {
use super::*;

View File

@ -7,21 +7,23 @@
use bytes::Bytes;
#[cfg(any(test, feature = "for-tests"))]
use quickcheck::{Arbitrary, Gen};
use quickcheck::Arbitrary;
use serde_derive::{Deserialize, Serialize};
use crate::{
tree::{
TreeAttributes, TreeChildDirectoryEntry, TreeChildEntry, TreeChildFileEntry, TreeEntry,
TreeRequest, UploadTreeEntry, UploadTreeRequest, UploadTreeResponse,
TreeRequest,
},
wire::{
is_default, ToApi, ToWire, WireDirectoryMetadata, WireEdenApiServerError, WireFileMetadata,
WireHgId, WireKey, WireParents, WireToApiConversionError, WireUploadToken,
WireKey, WireParents, WireToApiConversionError,
},
EdenApiServerError,
};
pub use crate::tree::{WireUploadTreeEntry, WireUploadTreeRequest, WireUploadTreeResponse};
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
pub struct WireTreeEntry {
#[serde(rename = "0", default, skip_serializing_if = "is_default")]
@ -257,102 +259,6 @@ impl ToApi for WireTreeRequest {
}
}
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
pub struct WireUploadTreeEntry {
#[serde(rename = "0", default, skip_serializing_if = "is_default")]
node_id: WireHgId,
#[serde(rename = "1", default, skip_serializing_if = "is_default")]
data: Vec<u8>,
#[serde(rename = "2", default, skip_serializing_if = "is_default")]
parents: WireParents,
}
#[derive(Clone, Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct WireUploadTreeRequest {
#[serde(rename = "0", default, skip_serializing_if = "is_default")]
pub entry: WireUploadTreeEntry,
}
#[derive(Clone, Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct WireUploadTreeResponse {
#[serde(rename = "0", default, skip_serializing_if = "is_default")]
pub index: usize,
#[serde(rename = "1", default, skip_serializing_if = "is_default")]
pub token: WireUploadToken,
}
impl ToWire for UploadTreeEntry {
type Wire = WireUploadTreeEntry;
fn to_wire(self) -> Self::Wire {
WireUploadTreeEntry {
node_id: self.node_id.to_wire(),
data: self.data.to_wire(),
parents: self.parents.to_wire(),
}
}
}
impl ToApi for WireUploadTreeEntry {
type Api = UploadTreeEntry;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(UploadTreeEntry {
node_id: self.node_id.to_api()?,
data: self.data.to_api()?,
parents: self.parents.to_api()?,
})
}
}
impl ToWire for UploadTreeRequest {
type Wire = WireUploadTreeRequest;
fn to_wire(self) -> Self::Wire {
WireUploadTreeRequest {
entry: self.entry.to_wire(),
}
}
}
impl ToApi for WireUploadTreeRequest {
type Api = UploadTreeRequest;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(UploadTreeRequest {
entry: self.entry.to_api()?,
})
}
}
impl ToWire for UploadTreeResponse {
type Wire = WireUploadTreeResponse;
fn to_wire(self) -> Self::Wire {
WireUploadTreeResponse {
index: self.index,
token: self.token.to_wire(),
}
}
}
impl ToApi for WireUploadTreeResponse {
type Api = UploadTreeResponse;
type Error = WireToApiConversionError;
fn to_api(self) -> Result<Self::Api, Self::Error> {
Ok(UploadTreeResponse {
index: self.index,
token: self.token.to_api()?,
})
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireTreeEntry {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
@ -411,13 +317,6 @@ impl Arbitrary for WireTreeRequest {
}
}
#[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for WireUploadTreeResponse {
fn arbitrary(g: &mut Gen) -> Self {
UploadTreeResponse::arbitrary(g).to_wire()
}
}
#[cfg(test)]
mod tests {
use super::*;

View File

@ -0,0 +1,6 @@
---
source: anyid.rs
expression: "WireLookupResponse::arbitrary(&mut g)"
---
{"1":5612343741886906158,"2":{"1":{"1":{"5":[231,250,132,19,212,76,218,174,127,211,79,1,180,239,159,71,129,237,47,133,207,59,183,155,157,133,85,4,46,38,85,25]},"3":15574015762201919121},"2":{"1":[58]}}}

View File

@ -3,4 +3,4 @@ source: bookmark.rs
expression: "WireBookmarkEntry::arbitrary(&mut g)"
---
{"1":"€","2":null}
{"1":"€"}

View File

@ -0,0 +1,6 @@
---
source: commit.rs
expression: "WireUploadHgChangeset::arbitrary(&mut g)"
---
{"1":[229,136,231,250,132,19,212,76,218,174,127,211,79,1,180,239,159,71,129,237],"2":{"2":[133,207,59,183,155,157,133,85,4,46,38,85,25,36,58,55,101,239,1,100],"3":[21,29,1],"4":7171884571288751686,"5":1472710612,"7":["kwta/bwyqn/kcjuul/pl"]}}

View File

@ -0,0 +1,6 @@
---
source: commit.rs
expression: "WireUploadHgChangesetsRequest::arbitrary(&mut g)"
---
{"1":[{"1":[136,231,250,132,19,212,76,218,174,127,211,79,1,180,239,159,71,129,237,47],"2":{"1":{"3":[[207,59,183,155,157,133,85,4,46,38,85,25,36,58,55,101,239,1,100,81],[21,29,1,4,212,7,211,178,104,186,230,81,160,133,254,52,10,95,232,130]]},"2":[59,15,255,112,185,80,58,100,255,255,178,51,90,83,215,163,208,194,73,31],"3":[19,255],"4":-8968904448395217943,"5":-2147483648,"6":[{"1":[140],"2":[60]},{"1":[132,1]}],"8":[0,202]}}]}