mirror of
https://github.com/facebook/sapling.git
synced 2024-12-25 14:05:00 +03:00
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:
parent
7f0f541fa1
commit
f27e1eb2e0
@ -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"
|
||||
|
@ -15,5 +15,6 @@
|
||||
|
||||
mod backingstore;
|
||||
mod raw;
|
||||
mod treecontentstore;
|
||||
|
||||
pub use crate::backingstore::BackingStore;
|
||||
|
37
eden/scm/lib/backingstore/src/treecontentstore.rs
Normal file
37
eden/scm/lib/backingstore/src/treecontentstore.rs
Normal 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."))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user