types: rename LooseHistoryEntry and PackHistoryEntry

Summary: `LooseHistoryEntry` and `PackHistoryEntry` aren't the best names for these types, since the latter is what most users should use, whereas the former should only typically used for data transmission. As such, we should rename these to clarify the intent.

Differential Revision: D14512749

fbshipit-source-id: 5293df89766825077b2ba07224297b958bf46002
This commit is contained in:
Arun Kulshreshtha 2019-03-18 19:46:26 -07:00 committed by Facebook Github Bot
parent 23b335785f
commit ef3f3dea44
5 changed files with 37 additions and 38 deletions

View File

@ -9,7 +9,7 @@ use tokio_threadpool::blocking;
use cloned::cloned; use cloned::cloned;
use revisionstore::{HistoryPackVersion, MutableHistoryPack, MutablePack}; use revisionstore::{HistoryPackVersion, MutableHistoryPack, MutablePack};
use types::{Key, NodeInfo, PackHistoryEntry}; use types::{HistoryEntry, Key, NodeInfo};
pub struct AsyncMutableHistoryPackInner { pub struct AsyncMutableHistoryPackInner {
data: MutableHistoryPack, data: MutableHistoryPack,
@ -70,7 +70,7 @@ impl AsyncMutableHistoryPack {
/// Convenience function for adding a `types::PackHistoryEntry`. /// Convenience function for adding a `types::PackHistoryEntry`.
pub fn add_entry( pub fn add_entry(
self, self,
entry: &PackHistoryEntry, entry: &HistoryEntry,
) -> impl Future<Item = Self, Error = Error> + Send + 'static { ) -> impl Future<Item = Self, Error = Error> + Send + 'static {
self.add(&entry.key, &entry.nodeinfo) self.add(&entry.key, &entry.nodeinfo)
} }

View File

@ -18,7 +18,7 @@ use revisionstore::{
DataPackVersion, Delta, HistoryPackVersion, Metadata, MutableDataPack, MutableHistoryPack, DataPackVersion, Delta, HistoryPackVersion, Metadata, MutableDataPack, MutableHistoryPack,
MutablePack, MutablePack,
}; };
use types::{Key, PackHistoryEntry}; use types::{HistoryEntry, Key};
use url_ext::UrlExt; use url_ext::UrlExt;
use crate::client::{EdenApiHttpClient, HyperClient}; use crate::client::{EdenApiHttpClient, HyperClient};
@ -155,7 +155,7 @@ fn get_history(
url_prefix: &Url, url_prefix: &Url,
key: Key, key: Key,
max_depth: Option<u32>, max_depth: Option<u32>,
) -> impl Stream<Item = PackHistoryEntry, Error = Error> { ) -> impl Stream<Item = HistoryEntry, Error = Error> {
log::debug!("Fetching history for key: {}", &key); log::debug!("Fetching history for key: {}", &key);
let filenode = key.node().to_hex(); let filenode = key.node().to_hex();
let filename = url_encode(&key.name()); let filename = url_encode(&key.name());
@ -198,7 +198,7 @@ fn get_history(
stream::iter_result(entries).from_err() stream::iter_result(entries).from_err()
}) })
.flatten_stream() .flatten_stream()
.map(move |entry| PackHistoryEntry::from_loose(entry, key.name().to_vec())) .map(move |entry| HistoryEntry::from_wire(entry, key.name().to_vec()))
} }
/// Create a new datapack in the given directory, and populate it with the file /// Create a new datapack in the given directory, and populate it with the file
@ -229,7 +229,7 @@ fn write_datapack(
/// with the given history entries. /// with the given history entries.
fn write_historypack( fn write_historypack(
pack_dir: impl AsRef<Path>, pack_dir: impl AsRef<Path>,
entries: impl IntoIterator<Item = PackHistoryEntry>, entries: impl IntoIterator<Item = HistoryEntry>,
) -> Fallible<PathBuf> { ) -> Fallible<PathBuf> {
let mut historypack = MutableHistoryPack::new(pack_dir, HistoryPackVersion::One)?; let mut historypack = MutableHistoryPack::new(pack_dir, HistoryPackVersion::One)?;
for entry in entries { for entry in entries {

View File

@ -16,7 +16,7 @@ use crypto::sha1::Sha1;
use failure::{Fail, Fallible}; use failure::{Fail, Fallible};
use tempfile::NamedTempFile; use tempfile::NamedTempFile;
use types::{Key, NodeInfo, PackHistoryEntry}; use types::{Key, NodeInfo};
use crate::ancestors::{AncestorIterator, AncestorTraversal}; use crate::ancestors::{AncestorIterator, AncestorTraversal};
use crate::historyindex::{FileSectionLocation, HistoryIndex, NodeLocation}; use crate::historyindex::{FileSectionLocation, HistoryIndex, NodeLocation};
@ -67,7 +67,7 @@ impl MutableHistoryPack {
Ok(()) Ok(())
} }
pub fn add_entry(&mut self, entry: &PackHistoryEntry) -> Fallible<()> { pub fn add_entry(&mut self, entry: &types::HistoryEntry) -> Fallible<()> {
self.add(&entry.key, &entry.nodeinfo) self.add(&entry.key, &entry.nodeinfo)
} }

View File

@ -19,19 +19,18 @@ use crate::{key::Key, node::Node, nodeinfo::NodeInfo, parents::Parents};
Serialize, Serialize,
Deserialize Deserialize
)] )]
pub struct PackHistoryEntry { pub struct HistoryEntry {
pub key: Key, pub key: Key,
pub nodeinfo: NodeInfo, pub nodeinfo: NodeInfo,
} }
impl PackHistoryEntry { impl HistoryEntry {
/// A LooseHistoryEntry doesn't contain enough information to /// A WireHistoryEntry doesn't contain enough information to construct
/// construct a PackHistoryEntry because it doesn't contain the /// a HistoryEntry because it doesn't contain the name of file to which
/// name of file to which the entry refers. (The name is a bytestring /// the entry refers. (The name is a bytestring that usually consists
/// that usually consists of the file's path.) As such, the name /// of the file's path.) As such, the name needs to be supplied by the
/// needs to be supplied by the caller in order to convert to /// caller in order to perform the conversion.
/// PackHistoryEntry. pub fn from_wire(entry: WireHistoryEntry, name: Vec<u8>) -> Self {
pub fn from_loose(entry: LooseHistoryEntry, name: Vec<u8>) -> Self {
// If this file was copied, use the original name as the name of // If this file was copied, use the original name as the name of
// the p1 key instead of the current entry's name. // the p1 key instead of the current entry's name.
let p1_name = entry.copyfrom.unwrap_or_else(|| name.clone()); let p1_name = entry.copyfrom.unwrap_or_else(|| name.clone());
@ -61,15 +60,15 @@ impl PackHistoryEntry {
} }
} }
impl From<(LooseHistoryEntry, Vec<u8>)> for PackHistoryEntry { impl From<(WireHistoryEntry, Vec<u8>)> for HistoryEntry {
fn from((entry, name): (LooseHistoryEntry, Vec<u8>)) -> Self { fn from((entry, name): (WireHistoryEntry, Vec<u8>)) -> Self {
Self::from_loose(entry, name) Self::from_wire(entry, name)
} }
} }
/// History entry structure containing fields corresponding to /// History entry structure containing fields corresponding to
/// a single history record in Mercurial's loose file format. /// a single history record in Mercurial's loose file format.
/// This format contains less information than a PackHistoryEntry /// This format contains less information than a HistoryEntry
/// (namely, it doesn't contain the name of the file), and has /// (namely, it doesn't contain the name of the file), and has
/// less redundancy, making it more suitable as a compact /// less redundancy, making it more suitable as a compact
/// representation of a history entry for data exchange between /// representation of a history entry for data exchange between
@ -86,15 +85,15 @@ impl From<(LooseHistoryEntry, Vec<u8>)> for PackHistoryEntry {
Serialize, Serialize,
Deserialize Deserialize
)] )]
pub struct LooseHistoryEntry { pub struct WireHistoryEntry {
pub node: Node, pub node: Node,
pub parents: Parents, pub parents: Parents,
pub linknode: Node, pub linknode: Node,
pub copyfrom: Option<Vec<u8>>, pub copyfrom: Option<Vec<u8>>,
} }
impl From<PackHistoryEntry> for LooseHistoryEntry { impl From<HistoryEntry> for WireHistoryEntry {
fn from(entry: PackHistoryEntry) -> Self { fn from(entry: HistoryEntry) -> Self {
let [p1, p2] = entry.nodeinfo.parents; let [p1, p2] = entry.nodeinfo.parents;
// If the p1's name differs from the entry's name, this means the file // If the p1's name differs from the entry's name, this means the file
// was copied, so populate the copyfrom path with the p1 name. // was copied, so populate the copyfrom path with the p1 name.
@ -117,7 +116,7 @@ impl From<PackHistoryEntry> for LooseHistoryEntry {
use quickcheck::{quickcheck, Arbitrary}; use quickcheck::{quickcheck, Arbitrary};
#[cfg(any(test, feature = "for-tests"))] #[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for PackHistoryEntry { impl Arbitrary for HistoryEntry {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self { fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
let key = Key::arbitrary(g); let key = Key::arbitrary(g);
let mut nodeinfo = NodeInfo::arbitrary(g); let mut nodeinfo = NodeInfo::arbitrary(g);
@ -142,12 +141,12 @@ impl Arbitrary for PackHistoryEntry {
nodeinfo.parents[1] = Key::default(); nodeinfo.parents[1] = Key::default();
} }
PackHistoryEntry { key, nodeinfo } Self { key, nodeinfo }
} }
} }
#[cfg(any(test, feature = "for-tests"))] #[cfg(any(test, feature = "for-tests"))]
impl Arbitrary for LooseHistoryEntry { impl Arbitrary for WireHistoryEntry {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self { fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
// It doesn't make sense to have a non-None copyfrom containing // It doesn't make sense to have a non-None copyfrom containing
// an empty name, so set copyfrom to None in such cases. // an empty name, so set copyfrom to None in such cases.
@ -160,7 +159,7 @@ impl Arbitrary for LooseHistoryEntry {
copyfrom = None; copyfrom = None;
} }
LooseHistoryEntry { Self {
node: Node::arbitrary(g), node: Node::arbitrary(g),
parents, parents,
linknode: Node::arbitrary(g), linknode: Node::arbitrary(g),
@ -174,17 +173,17 @@ mod tests {
use super::*; use super::*;
quickcheck! { quickcheck! {
fn pack_entry_roundtrip(pack: PackHistoryEntry) -> bool { fn history_entry_roundtrip(entry: HistoryEntry) -> bool {
let name = pack.key.name.clone(); let name = entry.key.name.clone();
let loose = LooseHistoryEntry::from(pack.clone()); let wire = WireHistoryEntry::from(entry.clone());
let roundtrip = PackHistoryEntry::from((loose, name)); let roundtrip = HistoryEntry::from((wire, name));
pack == roundtrip entry == roundtrip
} }
fn loose_entry_roundtrip(loose: LooseHistoryEntry, name: Vec<u8>) -> bool { fn wire_entry_roundtrip(wire: WireHistoryEntry, name: Vec<u8>) -> bool {
let pack = PackHistoryEntry::from((loose.clone(), name)); let entry = HistoryEntry::from((wire.clone(), name));
let roundtrip = LooseHistoryEntry::from(pack); let roundtrip = WireHistoryEntry::from(entry);
loose == roundtrip wire == roundtrip
} }
} }
} }

View File

@ -13,7 +13,7 @@ pub mod nodeinfo;
pub mod parents; pub mod parents;
pub mod path; pub mod path;
pub use crate::historyentry::{LooseHistoryEntry, PackHistoryEntry}; pub use crate::historyentry::{HistoryEntry, WireHistoryEntry};
pub use crate::key::Key; pub use crate::key::Key;
pub use crate::node::Node; pub use crate::node::Node;
pub use crate::nodeinfo::NodeInfo; pub use crate::nodeinfo::NodeInfo;