mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 16:57:49 +03:00
07452335fb
Summary: This commit switch from explicitly specifying `ImportPriority` into passing priorities from `ObjectFetchContext`. Reviewed By: xavierd Differential Revision: D21872720 fbshipit-source-id: 26055eff21cab4ce6370e96ac3acbac2fd6af3f0
104 lines
2.9 KiB
C++
104 lines
2.9 KiB
C++
/*
|
|
* 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.
|
|
*/
|
|
|
|
#include "FakeObjectStore.h"
|
|
|
|
#include <folly/String.h>
|
|
#include <folly/futures/Future.h>
|
|
|
|
using folly::Future;
|
|
using folly::makeFuture;
|
|
using std::make_shared;
|
|
using std::shared_ptr;
|
|
|
|
namespace facebook {
|
|
namespace eden {
|
|
|
|
FakeObjectStore::FakeObjectStore() {}
|
|
|
|
FakeObjectStore::~FakeObjectStore() {}
|
|
|
|
void FakeObjectStore::addTree(Tree&& tree) {
|
|
auto treeHash = tree.getHash();
|
|
trees_.emplace(std::move(treeHash), std::move(tree));
|
|
}
|
|
|
|
void FakeObjectStore::addBlob(Blob&& blob) {
|
|
auto blobHash = blob.getHash();
|
|
blobs_.emplace(blobHash, std::move(blob));
|
|
}
|
|
|
|
void FakeObjectStore::setTreeForCommit(const Hash& commitID, Tree&& tree) {
|
|
auto ret = commits_.emplace(commitID, std::move(tree));
|
|
if (!ret.second) {
|
|
// Warn the caller that a Tree has already been specified for this commit,
|
|
// which is likely a logical error. If this turns out to be something that
|
|
// we want to do in a test, then we can change this behavior.
|
|
throw std::runtime_error(folly::to<std::string>(
|
|
"tree already added for commit with id ", commitID));
|
|
}
|
|
}
|
|
|
|
Future<std::shared_ptr<const Tree>> FakeObjectStore::getTree(
|
|
const Hash& id,
|
|
ObjectFetchContext&) const {
|
|
++accessCounts_[id];
|
|
auto iter = trees_.find(id);
|
|
if (iter == trees_.end()) {
|
|
return makeFuture<shared_ptr<const Tree>>(
|
|
std::domain_error("tree " + id.toString() + " not found"));
|
|
}
|
|
return makeFuture(make_shared<Tree>(iter->second));
|
|
}
|
|
|
|
Future<std::shared_ptr<const Blob>> FakeObjectStore::getBlob(
|
|
const Hash& id,
|
|
ObjectFetchContext&) const {
|
|
++accessCounts_[id];
|
|
auto iter = blobs_.find(id);
|
|
if (iter == blobs_.end()) {
|
|
return makeFuture<shared_ptr<const Blob>>(
|
|
std::domain_error("blob " + id.toString() + " not found"));
|
|
}
|
|
return makeFuture(make_shared<Blob>(iter->second));
|
|
}
|
|
|
|
Future<shared_ptr<const Tree>> FakeObjectStore::getTreeForCommit(
|
|
const Hash& commitID,
|
|
ObjectFetchContext&) const {
|
|
++accessCounts_[commitID];
|
|
auto iter = commits_.find(commitID);
|
|
if (iter == commits_.end()) {
|
|
return makeFuture<shared_ptr<const Tree>>(std::domain_error(
|
|
"tree data for commit " + commitID.toString() + " not found"));
|
|
}
|
|
return makeFuture(make_shared<Tree>(iter->second));
|
|
}
|
|
|
|
folly::Future<std::shared_ptr<const Tree>> FakeObjectStore::getTreeForManifest(
|
|
const Hash& commitID,
|
|
const Hash& /* manifestID */,
|
|
ObjectFetchContext&) const {
|
|
return getTreeForCommit(commitID);
|
|
}
|
|
|
|
folly::Future<folly::Unit> FakeObjectStore::prefetchBlobs(
|
|
const std::vector<Hash>&,
|
|
ObjectFetchContext&) const {
|
|
return folly::unit;
|
|
}
|
|
|
|
size_t FakeObjectStore::getAccessCount(const Hash& hash) const {
|
|
if (auto* item = folly::get_ptr(accessCounts_, hash)) {
|
|
return *item;
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
} // namespace eden
|
|
} // namespace facebook
|