Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format the whole codebase with clang-format #2509

Merged
merged 4 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
44 changes: 26 additions & 18 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,38 @@
# This source code is licensed under Apache 2.0 License,
# attached with Common Clause Condition 1.0, found in the LICENSES directory.
#
# This is the output of clang-format-7.0 --style=google --dump-config,
# This is the output of clang-format-9.0 --style=google --dump-config,
# except for changes mentioned below.
# We have locked the version of clang-format in order to avoid inconsistencies
# in the format caused by developers using different clang-format versions.
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterEnum: false
Expand All @@ -46,6 +59,7 @@ BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
Expand All @@ -60,7 +74,7 @@ ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
Expand All @@ -73,6 +87,7 @@ IncludeCategories:
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
Expand All @@ -82,6 +97,7 @@ MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
Expand Down Expand Up @@ -125,6 +141,7 @@ ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
Expand All @@ -133,25 +150,16 @@ SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 4
Standard: Auto
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseTab: Never

#Different from google style
Standard: Cpp11
AccessModifierOffset: -4
AllowAllParametersOfDeclarationOnNextLine: false
ColumnLimit: 100
ObjCBlockIndentWidth: 4
AlignEscapedNewlines: Right
AlwaysBreakBeforeMultilineStrings: false
BinPackArguments: false
BinPackParameters: false
IndentWidth: 4
SpacesBeforeTrailingComments: 3
AllowShortFunctionsOnASingleLine: Empty
...
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ add_custom_target(
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)


add_custom_target(
clang-format
COMMAND "find" "src/" "-type" "f" "\\(" "-iname" "\\*.h" "-o" "-iname" "\\*.cpp" "\\)" "-exec" "clang-format" "-i" "{}" "\\;"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)

if (ENABLE_NATIVE)
message(STATUS "ENABLE_NATIVE is ${ENABLE_NATIVE}")
add_compile_options(-fPIC)
Expand Down
76 changes: 37 additions & 39 deletions src/clients/meta/FileBasedClusterIdMan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,56 @@
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
*/

#include "common/base/Base.h"
#include "clients/meta/FileBasedClusterIdMan.h"

#include "common/base/Base.h"

namespace nebula {
namespace meta {

// static
bool FileBasedClusterIdMan::persistInFile(ClusterID clusterId,
const std::string& filename) {
auto dirname = fs::FileUtils::dirname(filename.c_str());
if (!fs::FileUtils::makeDir(dirname)) {
LOG(ERROR) << "Failed mkdir " << dirname;
return false;
}
if (fs::FileUtils::remove(filename.c_str())) {
LOG(INFO) << "Remove the existed file " << filename;
}
int fd = ::open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd < 0) {
LOG(ERROR) << "Open file error, file " << filename << ", error " << strerror(errno);
return false;
}
int bytes = ::write(fd, reinterpret_cast<const char*>(&clusterId), sizeof(ClusterID));
if (bytes != sizeof(clusterId)) {
LOG(ERROR) << "Write clusterId failed!";
::close(fd);
return false;
}
LOG(INFO) << "Persiste clusterId " << clusterId << " succeeded!";
bool FileBasedClusterIdMan::persistInFile(ClusterID clusterId, const std::string& filename) {
auto dirname = fs::FileUtils::dirname(filename.c_str());
if (!fs::FileUtils::makeDir(dirname)) {
LOG(ERROR) << "Failed mkdir " << dirname;
return false;
}
if (fs::FileUtils::remove(filename.c_str())) {
LOG(INFO) << "Remove the existed file " << filename;
}
int fd = ::open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd < 0) {
LOG(ERROR) << "Open file error, file " << filename << ", error " << strerror(errno);
return false;
}
int bytes = ::write(fd, reinterpret_cast<const char*>(&clusterId), sizeof(ClusterID));
if (bytes != sizeof(clusterId)) {
LOG(ERROR) << "Write clusterId failed!";
::close(fd);
return true;
return false;
}
LOG(INFO) << "Persiste clusterId " << clusterId << " succeeded!";
::close(fd);
return true;
}


// static
ClusterID FileBasedClusterIdMan::getClusterIdFromFile(const std::string& filename) {
int fd = ::open(filename.c_str(), O_RDONLY);
if (fd < 0) {
LOG(WARNING) << "Open file failed, error " << strerror(errno);
return 0;
}
ClusterID clusterId = 0;
int len = ::read(fd, reinterpret_cast<char*>(&clusterId), sizeof(ClusterID));
if (len != sizeof(ClusterID)) {
LOG(ERROR) << "Get clusterId failed!";
::close(fd);
return 0;
}
LOG(INFO) << "Get clusterId: " << clusterId;
int fd = ::open(filename.c_str(), O_RDONLY);
if (fd < 0) {
LOG(WARNING) << "Open file failed, error " << strerror(errno);
return 0;
}
ClusterID clusterId = 0;
int len = ::read(fd, reinterpret_cast<char*>(&clusterId), sizeof(ClusterID));
if (len != sizeof(ClusterID)) {
LOG(ERROR) << "Get clusterId failed!";
::close(fd);
return clusterId;
return 0;
}
LOG(INFO) << "Get clusterId: " << clusterId;
::close(fd);
return clusterId;
}

} // namespace meta
Expand Down
7 changes: 3 additions & 4 deletions src/clients/meta/FileBasedClusterIdMan.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@
#include "common/fs/FileUtils.h"
#include "common/meta/ClusterIdManBase.h"


namespace nebula {
namespace meta {

/**
* This class manages clusterId used for meta server and storage server.
* */
class FileBasedClusterIdMan : public ClusterIdManBase {
public:
static bool persistInFile(ClusterID clusterId, const std::string& filename);
public:
static bool persistInFile(ClusterID clusterId, const std::string& filename);

static ClusterID getClusterIdFromFile(const std::string& filename);
static ClusterID getClusterIdFromFile(const std::string& filename);
};

} // namespace meta
Expand Down
Loading