populate TreeEntry::{size,contentSha1} if present in mononoke data

Summary:
Nothing populates these fields yet today, but will in a later diff.
If present in the json data for an entry, populate them in our TreeEntry.

When processing trees from mononoke, check for these fields being set
and emit them into the current writeBatch so that we set the BlobMetadata.

Reviewed By: chadaustin

Differential Revision: D12814793

fbshipit-source-id: cd19d3f553c22462adc58c024a90cfeb5b8da224
This commit is contained in:
Wez Furlong 2018-10-31 11:48:14 -07:00 committed by Facebook Github Bot
parent 7d10cfea88
commit e3dbed8148
2 changed files with 26 additions and 1 deletions

View File

@ -22,6 +22,7 @@
#include "eden/fs/model/Hash.h"
#include "eden/fs/model/Tree.h"
#include "eden/fs/store/LocalStore.h"
#include "eden/fs/store/SerializedBlobMetadata.h"
#include "eden/fs/store/StoreResult.h"
#include "eden/fs/store/hg/HgImportPyError.h"
#include "eden/fs/store/hg/HgImporter.h"
@ -397,6 +398,17 @@ Future<unique_ptr<Tree>> HgBackingStore::importTreeImpl(
entries.emplace_back(
proxyHash, entryName.stringPiece(), entry.getType());
if (entry.getContentSha1() && entry.getSize()) {
BlobMetadata metadata{*entry.getContentSha1(), *entry.getSize()};
SerializedBlobMetadata metadataBytes(metadata);
auto hashSlice = proxyHash.getBytes();
writeBatch->put(
KeySpace::BlobMetaDataFamily,
hashSlice,
metadataBytes.slice());
}
}
auto tree = make_unique<Tree>(std::move(entries), edenTreeID);

View File

@ -169,6 +169,7 @@ std::unique_ptr<Tree> convertBufToTree(
}
std::vector<TreeEntry> entries;
entries.reserve(parsed.size());
for (auto i = parsed.begin(); i != parsed.end(); ++i) {
auto name = i->at("name").asString();
auto hash = Hash(i->at("hash").asString());
@ -186,7 +187,19 @@ std::unique_ptr<Tree> convertBufToTree(
throw std::runtime_error(folly::to<std::string>(
"unknown file type from mononoke: ", str_type));
}
entries.push_back(TreeEntry(hash, name, file_type));
auto contentSha1 = i->get_ptr("content_sha1");
auto size = i->get_ptr("size");
if (contentSha1 && !contentSha1->isNull() && size && !size->isNull()) {
entries.emplace_back(
hash,
name,
file_type,
static_cast<uint64_t>(size->asInt()),
Hash(contentSha1->asString()));
} else {
entries.emplace_back(hash, name, file_type);
}
}
return std::make_unique<Tree>(std::move(entries), id);
}