From 2aaa07f3a4ff3f4e02095bdc90b43b6d5661e713 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Thu, 16 Jul 2026 13:19:21 -1000 Subject: Convert the commit-links filter to Lua Lua is becoming the one language for the filter extensions, and this was the last shell filter. --- extensions/link-commits.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 extensions/link-commits.lua (limited to 'extensions/link-commits.lua') diff --git a/extensions/link-commits.lua b/extensions/link-commits.lua new file mode 100644 index 0000000..160a12d --- /dev/null +++ b/extensions/link-commits.lua @@ -0,0 +1,27 @@ +-- Turns object hashes and issue references in commit messages into links. +-- Use it with the commit-filter or repo.commit-filter setting and the lua: +-- prefix. cgit hands the filter the message already HTML-escaped, so this +-- only wraps matches in anchors. + +local buffer + +function filter_open(...) + buffer = "" +end + +function filter_write(str) + buffer = buffer .. str +end + +function filter_close() + -- Link a 7 to 64 character object name to this repository. + local out = buffer:gsub("%f[%w](%x+)%f[%W]", function(hex) + if #hex >= 7 and #hex <= 64 then + return '' .. hex .. '' + end + end) + -- Link "#123" to a bug tracker. Point this at your own. + out = out:gsub("#(%d+)", '#%1') + html(out) + return 0 +end -- cgit v2.8.0