mononoke: make PartId a public alias for u32, importable from mercurial_bundles

Summary: What title says. I am only doing this for readability. I don't think we'll ever change the `PartId` to be something else. But having an importable type for it seems useful.

Reviewed By: krallin

Differential Revision: D16073632

fbshipit-source-id: c11349e453c7b5e33b9d14097b6171eeb88865d8
This commit is contained in:
Kostia Balytskyi 2019-07-01 10:01:57 -07:00 committed by Facebook Github Bot
parent 5e8b126693
commit 2521c87f0d
6 changed files with 20 additions and 17 deletions

View File

@ -23,6 +23,7 @@ use async_compression::{Compressor, CompressorType};
use crate::chunk::{Chunk, ChunkEncoder};
use crate::errors::*;
use crate::part_encode::{PartEncode, PartEncodeBuilder};
use crate::part_header::PartId;
use crate::types::StreamHeader;
use crate::utils::{capitalize_first, get_compression_param, is_mandatory_param};
use mercurial_types::percent_encode;
@ -91,7 +92,7 @@ where
}
pub fn add_part(&mut self, part: PartEncodeBuilder) -> &mut Self {
let part_id = self.parts.len() as u32;
let part_id = self.parts.len() as PartId;
self.parts.push(part.build(part_id));
self
}

View File

@ -87,7 +87,7 @@ use std::fmt;
use futures_ext::{BoxFuture, BoxStream};
pub use crate::bundle2_encode::Bundle2EncodeBuilder;
pub use crate::part_header::{PartHeader, PartHeaderInner, PartHeaderType};
pub use crate::part_header::{PartHeader, PartHeaderInner, PartHeaderType, PartId};
pub use crate::types::StreamHeader;
pub enum Bundle2Item {

View File

@ -14,7 +14,7 @@ use futures::{Async, Future, Poll, Stream};
use crate::chunk::Chunk;
use crate::errors::*;
use crate::part_header::{PartHeader, PartHeaderBuilder, PartHeaderType};
use crate::part_header::{PartHeader, PartHeaderBuilder, PartHeaderType, PartId};
/// Represents a stream of chunks produced by the individual part handler.
pub struct ChunkStream(Box<dyn Stream<Item = Chunk, Error = Error> + Send>);
@ -121,7 +121,7 @@ impl PartEncodeBuilder {
self
}
pub fn build(self, part_id: u32) -> PartEncode {
pub fn build(self, part_id: PartId) -> PartEncode {
PartEncode {
state: GenerationState::NotStarted(self.headerb.build(part_id), self.data),
}

View File

@ -15,6 +15,8 @@ use crate::chunk::Chunk;
use crate::errors::*;
use crate::utils::BytesExt;
pub type PartId = u32;
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub enum PartHeaderType {
/// Responsible for sending Changesets and Filelogs during a push. In Mercurial it also sends
@ -126,7 +128,7 @@ impl PartHeaderType {
pub struct PartHeaderInner {
pub part_type: PartHeaderType,
pub mandatory: bool,
pub part_id: u32,
pub part_id: PartId,
// Part parameter keys are strings and values are arbitrary bytestrings
// (which can even include null characters).
pub mparams: HashMap<String, Bytes>,
@ -144,7 +146,7 @@ impl PartHeader {
}
#[inline]
pub fn part_id(&self) -> u32 {
pub fn part_id(&self) -> PartId {
self.0.part_id
}
@ -375,7 +377,7 @@ impl PartHeaderBuilder {
///
/// We only accept part_id at this point because in the serialization use
/// case, a part id is only assigned when the header is finalized.
pub fn build(self, part_id: u32) -> PartHeader {
pub fn build(self, part_id: PartId) -> PartHeader {
PartHeader(PartHeaderInner {
part_type: self.part_type,
mandatory: self.mandatory,
@ -463,7 +465,7 @@ mod test {
as fn(
PartHeaderType,
bool,
u32,
PartId,
HashMap<String, QCBytes>,
HashMap<String, QCBytes>,
) -> TestResult,
@ -473,7 +475,7 @@ mod test {
fn roundtrip(
part_type: PartHeaderType,
mandatory: bool,
part_id: u32,
part_id: PartId,
mparams: HashMap<String, QCBytes>,
aparams: HashMap<String, QCBytes>,
) -> TestResult {
@ -490,7 +492,7 @@ mod test {
fn roundtrip_inner(
part_type: PartHeaderType,
mandatory: bool,
part_id: u32,
part_id: PartId,
mparams: HashMap<String, QCBytes>,
aparams: HashMap<String, QCBytes>,
) -> Result<TestResult> {

View File

@ -18,7 +18,7 @@ use tokio_codec::{Decoder, Framed, FramedParts};
use tokio_io::AsyncRead;
use crate::errors::*;
use crate::part_header::{self, PartHeader, PartHeaderType};
use crate::part_header::{self, PartHeader, PartHeaderType, PartId};
use crate::part_inner::validate_header;
use crate::types::StreamHeader;
use crate::utils::{get_decompressor_type, BytesExt};
@ -52,7 +52,7 @@ enum OuterState {
Header,
Payload {
part_type: PartHeaderType,
part_id: u32,
part_id: PartId,
},
DiscardPayload,
StreamEnd,
@ -257,12 +257,12 @@ pub enum OuterFrame {
Header(PartHeader),
Payload {
part_type: PartHeaderType,
part_id: u32,
part_id: PartId,
payload: Bytes,
},
PartEnd {
part_type: PartHeaderType,
part_id: u32,
part_id: PartId,
},
Discard,
StreamEnd,

View File

@ -13,7 +13,7 @@ use super::wirepack::packer::WirePackPacker;
use crate::errors::*;
use crate::failure::prelude::*;
use crate::part_encode::PartEncodeBuilder;
use crate::part_header::PartHeaderType;
use crate::part_header::{PartHeaderType, PartId};
use byteorder::{BigEndian, WriteBytesExt};
use bytes::Bytes;
use context::CoreContext;
@ -231,7 +231,7 @@ impl fmt::Display for ChangegroupApplyResult {
pub fn replychangegroup_part(
res: ChangegroupApplyResult,
in_reply_to: u32,
in_reply_to: PartId,
) -> Result<PartEncodeBuilder> {
let mut builder = PartEncodeBuilder::mandatory(PartHeaderType::ReplyChangegroup)?;
builder.add_mparam("return", format!("{}", res))?;
@ -240,7 +240,7 @@ pub fn replychangegroup_part(
Ok(builder)
}
pub fn replypushkey_part(res: bool, in_reply_to: u32) -> Result<PartEncodeBuilder> {
pub fn replypushkey_part(res: bool, in_reply_to: PartId) -> Result<PartEncodeBuilder> {
let mut builder = PartEncodeBuilder::mandatory(PartHeaderType::ReplyPushkey)?;
if res {
builder.add_mparam("return", "1")?;