From f27e1eb2e0f7a01528c1aba0912ad2e043457c6a Mon Sep 17 00:00:00 2001 From: "Zeyi (Rice) Fan" Date: Tue, 19 Nov 2019 17:56:59 -0800 Subject: [PATCH] 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 --- eden/scm/lib/backingstore/Cargo.toml | 3 +- eden/scm/lib/backingstore/src/lib.rs | 1 + .../lib/backingstore/src/treecontentstore.rs | 37 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 eden/scm/lib/backingstore/src/treecontentstore.rs diff --git a/eden/scm/lib/backingstore/Cargo.toml b/eden/scm/lib/backingstore/Cargo.toml index 6db9b5f1ce..f3d2e00c2d 100644 --- a/eden/scm/lib/backingstore/Cargo.toml +++ b/eden/scm/lib/backingstore/Cargo.toml @@ -5,8 +5,9 @@ authors = ["Facebook Source Control Team "] 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" diff --git a/eden/scm/lib/backingstore/src/lib.rs b/eden/scm/lib/backingstore/src/lib.rs index 1b924ce19e..5e214f4717 100644 --- a/eden/scm/lib/backingstore/src/lib.rs +++ b/eden/scm/lib/backingstore/src/lib.rs @@ -15,5 +15,6 @@ mod backingstore; mod raw; +mod treecontentstore; pub use crate::backingstore::BackingStore; diff --git a/eden/scm/lib/backingstore/src/treecontentstore.rs b/eden/scm/lib/backingstore/src/treecontentstore.rs new file mode 100644 index 0000000000..1208f7e8d2 --- /dev/null +++ b/eden/scm/lib/backingstore/src/treecontentstore.rs @@ -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 { + 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.")) + } +}