From f4ecc799c87fa504b375afc17a7f8302789254b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20S=C3=B6derqvist?= Date: Thu, 3 Feb 2022 09:25:37 +0100 Subject: [PATCH] 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 --- .../generate-module-api-doc.rb | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) rename src/modules/gendoc.rb => utils/generate-module-api-doc.rb (86%) diff --git a/src/modules/gendoc.rb b/utils/generate-module-api-doc.rb similarity index 86% rename from src/modules/gendoc.rb rename to 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 "\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 "\n\n" -src = File.open(File.dirname(__FILE__) ++ "/../module.c").to_a +puts "\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|