summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViktor Söderqvist <viktor.soderqvist@est.tech>2022-02-03 09:25:37 +0100
committerGitHub <noreply@github.com>2022-02-03 10:25:37 +0200
commitf4ecc799c87fa504b375afc17a7f8302789254b5 (patch)
tree70166cc853f6a9b9b14f3368565c33210e2f219c
parentc9e1602f9016c169e1e72ce305aab53cbc97c616 (diff)
downloadredis-f4ecc799c87fa504b375afc17a7f8302789254b5.tar.gz
Add 'Available since' to module API function docs (#10229)
The script which generates the markdown docs from module.c is updated to include the version in which each module API function was introduced. The script uses git tags to find this information. If git is not available or if we're not in a git repo, the 'since' is silently skipped. The line `**Available since:** (version)` is added after the function prototype Rename to utils/generate-module-api-doc.rb
-rw-r--r--utils/generate-module-api-doc.rb (renamed from src/modules/gendoc.rb)24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/modules/gendoc.rb b/utils/generate-module-api-doc.rb
index f83b1ad9d..8a16751b9 100644
--- a/src/modules/gendoc.rb
+++ b/utils/generate-module-api-doc.rb
@@ -78,6 +78,7 @@ def docufy(src,i)
puts "<span id=\"#{name}\"></span>\n\n"
puts "### `#{name}`\n\n"
puts " #{proto}\n"
+ puts "**Available since:** #{$since[name]}\n\n" if $since[name]
comment = ""
while true
i = i-1
@@ -135,8 +136,9 @@ def is_func_line(src, i)
end
puts "# Modules API reference\n\n"
-puts "<!-- This file is generated from module.c using gendoc.rb -->\n\n"
-src = File.open(File.dirname(__FILE__) ++ "/../module.c").to_a
+puts "<!-- This file is generated from module.c using\n"
+puts " utils/generate-module-api-doc.rb -->\n\n"
+src = File.open(File.dirname(__FILE__) ++ "/../src/module.c").to_a
# Build function index
$index = {}
@@ -148,6 +150,24 @@ src.each_with_index do |line,i|
end
end
+# Populate the 'since' map (name => version) if we're in a git repo.
+$since = {}
+git_dir = File.dirname(__FILE__) ++ "/../.git"
+if File.directory?(git_dir) && `which git` != ""
+ `git --git-dir="#{git_dir}" tag --sort=v:refname`.each_line do |version|
+ next if version !~ /^(\d+)\.\d+\.\d+?$/ || $1.to_i < 4
+ version.chomp!
+ `git --git-dir="#{git_dir}" cat-file blob "#{version}:src/module.c"`.each_line do |line|
+ if line =~ /^\w.*[ \*]RM_([A-z0-9]+)/
+ name = "RedisModule_#{$1}"
+ if ! $since[name]
+ $since[name] = version
+ end
+ end
+ end
+ end
+end
+
# Print TOC
puts "## Sections\n\n"
src.each_with_index do |_line,i|