2019-10-20 04:46:34 +03:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2019-10-20 04:46:34 +03:00
|
|
|
#include "HgNativeBackingStore.h"
|
2019-10-20 04:46:34 +03:00
|
|
|
|
2019-10-20 04:46:34 +03:00
|
|
|
#include <folly/Optional.h>
|
2019-10-20 04:46:34 +03:00
|
|
|
#include <folly/Range.h>
|
2019-10-20 04:46:34 +03:00
|
|
|
#include <folly/io/IOBuf.h>
|
|
|
|
#include <folly/logging/xlog.h>
|
2019-10-20 04:46:34 +03:00
|
|
|
#include <memory>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace eden {
|
|
|
|
|
|
|
|
HgNativeBackingStore::HgNativeBackingStore(folly::StringPiece repository) {
|
|
|
|
RustCFallible<RustBackingStore> store(
|
|
|
|
rust_backingstore_new(repository.data(), repository.size()),
|
|
|
|
rust_backingstore_free);
|
|
|
|
|
|
|
|
if (store.isError()) {
|
|
|
|
throw std::runtime_error(store.getError());
|
|
|
|
}
|
|
|
|
|
|
|
|
store_ = store.unwrap();
|
|
|
|
}
|
2019-10-20 04:46:34 +03:00
|
|
|
|
2019-10-20 04:46:34 +03:00
|
|
|
folly::Optional<folly::IOBuf> HgNativeBackingStore::getBlob(
|
2019-10-20 04:46:34 +03:00
|
|
|
folly::ByteRange name,
|
|
|
|
folly::ByteRange node) {
|
|
|
|
RustCFallible<RustCBytes> result(
|
|
|
|
rust_backingstore_get_blob(
|
|
|
|
store_.get(), name.data(), name.size(), node.data(), node.size()),
|
|
|
|
rust_cbytes_free);
|
|
|
|
|
|
|
|
if (result.isError()) {
|
2019-10-23 00:59:07 +03:00
|
|
|
XLOG(DBG5) << "Error while getting blob name=" << name.data()
|
|
|
|
<< " node=" << folly::hexlify(node)
|
|
|
|
<< " from backingstore: " << result.getError();
|
2019-10-20 04:46:34 +03:00
|
|
|
return folly::none;
|
2019-10-20 04:46:34 +03:00
|
|
|
}
|
|
|
|
auto buffer = result.get();
|
|
|
|
auto iobuf =
|
|
|
|
folly::IOBuf{folly::IOBuf::COPY_BUFFER, buffer->ptr, buffer->len};
|
|
|
|
|
|
|
|
return iobuf;
|
|
|
|
}
|
2019-11-01 02:39:59 +03:00
|
|
|
|
|
|
|
folly::Optional<folly::IOBuf> HgNativeBackingStore::getTree(
|
|
|
|
folly::ByteRange name,
|
|
|
|
folly::ByteRange node) {
|
|
|
|
RustCFallible<RustCBytes> result(
|
|
|
|
rust_backingstore_get_tree(
|
|
|
|
store_.get(), name.data(), name.size(), node.data(), node.size()),
|
|
|
|
rust_cbytes_free);
|
|
|
|
|
|
|
|
if (result.isError()) {
|
|
|
|
XLOG(DBG5) << "Error while getting tree name=" << name.data()
|
|
|
|
<< " node=" << folly::hexlify(node)
|
|
|
|
<< " from backingstore: " << result.getError();
|
|
|
|
return folly::none;
|
|
|
|
}
|
|
|
|
auto buffer = result.get();
|
|
|
|
auto iobuf =
|
|
|
|
folly::IOBuf{folly::IOBuf::COPY_BUFFER, buffer->ptr, buffer->len};
|
|
|
|
|
|
|
|
return iobuf;
|
|
|
|
}
|
2019-10-20 04:46:34 +03:00
|
|
|
} // namespace eden
|
|
|
|
} // namespace facebook
|