diff --git a/eden/scm/lib/edenapi/types/proc_macros/lib.rs b/eden/scm/lib/edenapi/types/proc_macros/lib.rs index fcffcf599e..4ac9ab59d8 100644 --- a/eden/scm/lib/edenapi/types/proc_macros/lib.rs +++ b/eden/scm/lib/edenapi/types/proc_macros/lib.rs @@ -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, diff --git a/eden/scm/lib/edenapi/types/src/anyid.rs b/eden/scm/lib/edenapi/types/src/anyid.rs index c0bee2e552..0446b80a60 100644 --- a/eden/scm/lib/edenapi/types/src/anyid.rs +++ b/eden/scm/lib/edenapi/types/src/anyid.rs @@ -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, } -#[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, } @@ -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), + } + } +} diff --git a/eden/scm/lib/edenapi/types/src/bookmark.rs b/eden/scm/lib/edenapi/types/src/bookmark.rs index 2878b0e013..3db951146f 100644 --- a/eden/scm/lib/edenapi/types/src/bookmark.rs +++ b/eden/scm/lib/edenapi/types/src/bookmark.rs @@ -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, } @@ -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, } diff --git a/eden/scm/lib/edenapi/types/src/commit.rs b/eden/scm/lib/edenapi/types/src/commit.rs index 4ec93c2e2b..9e415e120d 100644 --- a/eden/scm/lib/edenapi/types/src/commit.rs +++ b/eden/scm/lib/edenapi/types/src/commit.rs @@ -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, + #[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, + #[id(2)] pub count: u64, + #[id(3)] pub hgids: Vec, } +#[auto_wire] #[derive(Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] #[derive(Serialize, Deserialize)] pub struct CommitLocationToHashRequestBatch { + #[id(1)] pub requests: Vec, } @@ -107,17 +117,23 @@ pub struct CommitKnownResponse { pub known: Result, } +#[auto_wire] #[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] #[derive(Serialize)] pub struct CommitGraphEntry { + #[id(1)] pub hgid: HgId, + #[id(2)] pub parents: Vec, } +#[auto_wire] #[derive(Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] #[derive(Serialize, Deserialize)] pub struct CommitGraphRequest { + #[id(1)] pub common: Vec, + #[id(2)] pub heads: Vec, } @@ -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, + #[id(2)] pub value: Vec, } +#[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, + #[id(4)] pub time: i64, + #[id(5)] pub tz: i32, + #[id(6)] pub extras: Vec, + #[id(7)] pub files: Vec, + #[id(8)] pub message: Vec, } +#[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, + #[id(3)] pub split: Vec, + #[id(4)] pub op: String, + #[id(5)] pub user: Vec, + #[id(6)] pub time: i64, + #[id(7)] pub tz: i32, + #[id(8)] pub extras: Vec, } +#[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, /// list of mutation entries for the uploading changesets + #[id(2)] pub mutations: Vec, } +#[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, } @@ -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 { diff --git a/eden/scm/lib/edenapi/types/src/complete_tree.rs b/eden/scm/lib/edenapi/types/src/complete_tree.rs index b27f5ca025..ae7f6e859f 100644 --- a/eden/scm/lib/edenapi/types/src/complete_tree.rs +++ b/eden/scm/lib/edenapi/types/src/complete_tree.rs @@ -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, + #[id(2)] pub basemfnodes: Vec, + #[id(3)] pub depth: Option, } diff --git a/eden/scm/lib/edenapi/types/src/file.rs b/eden/scm/lib/edenapi/types/src/file.rs index d9eb423e3d..52dfc502fa 100644 --- a/eden/scm/lib/edenapi/types/src/file.rs +++ b/eden/scm/lib/edenapi/types/src/file.rs @@ -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, + #[id(1)] pub reqs: Vec, } @@ -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, } -#[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, } diff --git a/eden/scm/lib/edenapi/types/src/metadata.rs b/eden/scm/lib/edenapi/types/src/metadata.rs index 14673b09f3..4db8ebffa4 100644 --- a/eden/scm/lib/edenapi/types/src/metadata.rs +++ b/eden/scm/lib/edenapi/types/src/metadata.rs @@ -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, + #[id(1)] pub simple_format_sha1: Option, + #[id(2)] pub simple_format_sha256: Option, + #[id(3)] pub child_files_count: Option, + #[id(4)] pub child_files_total_size: Option, + #[id(5)] pub child_dirs_count: Option, + #[id(6)] pub descendant_files_count: Option, + #[id(7)] pub descendant_files_total_size: Option, } +#[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, + #[id(1)] pub content_id: Option, + #[id(2)] pub file_type: Option, + #[id(3)] pub size: Option, + #[id(4)] pub content_sha1: Option, + #[id(5)] pub content_sha256: Option, } +#[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, } diff --git a/eden/scm/lib/edenapi/types/src/token.rs b/eden/scm/lib/edenapi/types/src/token.rs index d8ad1440f5..e07ecf0b82 100644 --- a/eden/scm/lib/edenapi/types/src/token.rs +++ b/eden/scm/lib/edenapi/types/src/token.rs @@ -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 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, + #[id(2)] pub metadata: Option, // 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, } +#[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 { diff --git a/eden/scm/lib/edenapi/types/src/tree.rs b/eden/scm/lib/edenapi/types/src/tree.rs index e564c868c2..bf33dde801 100644 --- a/eden/scm/lib/edenapi/types/src/tree.rs +++ b/eden/scm/lib/edenapi/types/src/tree.rs @@ -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, + #[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), + } + } +} diff --git a/eden/scm/lib/edenapi/types/src/wire/anyid.rs b/eden/scm/lib/edenapi/types/src/wire/anyid.rs index a40e494975..22cec61453 100644 --- a/eden/scm/lib/edenapi/types/src/wire/anyid.rs +++ b/eden/scm/lib/edenapi/types/src/wire/anyid.rs @@ -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, -} - -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 { - 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, -} - -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 { - 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); } diff --git a/eden/scm/lib/edenapi/types/src/wire/bookmark.rs b/eden/scm/lib/edenapi/types/src/wire/bookmark.rs index 59c8a7b894..7f380c9f9e 100644 --- a/eden/scm/lib/edenapi/types/src/wire/bookmark.rs +++ b/eden/scm/lib/edenapi/types/src/wire/bookmark.rs @@ -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, -} - -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 { - 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, -} - -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 { - 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 { diff --git a/eden/scm/lib/edenapi/types/src/wire/commit.rs b/eden/scm/lib/edenapi/types/src/wire/commit.rs index e629d48597..089152e8d3 100644 --- a/eden/scm/lib/edenapi/types/src/wire/commit.rs +++ b/eden/scm/lib/edenapi/types/src/wire/commit.rs @@ -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, -} - -#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)] -pub struct WireCommitLocationToHashRequestBatch { - #[serde(rename = "1")] - pub requests: Vec, -} - -#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)] -pub struct WireCommitGraphRequest { - #[serde(rename = "1")] - pub common: Vec, - #[serde(rename = "2")] - pub heads: Vec, -} - -#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)] -pub struct WireCommitGraphEntry { - #[serde(rename = "1")] - pub hgid: WireHgId, - #[serde(rename = "2")] - pub parents: Vec, -} - impl ToWire for Location { 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 { - 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 { - 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 { - 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 { - 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 { - 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, - - #[serde(rename = "2")] - pub value: Vec, -} - -#[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, - - #[serde(rename = "4")] - pub time: i64, - - #[serde(rename = "5")] - pub tz: i32, - - #[serde(rename = "6")] - pub extras: Vec, - - #[serde(rename = "7")] - pub files: Vec, - - #[serde(rename = "8")] - pub message: Vec, -} - -#[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, - - #[serde(rename = "3")] - pub split: Vec, - - #[serde(rename = "4")] - pub op: String, - - #[serde(rename = "5")] - pub user: Vec, - - #[serde(rename = "6")] - pub time: i64, - - #[serde(rename = "7")] - pub tz: i32, - - #[serde(rename = "8")] - pub extras: Vec, -} - -#[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, - - /// list of mutation entries for the uploading changesets - #[serde(rename = "2")] - pub mutations: Vec, -} - -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 { - 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 { - 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 { - 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 { - 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 { - 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, -} - #[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, } -#[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 { - 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 { - 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, } -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 { - 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 { - 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 { - 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, ); diff --git a/eden/scm/lib/edenapi/types/src/wire/complete_tree.rs b/eden/scm/lib/edenapi/types/src/wire/complete_tree.rs index b8b644b03e..8d8d751ff4 100644 --- a/eden/scm/lib/edenapi/types/src/wire/complete_tree.rs +++ b/eden/scm/lib/edenapi/types/src/wire/complete_tree.rs @@ -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, - - #[serde(rename = "2", default, skip_serializing_if = "is_default")] - pub basemfnodes: Vec, - - #[serde(rename = "3", default, skip_serializing_if = "is_default")] - pub depth: Option, -} - -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 { - 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 { diff --git a/eden/scm/lib/edenapi/types/src/wire/file.rs b/eden/scm/lib/edenapi/types/src/wire/file.rs index 8e499e05f2..0a55188308 100644 --- a/eden/scm/lib/edenapi/types/src/wire/file.rs +++ b/eden/scm/lib/edenapi/types/src/wire/file.rs @@ -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 { - 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 { - 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, - - #[serde(rename = "1", default, skip_serializing_if = "is_default")] - pub reqs: Vec, -} - -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 { - 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, -} - -#[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 { - 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 { - 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 { - 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::*; diff --git a/eden/scm/lib/edenapi/types/src/wire/history.rs b/eden/scm/lib/edenapi/types/src/wire/history.rs index ef899a6dc8..13eafe879e 100644 --- a/eden/scm/lib/edenapi/types/src/wire/history.rs +++ b/eden/scm/lib/edenapi/types/src/wire/history.rs @@ -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, diff --git a/eden/scm/lib/edenapi/types/src/wire/metadata.rs b/eden/scm/lib/edenapi/types/src/wire/metadata.rs index f39f830de2..80fb5a3753 100644 --- a/eden/scm/lib/edenapi/types/src/wire/metadata.rs +++ b/eden/scm/lib/edenapi/types/src/wire/metadata.rs @@ -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, - - #[serde(rename = "1", default, skip_serializing_if = "is_default")] - simple_format_sha1: Option, - - #[serde(rename = "2", default, skip_serializing_if = "is_default")] - simple_format_sha256: Option, - - #[serde(rename = "3", default, skip_serializing_if = "is_default")] - child_files_count: Option, - - #[serde(rename = "4", default, skip_serializing_if = "is_default")] - child_files_total_size: Option, - - #[serde(rename = "5", default, skip_serializing_if = "is_default")] - child_dirs_count: Option, - - #[serde(rename = "6", default, skip_serializing_if = "is_default")] - descendant_files_count: Option, - - #[serde(rename = "7", default, skip_serializing_if = "is_default")] - descendant_files_total_size: Option, -} - -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 { - 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 { - 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, - - #[serde(rename = "1", default, skip_serializing_if = "is_default")] - content_id: Option, - - #[serde(rename = "2", default, skip_serializing_if = "is_default")] - file_type: Option, - - #[serde(rename = "3", default, skip_serializing_if = "is_default")] - size: Option, - - #[serde(rename = "4", default, skip_serializing_if = "is_default")] - content_sha1: Option, - - #[serde(rename = "5", default, skip_serializing_if = "is_default")] - content_sha256: Option, -} - -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 { - 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 { - 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 { diff --git a/eden/scm/lib/edenapi/types/src/wire/mod.rs b/eden/scm/lib/edenapi/types/src/wire/mod.rs index 66b84fa3a5..efb23f364a 100644 --- a/eden/scm/lib/edenapi/types/src/wire/mod.rs +++ b/eden/scm/lib/edenapi/types/src/wire/mod.rs @@ -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 ToApi for Option { // 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); + +impl ToWire for Option { + type Wire = WrapNonZero; + + fn to_wire(self) -> Self::Wire { + WrapNonZero(self.map_or(0, |x| x.get())) + } +} + +impl ToApi for WrapNonZero { + type Api = Option; + type Error = Infallible; + + fn to_api(self) -> Result { + Ok(NonZeroU64::new(self.0)) + } +} #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum WireEdenApiServerError { diff --git a/eden/scm/lib/edenapi/types/src/wire/pull.rs b/eden/scm/lib/edenapi/types/src/wire/pull.rs index ccda49aa36..79b2b933fb 100644 --- a/eden/scm/lib/edenapi/types/src/wire/pull.rs +++ b/eden/scm/lib/edenapi/types/src/wire/pull.rs @@ -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 { - 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 { diff --git a/eden/scm/lib/edenapi/types/src/wire/token.rs b/eden/scm/lib/edenapi/types/src/wire/token.rs index 910edbf800..49386852e2 100644 --- a/eden/scm/lib/edenapi/types/src/wire/token.rs +++ b/eden/scm/lib/edenapi/types/src/wire/token.rs @@ -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, - #[serde(rename = "3", default, skip_serializing_if = "is_default")] - pub bubble_id: Option, - // 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, -} - -#[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 { - 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 { - 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 { - 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 { - 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::*; diff --git a/eden/scm/lib/edenapi/types/src/wire/tree.rs b/eden/scm/lib/edenapi/types/src/wire/tree.rs index 140238a539..a1f8c156e8 100644 --- a/eden/scm/lib/edenapi/types/src/wire/tree.rs +++ b/eden/scm/lib/edenapi/types/src/wire/tree.rs @@ -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, - - #[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 { - 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 { - 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 { - 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::*; diff --git a/eden/scm/lib/insta_ext/snapshots/edenapi_types__wire__anyid__tests__auto_test_wire_lookup_response.snap b/eden/scm/lib/insta_ext/snapshots/edenapi_types__wire__anyid__tests__auto_test_wire_lookup_response.snap new file mode 100644 index 0000000000..a82411bbcc --- /dev/null +++ b/eden/scm/lib/insta_ext/snapshots/edenapi_types__wire__anyid__tests__auto_test_wire_lookup_response.snap @@ -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]}}} diff --git a/eden/scm/lib/insta_ext/snapshots/edenapi_types__wire__bookmark__tests__auto_test_wire_bookmark_entry.snap b/eden/scm/lib/insta_ext/snapshots/edenapi_types__wire__bookmark__tests__auto_test_wire_bookmark_entry.snap index 1981fe97a9..b576a750ac 100644 --- a/eden/scm/lib/insta_ext/snapshots/edenapi_types__wire__bookmark__tests__auto_test_wire_bookmark_entry.snap +++ b/eden/scm/lib/insta_ext/snapshots/edenapi_types__wire__bookmark__tests__auto_test_wire_bookmark_entry.snap @@ -3,4 +3,4 @@ source: bookmark.rs expression: "WireBookmarkEntry::arbitrary(&mut g)" --- -{"1":"€","2":null} +{"1":"€"} diff --git a/eden/scm/lib/insta_ext/snapshots/edenapi_types__wire__commit__tests__auto_test_wire_upload_hg_changeset.snap b/eden/scm/lib/insta_ext/snapshots/edenapi_types__wire__commit__tests__auto_test_wire_upload_hg_changeset.snap new file mode 100644 index 0000000000..2a642ffbd4 --- /dev/null +++ b/eden/scm/lib/insta_ext/snapshots/edenapi_types__wire__commit__tests__auto_test_wire_upload_hg_changeset.snap @@ -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"]}} diff --git a/eden/scm/lib/insta_ext/snapshots/edenapi_types__wire__commit__tests__auto_test_wire_upload_hg_changesets_request.snap b/eden/scm/lib/insta_ext/snapshots/edenapi_types__wire__commit__tests__auto_test_wire_upload_hg_changesets_request.snap new file mode 100644 index 0000000000..d904cbd6ff --- /dev/null +++ b/eden/scm/lib/insta_ext/snapshots/edenapi_types__wire__commit__tests__auto_test_wire_upload_hg_changesets_request.snap @@ -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]}}]}