Skip to content

Commit

Permalink
Remove unnecessary clang-format off annotations (valkey-io#628)
Browse files Browse the repository at this point in the history
We added some clang-format off comments before we had decided on the
format configuration. Now, it turns out that turning formatting off is
often not necessary.

---------

Signed-off-by: Viktor Söderqvist <[email protected]>
  • Loading branch information
zuiderkwast authored Jun 12, 2024
1 parent e65b2d2 commit 4bb7cc4
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 154 deletions.
36 changes: 13 additions & 23 deletions src/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1587,12 +1587,10 @@ static int ACLSelectorCheckKey(aclSelector *selector, const char *key, int keyle
listRewind(selector->patterns, &li);

int key_flags = 0;
/* clang-format off */
if (keyspec_flags & CMD_KEY_ACCESS) key_flags |= ACL_READ_PERMISSION;
if (keyspec_flags & CMD_KEY_INSERT) key_flags |= ACL_WRITE_PERMISSION;
if (keyspec_flags & CMD_KEY_DELETE) key_flags |= ACL_WRITE_PERMISSION;
if (keyspec_flags & CMD_KEY_UPDATE) key_flags |= ACL_WRITE_PERMISSION;
/* clang-format on */

/* Test this key against every pattern. */
while ((ln = listNext(&li))) {
Expand All @@ -1618,12 +1616,10 @@ static int ACLSelectorHasUnrestrictedKeyAccess(aclSelector *selector, int flags)
listRewind(selector->patterns, &li);

int access_flags = 0;
/* clang-format off */
if (flags & CMD_KEY_ACCESS) access_flags |= ACL_READ_PERMISSION;
if (flags & CMD_KEY_INSERT) access_flags |= ACL_WRITE_PERMISSION;
if (flags & CMD_KEY_DELETE) access_flags |= ACL_WRITE_PERMISSION;
if (flags & CMD_KEY_UPDATE) access_flags |= ACL_WRITE_PERMISSION;
/* clang-format on */

/* Test this key against every pattern. */
while ((ln = listNext(&li))) {
Expand Down Expand Up @@ -2669,15 +2665,13 @@ void addACLLogEntry(client *c, int reason, int context, int argpos, sds username
if (object) {
le->object = object;
} else {
/* clang-format off */
switch(reason) {
switch (reason) {
case ACL_DENIED_CMD: le->object = sdsdup(c->cmd->fullname); break;
case ACL_DENIED_KEY: le->object = sdsdup(c->argv[argpos]->ptr); break;
case ACL_DENIED_CHANNEL: le->object = sdsdup(c->argv[argpos]->ptr); break;
case ACL_DENIED_AUTH: le->object = sdsdup(c->argv[0]->ptr); break;
default: le->object = sdsempty();
}
/* clang-format on */
}

/* if we have a real client from the network, use it (could be missing on module timers) */
Expand Down Expand Up @@ -3058,28 +3052,24 @@ void aclCommand(client *c) {

addReplyBulkCString(c, "reason");
char *reasonstr;
/* clang-format off */
switch(le->reason) {
case ACL_DENIED_CMD: reasonstr="command"; break;
case ACL_DENIED_KEY: reasonstr="key"; break;
case ACL_DENIED_CHANNEL: reasonstr="channel"; break;
case ACL_DENIED_AUTH: reasonstr="auth"; break;
default: reasonstr="unknown";
switch (le->reason) {
case ACL_DENIED_CMD: reasonstr = "command"; break;
case ACL_DENIED_KEY: reasonstr = "key"; break;
case ACL_DENIED_CHANNEL: reasonstr = "channel"; break;
case ACL_DENIED_AUTH: reasonstr = "auth"; break;
default: reasonstr = "unknown";
}
/* clang-format on */
addReplyBulkCString(c, reasonstr);

addReplyBulkCString(c, "context");
char *ctxstr;
/* clang-format off */
switch(le->context) {
case ACL_LOG_CTX_TOPLEVEL: ctxstr="toplevel"; break;
case ACL_LOG_CTX_MULTI: ctxstr="multi"; break;
case ACL_LOG_CTX_LUA: ctxstr="lua"; break;
case ACL_LOG_CTX_MODULE: ctxstr="module"; break;
default: ctxstr="unknown";
switch (le->context) {
case ACL_LOG_CTX_TOPLEVEL: ctxstr = "toplevel"; break;
case ACL_LOG_CTX_MULTI: ctxstr = "multi"; break;
case ACL_LOG_CTX_LUA: ctxstr = "lua"; break;
case ACL_LOG_CTX_MODULE: ctxstr = "module"; break;
default: ctxstr = "unknown";
}
/* clang-format on */
addReplyBulkCString(c, ctxstr);

addReplyBulkCString(c, "object");
Expand Down
42 changes: 19 additions & 23 deletions src/aof.c
Original file line number Diff line number Diff line change
Expand Up @@ -1994,21 +1994,19 @@ int rioWriteStreamPendingEntry(rio *r,
RETRYCOUNT <count> JUSTID FORCE. */
streamID id;
streamDecodeID(rawid, &id);
/* clang-format off */
if (rioWriteBulkCount(r,'*',12) == 0) return 0;
if (rioWriteBulkString(r,"XCLAIM",6) == 0) return 0;
if (rioWriteBulkObject(r,key) == 0) return 0;
if (rioWriteBulkString(r,groupname,groupname_len) == 0) return 0;
if (rioWriteBulkString(r,consumer->name,sdslen(consumer->name)) == 0) return 0;
if (rioWriteBulkString(r,"0",1) == 0) return 0;
if (rioWriteBulkStreamID(r,&id) == 0) return 0;
if (rioWriteBulkString(r,"TIME",4) == 0) return 0;
if (rioWriteBulkLongLong(r,nack->delivery_time) == 0) return 0;
if (rioWriteBulkString(r,"RETRYCOUNT",10) == 0) return 0;
if (rioWriteBulkLongLong(r,nack->delivery_count) == 0) return 0;
if (rioWriteBulkString(r,"JUSTID",6) == 0) return 0;
if (rioWriteBulkString(r,"FORCE",5) == 0) return 0;
/* clang-format on */
if (rioWriteBulkCount(r, '*', 12) == 0) return 0;
if (rioWriteBulkString(r, "XCLAIM", 6) == 0) return 0;
if (rioWriteBulkObject(r, key) == 0) return 0;
if (rioWriteBulkString(r, groupname, groupname_len) == 0) return 0;
if (rioWriteBulkString(r, consumer->name, sdslen(consumer->name)) == 0) return 0;
if (rioWriteBulkString(r, "0", 1) == 0) return 0;
if (rioWriteBulkStreamID(r, &id) == 0) return 0;
if (rioWriteBulkString(r, "TIME", 4) == 0) return 0;
if (rioWriteBulkLongLong(r, nack->delivery_time) == 0) return 0;
if (rioWriteBulkString(r, "RETRYCOUNT", 10) == 0) return 0;
if (rioWriteBulkLongLong(r, nack->delivery_count) == 0) return 0;
if (rioWriteBulkString(r, "JUSTID", 6) == 0) return 0;
if (rioWriteBulkString(r, "FORCE", 5) == 0) return 0;
return 1;
}

Expand All @@ -2021,14 +2019,12 @@ int rioWriteStreamEmptyConsumer(rio *r,
size_t groupname_len,
streamConsumer *consumer) {
/* XGROUP CREATECONSUMER <key> <group> <consumer> */
/* clang-format off */
if (rioWriteBulkCount(r,'*',5) == 0) return 0;
if (rioWriteBulkString(r,"XGROUP",6) == 0) return 0;
if (rioWriteBulkString(r,"CREATECONSUMER",14) == 0) return 0;
if (rioWriteBulkObject(r,key) == 0) return 0;
if (rioWriteBulkString(r,groupname,groupname_len) == 0) return 0;
if (rioWriteBulkString(r,consumer->name,sdslen(consumer->name)) == 0) return 0;
/* clang-format on */
if (rioWriteBulkCount(r, '*', 5) == 0) return 0;
if (rioWriteBulkString(r, "XGROUP", 6) == 0) return 0;
if (rioWriteBulkString(r, "CREATECONSUMER", 14) == 0) return 0;
if (rioWriteBulkObject(r, key) == 0) return 0;
if (rioWriteBulkString(r, groupname, groupname_len) == 0) return 0;
if (rioWriteBulkString(r, consumer->name, sdslen(consumer->name)) == 0) return 0;
return 1;
}

Expand Down
24 changes: 11 additions & 13 deletions src/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1221,20 +1221,18 @@ char *ldbRespToHuman_Double(sds *o, char *reply);
* char*) so that we can return a modified pointer, as for SDS semantics. */
char *ldbRespToHuman(sds *o, char *reply) {
char *p = reply;
/* clang-format off */
switch(*p) {
case ':': p = ldbRespToHuman_Int(o,reply); break;
case '$': p = ldbRespToHuman_Bulk(o,reply); break;
case '+': p = ldbRespToHuman_Status(o,reply); break;
case '-': p = ldbRespToHuman_Status(o,reply); break;
case '*': p = ldbRespToHuman_MultiBulk(o,reply); break;
case '~': p = ldbRespToHuman_Set(o,reply); break;
case '%': p = ldbRespToHuman_Map(o,reply); break;
case '_': p = ldbRespToHuman_Null(o,reply); break;
case '#': p = ldbRespToHuman_Bool(o,reply); break;
case ',': p = ldbRespToHuman_Double(o,reply); break;
switch (*p) {
case ':': p = ldbRespToHuman_Int(o, reply); break;
case '$': p = ldbRespToHuman_Bulk(o, reply); break;
case '+': p = ldbRespToHuman_Status(o, reply); break;
case '-': p = ldbRespToHuman_Status(o, reply); break;
case '*': p = ldbRespToHuman_MultiBulk(o, reply); break;
case '~': p = ldbRespToHuman_Set(o, reply); break;
case '%': p = ldbRespToHuman_Map(o, reply); break;
case '_': p = ldbRespToHuman_Null(o, reply); break;
case '#': p = ldbRespToHuman_Bool(o, reply); break;
case ',': p = ldbRespToHuman_Double(o, reply); break;
}
/* clang-format on */
return p;
}

Expand Down
10 changes: 3 additions & 7 deletions src/listpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,27 +427,24 @@ static inline void lpEncodeString(unsigned char *buf, unsigned char *s, uint32_t
* lpCurrentEncodedSizeBytes or ASSERT_INTEGRITY_LEN (possibly since 'p' is
* a return value of another function that validated its return. */
static inline uint32_t lpCurrentEncodedSizeUnsafe(unsigned char *p) {
/* clang-format off */
if (LP_ENCODING_IS_7BIT_UINT(p[0])) return 1;
if (LP_ENCODING_IS_6BIT_STR(p[0])) return 1+LP_ENCODING_6BIT_STR_LEN(p);
if (LP_ENCODING_IS_6BIT_STR(p[0])) return 1 + LP_ENCODING_6BIT_STR_LEN(p);
if (LP_ENCODING_IS_13BIT_INT(p[0])) return 2;
if (LP_ENCODING_IS_16BIT_INT(p[0])) return 3;
if (LP_ENCODING_IS_24BIT_INT(p[0])) return 4;
if (LP_ENCODING_IS_32BIT_INT(p[0])) return 5;
if (LP_ENCODING_IS_64BIT_INT(p[0])) return 9;
if (LP_ENCODING_IS_12BIT_STR(p[0])) return 2+LP_ENCODING_12BIT_STR_LEN(p);
if (LP_ENCODING_IS_32BIT_STR(p[0])) return 5+LP_ENCODING_32BIT_STR_LEN(p);
if (LP_ENCODING_IS_12BIT_STR(p[0])) return 2 + LP_ENCODING_12BIT_STR_LEN(p);
if (LP_ENCODING_IS_32BIT_STR(p[0])) return 5 + LP_ENCODING_32BIT_STR_LEN(p);
if (p[0] == LP_EOF) return 1;
return 0;
/* clang-format on */
}

/* Return bytes needed to encode the length of the listpack element pointed by 'p'.
* This includes just the encoding byte, and the bytes needed to encode the length
* of the element (excluding the element data itself)
* If the element encoding is wrong then 0 is returned. */
static inline uint32_t lpCurrentEncodedSizeBytes(unsigned char *p) {
/* clang-format off */
if (LP_ENCODING_IS_7BIT_UINT(p[0])) return 1;
if (LP_ENCODING_IS_6BIT_STR(p[0])) return 1;
if (LP_ENCODING_IS_13BIT_INT(p[0])) return 1;
Expand All @@ -459,7 +456,6 @@ static inline uint32_t lpCurrentEncodedSizeBytes(unsigned char *p) {
if (LP_ENCODING_IS_32BIT_STR(p[0])) return 5;
if (p[0] == LP_EOF) return 1;
return 0;
/* clang-format on */
}

/* Skip the current entry returning the next. It is invalid to call this
Expand Down
8 changes: 2 additions & 6 deletions src/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -2843,7 +2843,6 @@ sds catClientInfoString(sds s, client *client) {
else
*p++ = 'S';
}
/* clang-format off */
if (client->flags & CLIENT_PRIMARY) *p++ = 'M';
if (client->flags & CLIENT_PUBSUB) *p++ = 'P';
if (client->flags & CLIENT_MULTI) *p++ = 'x';
Expand All @@ -2860,7 +2859,6 @@ sds catClientInfoString(sds s, client *client) {
if (client->flags & CLIENT_NO_EVICT) *p++ = 'e';
if (client->flags & CLIENT_NO_TOUCH) *p++ = 'T';
if (p == flags) *p++ = 'N';
/* clang-format on */
*p++ = '\0';

p = events;
Expand Down Expand Up @@ -3269,15 +3267,13 @@ NULL
listRewind(server.clients, &li);
while ((ln = listNext(&li)) != NULL) {
client *client = listNodeValue(ln);
/* clang-format off */
if (addr && strcmp(getClientPeerId(client),addr) != 0) continue;
if (laddr && strcmp(getClientSockname(client),laddr) != 0) continue;
if (addr && strcmp(getClientPeerId(client), addr) != 0) continue;
if (laddr && strcmp(getClientSockname(client), laddr) != 0) continue;
if (type != -1 && getClientType(client) != type) continue;
if (id != 0 && client->id != id) continue;
if (user && client->user != user) continue;
if (c == client && skipme) continue;
if (max_age != 0 && (long long)(commandTimeSnapshot() / 1000 - client->ctime) < max_age) continue;
/* clang-format on */

/* Kill it. */
if (c == client) {
Expand Down
36 changes: 16 additions & 20 deletions src/notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ int keyspaceEventsStringToFlags(char *classes) {
int c, flags = 0;

while ((c = *p++) != '\0') {
/* clang-format off */
switch(c) {
switch (c) {
case 'A': flags |= NOTIFY_ALL; break;
case 'g': flags |= NOTIFY_GENERIC; break;
case '$': flags |= NOTIFY_STRING; break;
Expand All @@ -61,7 +60,6 @@ int keyspaceEventsStringToFlags(char *classes) {
case 'n': flags |= NOTIFY_NEW; break;
default: return -1;
}
/* clang-format on */
}
return flags;
}
Expand All @@ -73,28 +71,26 @@ int keyspaceEventsStringToFlags(char *classes) {
sds keyspaceEventsFlagsToString(int flags) {
sds res;

/* clang-format off */
res = sdsempty();
if ((flags & NOTIFY_ALL) == NOTIFY_ALL) {
res = sdscatlen(res,"A",1);
res = sdscatlen(res, "A", 1);
} else {
if (flags & NOTIFY_GENERIC) res = sdscatlen(res,"g",1);
if (flags & NOTIFY_STRING) res = sdscatlen(res,"$",1);
if (flags & NOTIFY_LIST) res = sdscatlen(res,"l",1);
if (flags & NOTIFY_SET) res = sdscatlen(res,"s",1);
if (flags & NOTIFY_HASH) res = sdscatlen(res,"h",1);
if (flags & NOTIFY_ZSET) res = sdscatlen(res,"z",1);
if (flags & NOTIFY_EXPIRED) res = sdscatlen(res,"x",1);
if (flags & NOTIFY_EVICTED) res = sdscatlen(res,"e",1);
if (flags & NOTIFY_STREAM) res = sdscatlen(res,"t",1);
if (flags & NOTIFY_MODULE) res = sdscatlen(res,"d",1);
if (flags & NOTIFY_NEW) res = sdscatlen(res,"n",1);
if (flags & NOTIFY_GENERIC) res = sdscatlen(res, "g", 1);
if (flags & NOTIFY_STRING) res = sdscatlen(res, "$", 1);
if (flags & NOTIFY_LIST) res = sdscatlen(res, "l", 1);
if (flags & NOTIFY_SET) res = sdscatlen(res, "s", 1);
if (flags & NOTIFY_HASH) res = sdscatlen(res, "h", 1);
if (flags & NOTIFY_ZSET) res = sdscatlen(res, "z", 1);
if (flags & NOTIFY_EXPIRED) res = sdscatlen(res, "x", 1);
if (flags & NOTIFY_EVICTED) res = sdscatlen(res, "e", 1);
if (flags & NOTIFY_STREAM) res = sdscatlen(res, "t", 1);
if (flags & NOTIFY_MODULE) res = sdscatlen(res, "d", 1);
if (flags & NOTIFY_NEW) res = sdscatlen(res, "n", 1);
}
if (flags & NOTIFY_KEYSPACE) res = sdscatlen(res,"K",1);
if (flags & NOTIFY_KEYEVENT) res = sdscatlen(res,"E",1);
if (flags & NOTIFY_KEY_MISS) res = sdscatlen(res,"m",1);
if (flags & NOTIFY_KEYSPACE) res = sdscatlen(res, "K", 1);
if (flags & NOTIFY_KEYEVENT) res = sdscatlen(res, "E", 1);
if (flags & NOTIFY_KEY_MISS) res = sdscatlen(res, "m", 1);
return res;
/* clang-format on */
}

/* The API provided to the rest of the serer core is a simple function:
Expand Down
12 changes: 3 additions & 9 deletions src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,7 @@ void incrRefCount(robj *o) {

void decrRefCount(robj *o) {
if (o->refcount == 1) {
/* clang-format off */
switch(o->type) {
switch (o->type) {
case OBJ_STRING: freeStringObject(o); break;
case OBJ_LIST: freeListObject(o); break;
case OBJ_SET: freeSetObject(o); break;
Expand All @@ -383,7 +382,6 @@ void decrRefCount(robj *o) {
case OBJ_STREAM: freeStreamObject(o); break;
default: serverPanic("Unknown object type"); break;
}
/* clang-format on */
zfree(o);
} else {
if (o->refcount <= 0) serverPanic("decrRefCount against refcount <= 0");
Expand Down Expand Up @@ -552,8 +550,7 @@ void dismissObject(robj *o, size_t size_hint) {
* so we avoid these pointless loops when they're not going to do anything. */
#if defined(USE_JEMALLOC) && defined(__linux__)
if (o->refcount != 1) return;
/* clang-format off */
switch(o->type) {
switch (o->type) {
case OBJ_STRING: dismissStringObject(o); break;
case OBJ_LIST: dismissListObject(o, size_hint); break;
case OBJ_SET: dismissSetObject(o, size_hint); break;
Expand All @@ -562,7 +559,6 @@ void dismissObject(robj *o, size_t size_hint) {
case OBJ_STREAM: dismissStreamObject(o, size_hint); break;
default: break;
}
/* clang-format on */
#else
UNUSED(o);
UNUSED(size_hint);
Expand Down Expand Up @@ -930,8 +926,7 @@ int getIntFromObjectOrReply(client *c, robj *o, int *target, const char *msg) {
}

char *strEncoding(int encoding) {
/* clang-format off */
switch(encoding) {
switch (encoding) {
case OBJ_ENCODING_RAW: return "raw";
case OBJ_ENCODING_INT: return "int";
case OBJ_ENCODING_HT: return "hashtable";
Expand All @@ -943,7 +938,6 @@ char *strEncoding(int encoding) {
case OBJ_ENCODING_STREAM: return "stream";
default: return "unknown";
}
/* clang-format on */
}

/* =========================== Memory introspection ========================= */
Expand Down
4 changes: 1 addition & 3 deletions src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -3149,16 +3149,14 @@ void roleCommand(client *c) {
if (replicaIsInHandshakeState()) {
replica_state = "handshake";
} else {
/* clang-format off */
switch(server.repl_state) {
switch (server.repl_state) {
case REPL_STATE_NONE: replica_state = "none"; break;
case REPL_STATE_CONNECT: replica_state = "connect"; break;
case REPL_STATE_CONNECTING: replica_state = "connecting"; break;
case REPL_STATE_TRANSFER: replica_state = "sync"; break;
case REPL_STATE_CONNECTED: replica_state = "connected"; break;
default: replica_state = "unknown"; break;
}
/* clang-format on */
}
addReplyBulkCString(c, replica_state);
addReplyLongLong(c, server.primary ? server.primary->reploff : -1);
Expand Down
5 changes: 2 additions & 3 deletions src/resp_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ static int parseMap(ReplyParser *parser, void *p_ctx) {

/* Parse a reply pointed to by parser->curr_location. */
int parseReply(ReplyParser *parser, void *p_ctx) {
/* clang-format off */
switch (parser->curr_location[0]) {
case '$': return parseBulk(parser, p_ctx);
case '+': return parseSimpleString(parser, p_ctx);
Expand All @@ -224,8 +223,8 @@ int parseReply(ReplyParser *parser, void *p_ctx) {
case '(': return parseBigNumber(parser, p_ctx);
case '=': return parseVerbatimString(parser, p_ctx);
case '|': return parseAttributes(parser, p_ctx);
default: if (parser->callbacks.error) parser->callbacks.error(p_ctx);
default:
if (parser->callbacks.error) parser->callbacks.error(p_ctx);
}
/* clang-format on */
return C_ERR;
}
Loading

0 comments on commit 4bb7cc4

Please sign in to comment.