Unverified Commit ffbe36fc authored by guybe7's avatar guybe7 Committed by GitHub
Browse files

Command table: Sorted subcommands (#9951)



Sort the sub-commands so that every time we execute the script it generates the exact same results.
This will case less merge conflicts if two PRs edit different json files.

also:
* make the script agnostic to where it is executed (more flexible).
* add documentation about commands.c and the json files in the readme.
Co-authored-by: default avatarOran Agra <oran@redislabs.com>
parent 70ff26b4
......@@ -362,6 +362,12 @@ Inside server.c you can find code that handles other vital things of the Redis s
* `performEvictions()` is called when a new write command should be performed but Redis is out of memory according to the `maxmemory` directive.
* The global variable `redisCommandTable` defines all the Redis commands, specifying the name of the command, the function implementing the command, the number of arguments required, and other properties of each command.
commands.c
---
This file is auto generated by utils/generate-command-code.py, the content is based on the JSON files in the src/commands folder.
These are meant to be the single source of truth about the Redis commands, and all the metadata about them.
These JSON files are not meant to be used directly by anyone directly, instead that metadata can be obtained via the COMMAND command.
networking.c
---
......
This diff is collapsed.
......@@ -4,8 +4,6 @@ import os
import glob
import json
# Note: This script should be run from the src/ dir: ../utils/generate-command-code.py
ARG_TYPES = {
"string": "ARG_TYPE_STRING",
"integer": "ARG_TYPE_INTEGER",
......@@ -305,12 +303,13 @@ class Command(object):
def write_internal_structs(self, f):
if self.subcommands:
for subcommand in sorted(self.subcommands, key=lambda cmd: cmd.name):
subcommand_list = sorted(self.subcommands, key=lambda cmd: cmd.name)
for subcommand in subcommand_list:
subcommand.write_internal_structs(f)
f.write("/* %s command table */\n" % self.fullname())
f.write("struct redisCommand %s[] = {\n" % self.subcommand_table_name())
for subcommand in self.subcommands:
for subcommand in subcommand_list:
f.write("{%s},\n" % subcommand.struct_code())
f.write("{0}\n")
f.write("};\n\n")
......@@ -367,9 +366,12 @@ def create_command(name, desc):
# MAIN
# Figure out where the sources are
srcdir = os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + "/../src")
# Create all command objects
print("Processing json files...")
for filename in glob.glob('commands/*.json'):
for filename in glob.glob('%s/commands/*.json' % srcdir):
with open(filename,"r") as f:
d = json.load(f)
for name, desc in d.items():
......@@ -387,7 +389,7 @@ for command in commands.values():
command.subcommands.append(subcommand)
print("Generating commands.c...")
with open("commands.c","w") as f:
with open("%s/commands.c" % srcdir,"w") as f:
f.write("/* Automatically generated by %s, do not edit. */\n\n" % os.path.basename(__file__))
f.write("#include \"server.h\"\n")
f.write(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment