From 65bceaf5e5a3afcbdfa09110d6d3488d1a5ac9ad Mon Sep 17 00:00:00 2001 From: Meyer Jacobs Date: Thu, 12 Aug 2021 19:33:46 -0700 Subject: [PATCH] manifest-tree: implement TryFrom for directly converting from a serialized manifest tree entry to a manifest::List Summary: Allow `manifest-tree::Entry` to be constructed directly by other crates, and introduce a `TryFrom` conversion to `manifest::List::Directory`. This will be used by the scmstore `BackingStore` implementation to avoid having to rely on the `TreeStore` trait, which does not support batching. Reviewed By: kulshrax Differential Revision: D30282738 fbshipit-source-id: 590350dd53217fa8a181e91b194abca753a8adbe --- eden/scm/lib/manifest-tree/src/lib.rs | 5 ++++- eden/scm/lib/manifest-tree/src/store.rs | 26 +++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/eden/scm/lib/manifest-tree/src/lib.rs b/eden/scm/lib/manifest-tree/src/lib.rs index 5d3c19a605..e6443725ee 100644 --- a/eden/scm/lib/manifest-tree/src/lib.rs +++ b/eden/scm/lib/manifest-tree/src/lib.rs @@ -29,7 +29,10 @@ use pathmatcher::Matcher; use types::{HgId, Key, PathComponent, PathComponentBuf, RepoPath, RepoPathBuf}; pub(crate) use self::link::Link; -pub use self::{diff::Diff, store::TreeStore}; +pub use self::{ + diff::Diff, + store::{Entry as TreeEntry, TreeStore}, +}; use crate::{ iter::{BfsIter, DfsCursor, Step}, link::{DirLink, Durable, DurableEntry, Ephemeral, Leaf}, diff --git a/eden/scm/lib/manifest-tree/src/store.rs b/eden/scm/lib/manifest-tree/src/store.rs index b2c513b38d..06d8c98af7 100644 --- a/eden/scm/lib/manifest-tree/src/store.rs +++ b/eden/scm/lib/manifest-tree/src/store.rs @@ -6,6 +6,7 @@ */ use std::{ + convert::TryFrom, str::{from_utf8, FromStr}, sync::Arc, }; @@ -13,7 +14,7 @@ use std::{ use anyhow::{format_err, Result}; use bytes::{Bytes, BytesMut}; -use manifest::FileType; +use manifest::{FileMetadata, FileType, FsNodeMetadata}; use types::{HgId, Key, PathComponent, PathComponentBuf, RepoPath}; /// The `TreeStore` is an abstraction layer for the tree manifest that decouples how or where the @@ -100,7 +101,7 @@ impl InnerStore { /// representation. For this serialization format it is important that they don't contain /// `\0` or `\n`. #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct Entry(Bytes); +pub struct Entry(pub Bytes); pub struct EntryMut(BytesMut); @@ -200,6 +201,27 @@ impl<'a> Iterator for Elements<'a> { } } +impl TryFrom for manifest::List { + type Error = anyhow::Error; + + fn try_from(v: Entry) -> Result { + let mut entries = Vec::new(); + for entry in v.elements() { + let entry = entry?; + entries.push(( + entry.component, + match entry.flag { + Flag::Directory => FsNodeMetadata::Directory(Some(entry.hgid)), + Flag::File(file_type) => { + FsNodeMetadata::File(FileMetadata::new(entry.hgid, file_type)) + } + }, + )) + } + Ok(manifest::List::Directory(entries)) + } +} + impl Element { pub fn new(component: PathComponentBuf, hgid: HgId, flag: Flag) -> Element { Element {