mirror of
https://github.com/facebook/sapling.git
synced 2024-10-04 22:07:44 +03:00
replace most folly:format uses
Summary: folly:format is deprecated in lieu of fmt and std::format. Migrate most of EdenFS to fmt instead. Differential Revision: D31025948 fbshipit-source-id: 82ed674d5e255ac129995b56bc8b9731a5fbf82e
This commit is contained in:
parent
dbb6564fba
commit
49e49f9fc2
@ -92,15 +92,14 @@ RootId CheckoutConfig::getParentCommit() const {
|
||||
StringPiece contents{snapshotFileContents};
|
||||
|
||||
if (contents.size() < kSnapshotHeaderSize) {
|
||||
throw std::runtime_error(folly::sformat(
|
||||
throw std::runtime_error(fmt::format(
|
||||
"eden SNAPSHOT file is too short ({} bytes): {}",
|
||||
contents.size(),
|
||||
snapshotFile));
|
||||
}
|
||||
|
||||
if (!contents.startsWith(kSnapshotFileMagic)) {
|
||||
throw std::runtime_error(
|
||||
folly::sformat("unsupported legacy SNAPSHOT file"));
|
||||
throw std::runtime_error(fmt::format("unsupported legacy SNAPSHOT file"));
|
||||
}
|
||||
|
||||
IOBuf buf(IOBuf::WRAP_BUFFER, ByteRange{contents});
|
||||
@ -111,7 +110,7 @@ RootId CheckoutConfig::getParentCommit() const {
|
||||
switch (version) {
|
||||
case kSnapshotFormatVersion1: {
|
||||
if (sizeLeft != Hash::RAW_SIZE && sizeLeft != (Hash::RAW_SIZE * 2)) {
|
||||
throw std::runtime_error(folly::sformat(
|
||||
throw std::runtime_error(fmt::format(
|
||||
"unexpected length for eden SNAPSHOT file ({} bytes): {}",
|
||||
contents.size(),
|
||||
snapshotFile));
|
||||
@ -141,7 +140,7 @@ RootId CheckoutConfig::getParentCommit() const {
|
||||
}
|
||||
|
||||
default:
|
||||
throw std::runtime_error(folly::sformat(
|
||||
throw std::runtime_error(fmt::format(
|
||||
"unsupported eden SNAPSHOT file format (version {}): {}",
|
||||
uint32_t{version},
|
||||
snapshotFile));
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include "eden/fs/fuse/FuseDispatcher.h"
|
||||
|
||||
#include <folly/Exception.h>
|
||||
#include <folly/Format.h>
|
||||
#include <folly/executors/GlobalExecutor.h>
|
||||
#include <folly/futures/Future.h>
|
||||
#include <folly/logging/xlog.h>
|
||||
|
@ -533,7 +533,7 @@ folly::File PrivHelperServer::fuseMount(const char* mountPath, bool readOnly) {
|
||||
// requester. We could add this functionality in the future if we have a
|
||||
// need for it, but we would need to validate their changes are safe.
|
||||
const int rootMode = S_IFDIR;
|
||||
auto mountOpts = folly::sformat(
|
||||
auto mountOpts = fmt::format(
|
||||
"allow_other,default_permissions,"
|
||||
"rootmode={:o},user_id={},group_id={},fd={}",
|
||||
rootMode,
|
||||
|
@ -235,7 +235,7 @@ GlobNode::GlobNode(StringPiece pattern, bool includeDotfiles, bool hasSpecials)
|
||||
throw std::system_error(
|
||||
EINVAL,
|
||||
std::generic_category(),
|
||||
folly::sformat(
|
||||
fmt::format(
|
||||
"failed to compile pattern `{}` to GlobMatcher: {}",
|
||||
pattern,
|
||||
compiled.error()));
|
||||
|
@ -148,7 +148,7 @@ class OverlayChecker::RepairState {
|
||||
|
||||
// Name the repair directory based on the current timestamp
|
||||
auto now = getLocalTime(time(nullptr));
|
||||
auto timestampStr = folly::sformat(
|
||||
auto timestampStr = fmt::format(
|
||||
"{:04d}{:02d}{:02d}_{:02d}{:02d}{:02d}",
|
||||
now.tm_year + 1900,
|
||||
now.tm_mon + 1,
|
||||
@ -190,7 +190,7 @@ class OverlayChecker::RepairState {
|
||||
auto nowSec = std::chrono::duration_cast<seconds>(now);
|
||||
auto us = std::chrono::duration_cast<microseconds>(now - nowSec);
|
||||
auto timeFields = getLocalTime(nowSec.count());
|
||||
auto header = folly::sformat(
|
||||
auto header = fmt::format(
|
||||
"{:04d}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}.{:06d}: ",
|
||||
timeFields.tm_year + 1900,
|
||||
timeFields.tm_mon + 1,
|
||||
|
@ -249,7 +249,7 @@ std::optional<uint64_t> SqliteOverlay::readNextInodeNumber(
|
||||
// Return the result; columns are 0-based!
|
||||
auto blob = stmt.columnBlob(0);
|
||||
if (blob.size() != sizeof(uint64_t)) {
|
||||
throw std::logic_error(folly::sformat(
|
||||
throw std::logic_error(fmt::format(
|
||||
"Unable to fetch the next inode number from the db, size: {}",
|
||||
blob.size()));
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ inline void PrintTo(
|
||||
throw std::runtime_error("strftime failed");
|
||||
}
|
||||
|
||||
*os << buf.data() << folly::sformat(".{:09d}", ts.tv_nsec);
|
||||
*os << buf.data() << fmt::format(".{:09d}", ts.tv_nsec);
|
||||
}
|
||||
} // namespace std
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
#include "eden/fs/inodes/FileInode.h"
|
||||
|
||||
#include <folly/Format.h>
|
||||
#include <fmt/format.h>
|
||||
#include <folly/Range.h>
|
||||
#include <folly/portability/GTest.h>
|
||||
#include <folly/test/TestUtils.h>
|
||||
@ -29,8 +29,7 @@ using folly::literals::string_piece_literals::operator""_sp;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const timespec& ts) {
|
||||
os << folly::sformat("{}.{:09d}", ts.tv_sec, ts.tv_nsec);
|
||||
return os;
|
||||
return os << fmt::format("{}.{:09d}", ts.tv_sec, ts.tv_nsec);
|
||||
}
|
||||
|
||||
namespace std {
|
||||
@ -41,8 +40,7 @@ std::ostream& operator<<(
|
||||
auto duration = tp.time_since_epoch();
|
||||
auto secs = duration_cast<std::chrono::seconds>(duration);
|
||||
auto nsecs = duration_cast<std::chrono::nanoseconds>(duration - secs);
|
||||
os << folly::sformat("{}.{:09d}", secs.count(), nsecs.count());
|
||||
return os;
|
||||
return os << fmt::format("{}.{:09d}", secs.count(), nsecs.count());
|
||||
}
|
||||
} // namespace chrono
|
||||
} // namespace std
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#include "eden/fs/inodes/InodeMap.h"
|
||||
|
||||
#include <folly/Format.h>
|
||||
#include <folly/String.h>
|
||||
#include <folly/portability/GTest.h>
|
||||
#include <folly/test/TestUtils.h>
|
||||
|
@ -5,7 +5,6 @@
|
||||
* GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#include <folly/Format.h>
|
||||
#include <folly/String.h>
|
||||
#include <folly/portability/GTest.h>
|
||||
#include <folly/test/TestUtils.h>
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#include <folly/Format.h>
|
||||
#include <folly/String.h>
|
||||
#include <folly/portability/GTest.h>
|
||||
#include <folly/test/TestUtils.h>
|
||||
|
@ -5,8 +5,8 @@
|
||||
* GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#include "GitTree.h"
|
||||
#include <folly/Format.h>
|
||||
#include "eden/fs/model/git/GitTree.h"
|
||||
#include <fmt/format.h>
|
||||
#include <folly/String.h>
|
||||
#include <array>
|
||||
#include <cstdio>
|
||||
@ -83,12 +83,12 @@ std::unique_ptr<Tree> deserializeGitTree(
|
||||
} else if (mode == GitModeMask::SYMLINK) {
|
||||
fileType = TreeEntryType::SYMLINK;
|
||||
} else if (mode == GitModeMask::GIT_LINK) {
|
||||
throw std::domain_error(folly::sformat(
|
||||
throw std::domain_error(fmt::format(
|
||||
"Gitlinks are not currently supported: {:o} in object {}",
|
||||
mode,
|
||||
hash.toString()));
|
||||
} else {
|
||||
throw invalid_argument(folly::sformat(
|
||||
throw invalid_argument(fmt::format(
|
||||
"Unrecognized mode: {:o} in object {}", mode, hash.toString()));
|
||||
}
|
||||
|
||||
|
@ -421,7 +421,7 @@ namespace cursor_helper {
|
||||
// https://vt100.net/docs/vt510-rm/CPL.html
|
||||
// The cursor is moved to the start of the nth preceding line
|
||||
std::string move_cursor_up(size_t n) {
|
||||
return folly::sformat("\x1b\x5b{}F", n);
|
||||
return fmt::format("\x1b\x5b{}F", n);
|
||||
}
|
||||
|
||||
// https://vt100.net/docs/vt510-rm/ED.html
|
||||
|
@ -222,8 +222,8 @@ class ThriftLogHelper {
|
||||
~ThriftLogHelper() {
|
||||
// Logging completion time for the request
|
||||
// The line number points to where the object was originally created
|
||||
TLOG(itcLogger_, level_, itcFileName_, itcLineNumber_) << folly::sformat(
|
||||
"{}() took {:,} " EDEN_MICRO,
|
||||
TLOG(itcLogger_, level_, itcFileName_, itcLineNumber_) << fmt::format(
|
||||
"{}() took {} " EDEN_MICRO,
|
||||
itcFunctionName_,
|
||||
itcTimer_.elapsed().count());
|
||||
}
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#include "eden/fs/store/LocalStore.h"
|
||||
|
||||
#include <folly/Format.h>
|
||||
#include <folly/String.h>
|
||||
#include <folly/futures/Future.h>
|
||||
#include <folly/io/Cursor.h>
|
||||
|
@ -9,7 +9,6 @@
|
||||
|
||||
#include <folly/Conv.h>
|
||||
#include <folly/Executor.h>
|
||||
#include <folly/Format.h>
|
||||
#include <folly/futures/Future.h>
|
||||
#include <folly/io/IOBuf.h>
|
||||
|
||||
|
@ -35,7 +35,7 @@ BlobMetadata SerializedBlobMetadata::parse(
|
||||
const StoreResult& result) {
|
||||
auto bytes = result.bytes();
|
||||
if (bytes.size() != SIZE) {
|
||||
throw std::invalid_argument(folly::sformat(
|
||||
throw std::invalid_argument(fmt::format(
|
||||
"Blob metadata for {} had unexpected size {}. Could not deserialize.",
|
||||
blobID.toString(),
|
||||
bytes.size()));
|
||||
|
@ -117,7 +117,7 @@ TakeoverData TakeoverData::deserialize(IOBuf* buf) {
|
||||
buf->trimStart(sizeof(uint32_t));
|
||||
return deserializeVersion3(buf);
|
||||
default:
|
||||
throw std::runtime_error(folly::sformat(
|
||||
throw std::runtime_error(fmt::format(
|
||||
"Unrecognized TakeoverData response starting with {:x}",
|
||||
messageType));
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "FakeBackingStore.h"
|
||||
|
||||
#include <folly/Format.h>
|
||||
#include <fmt/format.h>
|
||||
#include <folly/MapUtil.h>
|
||||
#include <folly/futures/Future.h>
|
||||
#include <folly/logging/xlog.h>
|
||||
@ -129,7 +129,7 @@ StoredBlob* FakeBackingStore::putBlob(Hash hash, folly::StringPiece contents) {
|
||||
auto ret = maybePutBlob(hash, contents);
|
||||
if (!ret.second) {
|
||||
throw std::domain_error(
|
||||
folly::sformat("blob with hash {} already exists", hash.toString()));
|
||||
fmt::format("blob with hash {} already exists", hash.toString()));
|
||||
}
|
||||
return ret.first;
|
||||
}
|
||||
@ -277,7 +277,7 @@ StoredTree* FakeBackingStore::putTreeImpl(
|
||||
auto ret = maybePutTreeImpl(hash, std::move(sortedEntries));
|
||||
if (!ret.second) {
|
||||
throw std::domain_error(
|
||||
folly::sformat("tree with hash {} already exists", hash.toString()));
|
||||
fmt::format("tree with hash {} already exists", hash.toString()));
|
||||
}
|
||||
return ret.first;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <folly/Format.h>
|
||||
#include <fmt/format.h>
|
||||
#include <folly/Range.h>
|
||||
#include <folly/io/IOBuf.h>
|
||||
#include <folly/portability/GTest.h>
|
||||
@ -27,8 +27,8 @@
|
||||
.get(std::chrono::seconds(20))}) \
|
||||
<< " for inode path " << (fileInode)->getLogPath(); \
|
||||
EXPECT_EQ( \
|
||||
folly::sformat("{:#o}", (expectedPerms)), \
|
||||
folly::sformat("{:#o}", (fileInode)->getPermissions())) \
|
||||
fmt::format("{:#o}", (expectedPerms)), \
|
||||
fmt::format("{:#o}", (fileInode)->getPermissions())) \
|
||||
<< " for inode path " << (fileInode)->getLogPath(); \
|
||||
} while (0)
|
||||
#else
|
||||
|
@ -21,24 +21,24 @@ std::string durationStr(std::chrono::nanoseconds duration) {
|
||||
// deciding how much precision to show in the output.
|
||||
|
||||
if (duration < 1us) {
|
||||
return folly::sformat("{}ns", duration.count());
|
||||
return fmt::format("{}ns", duration.count());
|
||||
} else if (duration < 1ms) {
|
||||
return folly::sformat("{:.3}us", duration.count() / 1000.0);
|
||||
return fmt::format("{:.3}us", duration.count() / 1000.0);
|
||||
} else if (duration < 1s) {
|
||||
return folly::sformat("{:.3}ms", duration.count() / 1000000.0);
|
||||
return fmt::format("{:.3}ms", duration.count() / 1000000.0);
|
||||
} else if (duration < 1min) {
|
||||
return folly::sformat("{:.3}s", duration.count() / 1000000000.0);
|
||||
return fmt::format("{:.3}s", duration.count() / 1000000000.0);
|
||||
} else if (duration < 1h) {
|
||||
auto minutes = std::chrono::duration_cast<std::chrono::minutes>(duration);
|
||||
auto remainder = duration - minutes;
|
||||
return folly::sformat(
|
||||
return fmt::format(
|
||||
"{}m{:.3}s", minutes.count(), remainder.count() / 1000000000.0);
|
||||
} else if (duration < 24h) {
|
||||
auto hours = std::chrono::duration_cast<std::chrono::hours>(duration);
|
||||
auto remainder = duration - hours;
|
||||
auto minutes = std::chrono::duration_cast<std::chrono::minutes>(remainder);
|
||||
remainder -= minutes;
|
||||
return folly::sformat(
|
||||
return fmt::format(
|
||||
"{}h{}m{:.3}s",
|
||||
hours.count(),
|
||||
minutes.count(),
|
||||
@ -57,7 +57,7 @@ std::string durationStr(std::chrono::nanoseconds duration) {
|
||||
auto minutes = std::chrono::duration_cast<std::chrono::minutes>(remainder);
|
||||
remainder -= minutes;
|
||||
|
||||
return folly::sformat(
|
||||
return fmt::format(
|
||||
"{}d{:02}h{:02}m{:.3}s",
|
||||
days.count(),
|
||||
hours.count(),
|
||||
|
@ -721,6 +721,27 @@ TEST(PathFuncs, format) {
|
||||
EXPECT_EQ("x(src/abc.def)", folly::sformat("x({})", relPiece));
|
||||
}
|
||||
|
||||
TEST(PathFuncs, fmt) {
|
||||
// Test using fmt::format with all of the various path types
|
||||
PathComponentPiece comp("foo");
|
||||
EXPECT_EQ("x(foo)", fmt::format("x({})", comp));
|
||||
|
||||
PathComponentPiece compPiece("bar");
|
||||
EXPECT_EQ("x(bar)", fmt::format("x({})", compPiece));
|
||||
|
||||
AbsolutePath abs("/home/johndoe");
|
||||
EXPECT_EQ("x(/home/johndoe)", fmt::format("x({})", abs));
|
||||
|
||||
AbsolutePathPiece absPiece("/var/log/clowntown");
|
||||
EXPECT_EQ("x(/var/log/clowntown)", fmt::format("x({})", absPiece));
|
||||
|
||||
RelativePath rel("src/ping.c");
|
||||
EXPECT_EQ("x(src/ping.c)", fmt::format("x({})", rel));
|
||||
|
||||
RelativePathPiece relPiece("src/abc.def");
|
||||
EXPECT_EQ("x(src/abc.def)", fmt::format("x({})", relPiece));
|
||||
}
|
||||
|
||||
TEST(PathFuncs, splitFirst) {
|
||||
using SplitResult = decltype(splitFirst(std::declval<RelativePath>()));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user