mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 16:31:02 +03:00
fbdb46f5cb
Reviewed By: chadaustin Differential Revision: D17872966 fbshipit-source-id: cd60a364a2146f0dadbeca693b1d4a5d7c97ff63
31 lines
834 B
C++
31 lines
834 B
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 "TestUtil.h"
|
|
|
|
#include <cstring>
|
|
#include <stdexcept>
|
|
#include "eden/fs/model/Hash.h"
|
|
|
|
namespace facebook {
|
|
namespace eden {
|
|
Hash makeTestHash(folly::StringPiece value) {
|
|
constexpr size_t ASCII_SIZE = 2 * Hash::RAW_SIZE;
|
|
if (value.size() > ASCII_SIZE) {
|
|
throw std::invalid_argument(value.toString() + " is too big for Hash");
|
|
}
|
|
std::array<char, ASCII_SIZE> fullValue;
|
|
memset(fullValue.data(), '0', fullValue.size());
|
|
memcpy(
|
|
fullValue.data() + fullValue.size() - value.size(),
|
|
value.data(),
|
|
value.size());
|
|
return Hash{folly::StringPiece{folly::range(fullValue)}};
|
|
}
|
|
} // namespace eden
|
|
} // namespace facebook
|