Skip to content

Commit

Permalink
Clang format (oceanbase#320)
Browse files Browse the repository at this point in the history
### What problem were solved in this pull request?

Issue Number: close oceanbase#260

clang-format
  • Loading branch information
hnwyllmm authored Nov 17, 2023
1 parent a8f5fd9 commit 85990f9
Show file tree
Hide file tree
Showing 266 changed files with 2,959 additions and 4,227 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ AlwaysBreakTemplateDeclarations: true
# false表示函数实参要么都在同一行,要么都各自一行
BinPackArguments: false
# 避免格式化 LOG_* 宏
WhitespaceSensitiveMacros: ['LOG_DEFAULT', 'LOG_PANIC', 'LOG_ERROR', 'LOG_WARN', 'LOG_INFO', 'LOG_DEBUG', 'LOG_TRACE']
WhitespaceSensitiveMacros: ['LOG_DEFAULT', 'LOG_PANIC', 'LOG_ERROR', 'LOG_WARN', 'LOG_INFO', 'LOG_DEBUG', 'LOG_TRACE', 'ASSERT']
AlwaysBreakBeforeMultilineStrings: false
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Clang Format Checker
on:
pull_request:
branches: [ "main" ]
jobs:
clang-format-checking:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: RafikFarhad/clang-format-github-action@v3
with:
# sources 和 excludes 最终生成的find查找文件的命令大概是这样的
# find . -type f ! -wholename "./src/observer/sql/parser/lex_sql.*" \( -wholename "./**/*.h" -o -wholename "./**/*.cpp" \)
sources: "**/*.h,**/*.cpp,src/**/*.h,src/**/*.cpp,deps/common/**/*.h,deps/common/**/*.cpp"
excludes: "src/observer/sql/parser/lex_sql.*,src/observer/sql/parser/yacc_sql.*"
style: "file"
5 changes: 0 additions & 5 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
name: "CodeQL"

on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
schedule:
- cron: '37 12 * * 5'

Expand Down
6 changes: 3 additions & 3 deletions benchmark/bplus_tree_concurrency_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ See the Mulan PSL v2 for more details. */
//
// Created by Wangyunlai on 2023/03/14
//
#include <benchmark/benchmark.h>
#include <inttypes.h>
#include <stdexcept>
#include <benchmark/benchmark.h>

#include "storage/index/bplus_tree.h"
#include "storage/buffer/disk_buffer_pool.h"
#include "common/log/log.h"
#include "integer_generator.h"
#include "storage/buffer/disk_buffer_pool.h"
#include "storage/index/bplus_tree.h"

using namespace std;
using namespace common;
Expand Down
8 changes: 4 additions & 4 deletions benchmark/record_manager_concurrency_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ See the Mulan PSL v2 for more details. */
// Created by Wangyunlai on 2023/05/04
//

#include <benchmark/benchmark.h>
#include <inttypes.h>
#include <random>
#include <stdexcept>
#include <benchmark/benchmark.h>

#include "storage/record/record_manager.h"
#include "common/log/log.h"
#include "integer_generator.h"
#include "storage/buffer/disk_buffer_pool.h"
#include "storage/common/condition_filter.h"
#include "storage/record/record_manager.h"
#include "storage/trx/vacuous_trx.h"
#include "common/log/log.h"
#include "integer_generator.h"

using namespace std;
using namespace common;
Expand Down
6 changes: 3 additions & 3 deletions benchmark/server_concurrency_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ See the Mulan PSL v2 for more details. */
//

#if 0
#include <inttypes.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <inttypes.h>

#include <benchmark/benchmark.h>
#include <random>
#include <stdexcept>
#include <benchmark/benchmark.h>

#include "rc.h"
#include "common/log/log.h"
#include "rc.h"

using namespace std;
using namespace common;
Expand Down
14 changes: 6 additions & 8 deletions deps/common/conf/ini.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@ See the Mulan PSL v2 for more details. */

namespace common {

const std::string Ini::DEFAULT_SECTION = std::string("");
const std::string Ini::DEFAULT_SECTION = std::string("");
const std::map<std::string, std::string> Ini::empty_map_;

Ini::Ini()
{}
Ini::Ini() {}

Ini::~Ini()
{}
Ini::~Ini() {}

void Ini::insert_session(const std::string &session_name)
{
std::map<std::string, std::string> session_map;
std::map<std::string, std::string> session_map;
std::pair<std::string, std::map<std::string, std::string>> entry =
std::pair<std::string, std::map<std::string, std::string>>(session_name, session_map);

Expand Down Expand Up @@ -103,7 +101,7 @@ int Ini::insert_entry(std::map<std::string, std::string> *session_map, const std
return -1;
}

std::string key = line.substr(0, equal_pos);
std::string key = line.substr(0, equal_pos);
std::string value = line.substr(equal_pos + 1);

strip(key);
Expand Down Expand Up @@ -150,7 +148,7 @@ int Ini::load(const std::string &file_name)
if (read_buf[0] == CFG_SESSION_START_TAG && read_buf[strlen(read_buf) - 1] == CFG_SESSION_END_TAG) {

read_buf[strlen(read_buf) - 1] = '\0';
std::string session_name = std::string(read_buf + 1);
std::string session_name = std::string(read_buf + 1);

current_session = switch_session(session_name);

Expand Down
9 changes: 5 additions & 4 deletions deps/common/conf/ini.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ See the Mulan PSL v2 for more details. */
namespace common {

//********************************************************************
//#means comments
// #means comments
// Ini configuration format
//[section]
// VARNAME=VALUE

class Ini {
class Ini
{
public:
/**
* To simplify the logic, no lock's when loading configuration
Expand Down Expand Up @@ -88,7 +89,7 @@ class Ini {

// session name tag
static const char CFG_SESSION_START_TAG = '[';
static const char CFG_SESSION_END_TAG = ']';
static const char CFG_SESSION_END_TAG = ']';

protected:
/**
Expand All @@ -115,7 +116,7 @@ class Ini {
static const std::map<std::string, std::string> empty_map_;

std::set<std::string> file_names_;
SessionsMap sections_;
SessionsMap sections_;
};

/**
Expand Down
4 changes: 2 additions & 2 deletions deps/common/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace common {

#endif

enum
enum
{
// General Error Codes
STATUS_SUCCESS = 0, //!< Success status should be zero,
Expand All @@ -50,7 +50,7 @@ enum
STATUS_LAST_ERR //!< last error code
};

static const char FILE_PATH_SPLIT = '/';
static const char FILE_PATH_SPLIT = '/';
static const char FILE_PATH_SPLIT_STR[] = "/";

#define EPSILON (1E-6)
Expand Down
42 changes: 21 additions & 21 deletions deps/common/io/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ int readFromFile(const std::string &fileName, char *&outputData, size_t &fileSiz
// size_t fsSize = ftell( file );
// fseek( file, 0, SEEK_SET );

char buffer[4 * ONE_KILO];
char buffer[4 * ONE_KILO];
size_t readSize = 0;
size_t oneRead = 0;
size_t oneRead = 0;

char *data = NULL;
do {
Expand Down Expand Up @@ -72,10 +72,10 @@ int readFromFile(const std::string &fileName, char *&outputData, size_t &fileSiz

fclose(file);

data = (char *)lrealloc(data, readSize + 1);
data = (char *)lrealloc(data, readSize + 1);
data[readSize] = '\0';
outputData = data;
fileSize = readSize;
outputData = data;
fileSize = readSize;
return 0;
}

Expand All @@ -87,8 +87,8 @@ int writeToFile(const std::string &fileName, const char *data, uint32_t dataSize
return -1;
}

uint32_t leftSize = dataSize;
const char *buffer = data;
uint32_t leftSize = dataSize;
const char *buffer = data;
while (leftSize > 0) {
int writeCount = fwrite(buffer, 1, leftSize, file);
if (writeCount <= 0) {
Expand Down Expand Up @@ -134,15 +134,15 @@ int getFileNum(int64_t &fileNum, const std::string &path, const std::string &pat
{
try {
DIR *dirp = NULL;
dirp = opendir(path.c_str());
dirp = opendir(path.c_str());
if (dirp == NULL) {
std::cerr << "Failed to opendir " << path << SYS_OUTPUT_FILE_POS << SYS_OUTPUT_ERROR << std::endl;
return -1;
}

std::string fullPath;
std::string fullPath;
struct dirent *entry = NULL;
struct stat fs;
struct stat fs;
while ((entry = readdir(dirp)) != NULL) {
// don't care ".", "..", ".****" hidden files
if (!strncmp(entry->d_name, ".", 1)) {
Expand Down Expand Up @@ -197,15 +197,15 @@ int getFileList(std::vector<std::string> &fileList, const std::string &path, con
{
try {
DIR *dirp = NULL;
dirp = opendir(path.c_str());
dirp = opendir(path.c_str());
if (dirp == NULL) {
std::cerr << "Failed to opendir " << path << SYS_OUTPUT_FILE_POS << SYS_OUTPUT_ERROR << std::endl;
return -1;
}

std::string fullPath;
std::string fullPath;
struct dirent *entry = NULL;
struct stat fs;
struct stat fs;
while ((entry = readdir(dirp)) != NULL) {
// don't care ".", "..", ".****" hidden files
if (!strncmp(entry->d_name, ".", 1)) {
Expand Down Expand Up @@ -259,15 +259,15 @@ int getDirList(std::vector<std::string> &dirList, const std::string &path, const
{
try {
DIR *dirp = NULL;
dirp = opendir(path.c_str());
dirp = opendir(path.c_str());
if (dirp == NULL) {
std::cerr << "Failed to opendir " << path << SYS_OUTPUT_FILE_POS << SYS_OUTPUT_ERROR << std::endl;
return -1;
}

std::string fullPath;
std::string fullPath;
struct dirent *entry = NULL;
struct stat fs;
struct stat fs;
while ((entry = readdir(dirp)) != NULL) {
// don't care ".", "..", ".****" hidden files
if (!strncmp(entry->d_name, ".", 1)) {
Expand Down Expand Up @@ -354,17 +354,17 @@ int getFileSize(const char *filePath, int64_t &fileLen)
int writen(int fd, const void *buf, int size)
{
const char *tmp = (const char *)buf;
while ( size > 0) {
while (size > 0) {
const ssize_t ret = ::write(fd, tmp, size);
if (ret >= 0) {
tmp += ret;
tmp += ret;
size -= ret;
continue;
}
const int err = errno;
if (EAGAIN != err && EINTR != err)
return err;
}
}
return 0;
}

Expand All @@ -374,12 +374,12 @@ int readn(int fd, void *buf, int size)
while (size > 0) {
const ssize_t ret = ::read(fd, tmp, size);
if (ret > 0) {
tmp += ret;
tmp += ret;
size -= ret;
continue;
}
if (0 == ret)
return -1; // end of file
return -1; // end of file

const int err = errno;
if (EAGAIN != err && EINTR != err)
Expand Down
4 changes: 2 additions & 2 deletions deps/common/io/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int getFileSize(const char *filePath, uint64_t &fileLen);

/**
* @brief 一次性写入所有指定数据
*
*
* @param fd 写入的描述符
* @param buf 写入的数据
* @param size 写入多少数据
Expand All @@ -69,7 +69,7 @@ int writen(int fd, const void *buf, int size);

/**
* @brief 一次性读取指定长度的数据
*
*
* @param fd 读取的描述符
* @param buf 读取到这里
* @param size 读取的数据长度
Expand Down
4 changes: 2 additions & 2 deletions deps/common/io/roll_select_dir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void RollSelectDir::setBaseDir(std::string baseDir)
mBaseDir = baseDir;

std::vector<std::string> dirList;
int rc = getDirList(dirList, mBaseDir, "");
int rc = getDirList(dirList, mBaseDir, "");
if (rc) {
LOG_ERROR("Failed to all subdir entry");
}
Expand All @@ -40,7 +40,7 @@ void RollSelectDir::setBaseDir(std::string baseDir)

MUTEX_LOCK(&mMutex);
mSubdirs = dirList;
mPos = 0;
mPos = 0;
MUTEX_UNLOCK(&mMutex);
return;
}
Expand Down
21 changes: 8 additions & 13 deletions deps/common/io/roll_select_dir.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,24 @@ See the Mulan PSL v2 for more details. */
#include "common/lang/mutex.h"
namespace common {

class RollSelectDir : public SelectDir {
class RollSelectDir : public SelectDir
{
public:
RollSelectDir()
{
MUTEX_INIT(&mMutex, NULL);
}
~RollSelectDir()
{
MUTEX_DESTROY(&mMutex);
}
RollSelectDir() { MUTEX_INIT(&mMutex, NULL); }
~RollSelectDir() { MUTEX_DESTROY(&mMutex); }

public:
/**
* inherit from CSelectDir
*/
std::string select();
void setBaseDir(std::string baseDir);
void setBaseDir(std::string baseDir);

public:
std::string mBaseDir;
std::string mBaseDir;
std::vector<std::string> mSubdirs;
pthread_mutex_t mMutex;
uint32_t mPos;
pthread_mutex_t mMutex;
uint32_t mPos;
};

} // namespace common
Expand Down
Loading

0 comments on commit 85990f9

Please sign in to comment.