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

style: format #56

Merged
merged 14 commits into from
Nov 29, 2023
18 changes: 17 additions & 1 deletion .github/workflows/pikiwidb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Pikiwidb
on:
push:
pull_request:
branches: [ "unstable" ]

jobs:
build_on_macos:
Expand All @@ -13,4 +14,19 @@ jobs:

- name: Build
run: |
sh build.sh
sh build.sh

build_on_ubuntu:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Build
run: |
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release

- name: Check Format
working-directory: ${{ github.workspace }}/build
run: make check-format
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ ADD_CUSTOM_TARGET(format
--quiet
--fix
)
ADD_CUSTOM_TARGET(check-format
COMMAND ${BUILD_SUPPORT_DIR}/run_clang_format.py
/usr/bin/clang-format
${BUILD_SUPPORT_DIR}/clang_format_exclusions.txt
--source_dirs ${FORMAT_DIRS}
)

ADD_CUSTOM_TARGET(clang-tidy
COMMAND ${BUILD_SUPPORT_DIR}/run_clang_tidy.py
Expand Down
2 changes: 1 addition & 1 deletion build_support/run_clang_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def check(arguments, source_dir):
fullpaths = (os.path.join(directory, filename)
for filename in filenames)
source_files = [x for x in fullpaths
if x.endswith(".h") or x.endswith(".cpp")]
if x.endswith(".h") or x.endswith(".cpp") or x.endswith(".cc") or x.endswith(".c")]
formatted_filenames.extend(
# Filter out files that match the globs in the globs file
[filename for filename in source_files
Expand Down
4 changes: 1 addition & 3 deletions src/base_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ bool BaseCmd::CheckArg(size_t num) const {
return num >= -arity_;
}

std::vector<std::string> BaseCmd::CurrentKey(PClient* client) const {
return std::vector<std::string>{client->Key()};
}
std::vector<std::string> BaseCmd::CurrentKey(PClient* client) const { return std::vector<std::string>{client->Key()}; }

void BaseCmd::Execute(PClient* client) {
if (!DoInitial(client)) {
Expand Down
1 change: 0 additions & 1 deletion src/base_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const std::string kCmdNameBitCount = "bitcount";

const std::string kCmdNameAuth = "auth";


enum CmdFlags {
CmdFlagsWrite = (1 << 0), // May modify the dataset
CmdFlagsReadonly = (1 << 1), // Doesn't modify the dataset
Expand Down
2 changes: 1 addition & 1 deletion src/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ void PClient::FeedMonitors(const std::vector<std::string>& params) {
}
}
void PClient::SetKey(std::vector<std::string>& names) {
keys_ = std::move(names); // use std::move clear copy expense
keys_ = std::move(names); // use std::move clear copy expense
}

} // namespace pikiwidb
6 changes: 4 additions & 2 deletions src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ class PClient : public std::enable_shared_from_this<PClient>, public CmdRes {
void SetSubCmdName(const std::string& name);
const std::string& SubCmdName() const { return subCmdName_; }
std::string FullCmdName() const; // the full name of the command, such as config set|get|rewrite
void SetKey(const std::string& name) { keys_.clear(); keys_.emplace_back(name); }
void SetKey(const std::string& name) {
keys_.clear();
keys_.emplace_back(name);
}
void SetKey(std::vector<std::string>& names);
const std::string& Key() const { return keys_.at(0); }
const std::vector<std::string>& Keys() const { return keys_; }
Expand Down Expand Up @@ -219,7 +222,6 @@ class PClient : public std::enable_shared_from_this<PClient>, public CmdRes {
std::string cmdName_; // suchAs config
std::vector<std::string> keys_;


// All parameters of this command (including the command itself)
// e.g:["set","key","value"]
std::vector<std::string> params_;
Expand Down
2 changes: 1 addition & 1 deletion src/cmd_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CmdConfig : public BaseCmdGroup {
bool DoInitial(PClient* client) override { return true; };

private:
// std::vector<std::string> subCmd_;
// std::vector<std::string> subCmd_;

void DoCmd(PClient* client) override{};
};
Expand Down
4 changes: 2 additions & 2 deletions src/cmd_kv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ BitCountCmd::BitCountCmd(const std::string& name, int16_t arity)

bool BitCountCmd::DoInitial(PClient* client) {
size_t paramSize = client->argv_.size();
if(paramSize != 2 && paramSize != 4) {
if (paramSize != 2 && paramSize != 4) {
client->SetRes(CmdRes::kSyntaxErr, kCmdNameBitCount);
return false;
}
Expand All @@ -188,7 +188,7 @@ void BitCountCmd::DoCmd(PClient* client) {
if (pstd::String2int(client->argv_[2], &start_offset_) == 0 ||
pstd::String2int(client->argv_[3], &end_offset_) == 0) {
client->SetRes(CmdRes::kInvalidInt);
return ;
return;
}

auto str = GetDecodedString(value);
Expand Down
3 changes: 1 addition & 2 deletions src/cmd_table_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include "base_cmd.h"


namespace pikiwidb {

using CmdTable = std::unordered_map<std::string, std::unique_ptr<BaseCmd>>;
Expand All @@ -28,7 +27,7 @@ class CmdTableManager {

public:
void InitCmdTable();
std::pair<BaseCmd*,CmdRes::CmdRet> GetCommand(const std::string& cmdName, PClient* client);
std::pair<BaseCmd*, CmdRes::CmdRet> GetCommand(const std::string& cmdName, PClient* client);
// uint32_t DistributeKey(const std::string& key, uint32_t slot_num);
bool CmdExist(const std::string& cmd) const;
uint32_t GetCmdId();
Expand Down
4 changes: 2 additions & 2 deletions src/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

#include <map>
#include <vector>
#include "delegate.h"

#include "common.h"
#include "delegate.h"
#include "pstring.h"

namespace pikiwidb {
Expand Down Expand Up @@ -218,4 +219,3 @@ class PCommandTable {
};

} // namespace pikiwidb

3 changes: 2 additions & 1 deletion src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

#pragma once

#include <cstdio>
#include <strings.h>
#include <algorithm>
#include <cstddef>
#include <cstdio>
#include <functional>
#include <vector>

#include "pstring.h"

#define CRLF "\r\n"
Expand Down
1 change: 0 additions & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,3 @@ extern PConfig g_config;
extern bool LoadPikiwiDBConfig(const char* cfgFile, PConfig& cfg);

} // namespace pikiwidb

Loading