storemodel: provide git vs hg info for TreeStore

Summary:
Make TreeStore provides info whether it wants git or hg serialization.
Will be used by `flush()`.

Reviewed By: DurhamG

Differential Revision: D33237326

fbshipit-source-id: f63782dbbd5bb2711ddcc8f7c0581ef077d58dcc
This commit is contained in:
Jun Wu 2021-12-21 12:35:00 -08:00 committed by Facebook GitHub Bot
parent 95303588a6
commit 487be9b206
4 changed files with 28 additions and 15 deletions

View File

@ -12,6 +12,7 @@ use futures::stream::BoxStream;
use futures::stream::StreamExt;
use storemodel::ReadFileContents;
use storemodel::TreeStore;
use storemodel::TreeFormat;
use types::HgId;
use types::Key;
use types::RepoPath;
@ -48,4 +49,8 @@ impl TreeStore for GitStore {
}
Ok(())
}
fn format(&self) -> TreeFormat {
TreeFormat::Git
}
}

View File

@ -26,7 +26,6 @@ rand = { version = "0.8", features = ["small_rng"], optional = true }
sha-1 = "0.8"
storemodel = { path = "../storemodel" }
thiserror = "1.0.29"
tokio = { version = "1.10", features = ["full", "test-util", "tracing"] }
tracing = "0.1.29"
types = { path = "../types" }

View File

@ -16,26 +16,14 @@ use bytes::BytesMut;
use manifest::FileMetadata;
use manifest::FileType;
use manifest::FsNodeMetadata;
use storemodel::TreeFormat;
pub use storemodel::TreeStore;
use types::HgId;
use types::Key;
use types::PathComponent;
use types::PathComponentBuf;
use types::RepoPath;
pub use storemodel::TreeStore;
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum TreeFormat {
// NAME '\0' HEX_SHA1 MODE '\n'
// MODE: 't' (tree), 'l' (symlink), 'x' (executable)
Hg,
// MODE ' ' NAME '\0' BIN_SHA1
// MODE: '40000' (tree), '100644' (regular), '100755' (executable),
// '120000' (symlink), '160000' (gitlink)
Git,
}
#[derive(Clone)]
pub struct InnerStore {
tree_store: Arc<dyn TreeStore + Send + Sync>,
@ -46,6 +34,10 @@ impl InnerStore {
InnerStore { tree_store }
}
pub fn format(&self) -> TreeFormat {
self.tree_store.format()
}
pub fn get_entry(&self, path: &RepoPath, hgid: HgId) -> Result<Entry> {
tracing::debug_span!(
"tree::store::get",

View File

@ -64,4 +64,21 @@ pub trait TreeStore {
fn prefetch(&self, _keys: Vec<Key>) -> anyhow::Result<()> {
Ok(())
}
/// Decides whether the store uses git or hg format.
fn format(&self) -> TreeFormat {
TreeFormat::Hg
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum TreeFormat {
// NAME '\0' HEX_SHA1 MODE '\n'
// MODE: 't' (tree), 'l' (symlink), 'x' (executable)
Hg,
// MODE ' ' NAME '\0' BIN_SHA1
// MODE: '40000' (tree), '100644' (regular), '100755' (executable),
// '120000' (symlink), '160000' (gitlink)
Git,
}