mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 16:31:02 +03:00
e3f4a56f6b
Summary: We are unifying C++ APIs for accessing optional and unqualified fields: https://fb.workplace.com/groups/1730279463893632/permalink/2541675446087359/. This diff migrates code from accessing data members generated from unqualified Thrift fields directly to the `field_ref` API, i.e. replacing ``` thrift_obj.field ``` with ``` *thrift_obj.field_ref() ``` The `_ref` suffixes will be removed in the future once data members are private and names can be reclaimed. The output of this codemod has been reviewed in D20039637. The new API is documented in https://our.intern.facebook.com/intern/wiki/Thrift/FieldAccess/. drop-conflicts Reviewed By: yfeldblum Differential Revision: D22631599 fbshipit-source-id: 9bfcaeb636f34a32fd871c7cd6a2db4a7ace30bf
69 lines
1.8 KiB
C++
69 lines
1.8 KiB
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 "eden/fs/service/PrettyPrinters.h"
|
|
|
|
#include <folly/Conv.h>
|
|
#include <ostream>
|
|
|
|
namespace {
|
|
template <typename ThriftEnum>
|
|
std::ostream& outputThriftEnum(
|
|
std::ostream& os,
|
|
ThriftEnum value,
|
|
folly::StringPiece typeName) {
|
|
const char* name = apache::thrift::TEnumTraits<ThriftEnum>::findName(value);
|
|
if (name) {
|
|
return os << name;
|
|
} else {
|
|
return os << typeName << "::" << int(value);
|
|
}
|
|
}
|
|
|
|
template <typename ThriftEnum>
|
|
void appendThriftEnum(
|
|
ThriftEnum value,
|
|
std::string* result,
|
|
folly::StringPiece typeName) {
|
|
const char* name = apache::thrift::TEnumTraits<ThriftEnum>::findName(value);
|
|
if (name) {
|
|
result->append(name);
|
|
} else {
|
|
result->append(folly::to<std::string>(typeName, "::", int(value)));
|
|
}
|
|
}
|
|
} // unnamed namespace
|
|
|
|
namespace facebook {
|
|
namespace eden {
|
|
|
|
std::ostream& operator<<(std::ostream& os, ConflictType conflictType) {
|
|
return outputThriftEnum(os, conflictType, "ConflictType");
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream& os, const CheckoutConflict& conflict) {
|
|
os << "CheckoutConflict(type=" << *conflict.type_ref() << ", path=\""
|
|
<< *conflict.path_ref() << "\", message=\"" << *conflict.message_ref()
|
|
<< "\")";
|
|
return os;
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream& os, ScmFileStatus scmFileStatus) {
|
|
return outputThriftEnum(os, scmFileStatus, "ScmFileStatus");
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream& os, MountState mountState) {
|
|
return outputThriftEnum(os, mountState, "MountState");
|
|
}
|
|
|
|
void toAppend(MountState mountState, std::string* result) {
|
|
appendThriftEnum(mountState, result, "MountState");
|
|
}
|
|
|
|
} // namespace eden
|
|
} // namespace facebook
|