mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 00:14:35 +03:00
support importing subdirectory trees in the import tester
Summary: Add logic to the hg import tester tool to support recursively importing specific subdirectories using the tree manifest import mechanism. Reviewed By: wez Differential Revision: D5544818 fbshipit-source-id: 1637d32691c30dfab8d59599891feab6fb27bcdb
This commit is contained in:
parent
497a2ae765
commit
9f1bb674f7
@ -20,6 +20,7 @@
|
||||
#include <rocksdb/utilities/options_util.h> // @manual=@/rocksdb:rocksdb
|
||||
#include <sysexits.h>
|
||||
|
||||
#include "eden/fs/model/Tree.h"
|
||||
#include "eden/fs/store/LocalStore.h"
|
||||
#include "eden/fs/store/hg/HgImporter.h"
|
||||
#include "eden/fs/store/hg/HgManifestImporter.h"
|
||||
@ -36,6 +37,10 @@ DEFINE_string(
|
||||
flat_import_file,
|
||||
"",
|
||||
"Import flat manifest data from a manifest dump in the specified file.");
|
||||
DEFINE_string(
|
||||
subdir,
|
||||
"",
|
||||
"A subdirectory to import when using --import_type=tree.");
|
||||
DEFINE_string(
|
||||
rocksdb_options_file,
|
||||
"",
|
||||
@ -48,8 +53,11 @@ using folly::test::TemporaryDirectory;
|
||||
using folly::Endian;
|
||||
using folly::IOBuf;
|
||||
using folly::io::Cursor;
|
||||
using folly::StringPiece;
|
||||
using std::string;
|
||||
|
||||
namespace {
|
||||
|
||||
std::unique_ptr<rocksdb::DB> createRocksDb(AbsolutePathPiece dbPath) {
|
||||
rocksdb::Options options;
|
||||
if (FLAGS_rocksdb_options_file.empty()) {
|
||||
@ -83,6 +91,40 @@ std::unique_ptr<rocksdb::DB> createRocksDb(AbsolutePathPiece dbPath) {
|
||||
return std::unique_ptr<rocksdb::DB>(db);
|
||||
}
|
||||
|
||||
int importTree(
|
||||
LocalStore* store,
|
||||
AbsolutePathPiece repoPath,
|
||||
StringPiece revName,
|
||||
RelativePath subdir) {
|
||||
HgImporter importer(repoPath, store);
|
||||
|
||||
printf(
|
||||
"Importing revision \"%s\" using tree manifest\n", revName.str().c_str());
|
||||
auto rootHash = importer.importTreeManifest(revName);
|
||||
printf("/: %s\n", rootHash.toString().c_str());
|
||||
|
||||
auto tree = store->getTree(rootHash);
|
||||
for (const auto& component : subdir.components()) {
|
||||
auto entry = tree->getEntryPtr(component);
|
||||
if (!entry) {
|
||||
printf("%s: not found\n", component.stringPiece().str().c_str());
|
||||
return EX_DATAERR;
|
||||
}
|
||||
if (entry->getFileType() != FileType::DIRECTORY) {
|
||||
printf("%s: not a tree\n", component.stringPiece().str().c_str());
|
||||
return EX_DATAERR;
|
||||
}
|
||||
printf(
|
||||
"%s: %s\n",
|
||||
component.stringPiece().str().c_str(),
|
||||
entry->getHash().toString().c_str());
|
||||
tree = importer.importTree(entry->getHash());
|
||||
}
|
||||
|
||||
return EX_OK;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
folly::init(&argc, &argv);
|
||||
folly::initLoggingGlogStyle(FLAGS_logging, folly::LogLevel::INFO, false);
|
||||
@ -117,6 +159,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
LocalStore store(rocksPath);
|
||||
|
||||
int returnCode = EX_OK;
|
||||
if (!FLAGS_flat_import_file.empty()) {
|
||||
folly::File inputFile(FLAGS_flat_import_file);
|
||||
HgImporter::importFlatManifest(inputFile.fd(), &store);
|
||||
@ -126,10 +169,8 @@ int main(int argc, char* argv[]) {
|
||||
auto rootHash = importer.importFlatManifest(revName);
|
||||
printf("Imported root tree: %s\n", rootHash.toString().c_str());
|
||||
} else if (FLAGS_import_type == "tree") {
|
||||
HgImporter importer(repoPath, &store);
|
||||
printf("Importing revision \"%s\" using tree manifest\n", revName.c_str());
|
||||
auto rootHash = importer.importTreeManifest(revName);
|
||||
printf("Imported root tree: %s\n", rootHash.toString().c_str());
|
||||
RelativePath path{FLAGS_subdir};
|
||||
returnCode = importTree(&store, repoPath, revName, path);
|
||||
} else {
|
||||
fprintf(
|
||||
stderr,
|
||||
@ -138,5 +179,5 @@ int main(int argc, char* argv[]) {
|
||||
return EX_USAGE;
|
||||
}
|
||||
|
||||
return EX_OK;
|
||||
return returnCode;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user