backingstore: add TreeContentStore to impl TreeStore

Summary: `manifest::Tree` wants to have a store that implements `TreeStore`. However at current we don't want to introduce dependency between `manifest` and `contentstore`. So we create this wrapper struct to provide the trait implementation. This will allow us to use `manifest` to parse manifest data we get from hg store.

Reviewed By: chadaustin, xavierd

Differential Revision: D18365354

fbshipit-source-id: 3687032c7f51570ef51ccc4004efc87f64ef2188
This commit is contained in:
Zeyi (Rice) Fan 2019-11-19 17:56:59 -08:00 committed by Facebook Github Bot
parent 7f0f541fa1
commit f27e1eb2e0
3 changed files with 40 additions and 1 deletions

View File

@ -5,8 +5,9 @@ authors = ["Facebook Source Control Team <sourcecontrol-dev@fb.com>"]
edition = "2018"
[dependencies]
revisionstore = { path = "../revisionstore" }
configparser = { path = "../configparser" }
manifest = { path = "../manifest" }
revisionstore = { path = "../revisionstore" }
types = { path = "../types" }
bytes = "0.4.12"
failure = "0.1.6"

View File

@ -15,5 +15,6 @@
mod backingstore;
mod raw;
mod treecontentstore;
pub use crate::backingstore::BackingStore;

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
use bytes::Bytes;
use failure::{format_err, Fallible};
use manifest::TreeStore;
use revisionstore::{ContentStore, DataStore};
use types::{HgId, Key, RepoPath};
pub(crate) struct TreeContentStore {
inner: ContentStore,
}
impl TreeContentStore {
pub fn new(inner: ContentStore) -> Self {
TreeContentStore { inner }
}
}
impl TreeStore for TreeContentStore {
fn get(&self, path: &RepoPath, hgid: HgId) -> Fallible<Bytes> {
let key = Key::new(path.to_owned(), hgid);
self.inner.get(&key).and_then(|opt| {
opt.ok_or_else(|| format_err!("hgid: {:?} path: {:?} is not found.", path, hgid))
.map(Into::into)
})
}
fn insert(&self, _path: &RepoPath, _hgid: HgId, _data: Bytes) -> Fallible<()> {
Err(format_err!("insert is not implemented."))
}
}