summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/gitinfo-lua/gitinfo-lua.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/scripts/gitinfo-lua/gitinfo-lua.lua')
-rw-r--r--Master/texmf-dist/scripts/gitinfo-lua/gitinfo-lua.lua73
1 files changed, 60 insertions, 13 deletions
diff --git a/Master/texmf-dist/scripts/gitinfo-lua/gitinfo-lua.lua b/Master/texmf-dist/scripts/gitinfo-lua/gitinfo-lua.lua
index cba19b19d78..8c346ec3bed 100644
--- a/Master/texmf-dist/scripts/gitinfo-lua/gitinfo-lua.lua
+++ b/Master/texmf-dist/scripts/gitinfo-lua/gitinfo-lua.lua
@@ -23,8 +23,8 @@ end
local module = {
name = 'gitinfo-lua',
info = {
- version = '1.0.3', --TAGVERSION
- date = '2024/04/02', --TAGDATE
+ version = '1.1.0', --TAGVERSION
+ date = '2024/04/11', --TAGDATE
comment = "Git info Lua — Git integration with LaTeX",
author = "Erik Nijenhuis",
license = "free"
@@ -56,6 +56,8 @@ local mt = {
local gitinfo = {}
setmetatable(gitinfo, mt)
+local luakeys = require('luakeys')()
+
function api.trim(s)
return s and (s:gsub("^%s*(.-)%s*$", "%1")) or 'nil'
end
@@ -85,6 +87,15 @@ function api:dir(path)
self.cmd.cwd = path
end
+function api:dir_to_root()
+ local toplevel, err = self.cmd:exec('rev-parse --show-toplevel', false, nil, true)
+ if toplevel then
+ self.cmd.cwd = self.cmd.trim(toplevel)
+ else
+ tex.error(err)
+ end
+end
+
function api:version()
return self.trim(self.cmd:exec('describe --tags --always', true))
end
@@ -167,7 +178,7 @@ function api:cs_for_authors(csname, conjunction, sort_by_contrib)
tex.error(err)
end
else
- tex.error('ERROR: \\' .. csname .. ' not defined')
+ tex.error('ERROR: ' .. csname .. ' not defined')
end
end
@@ -188,7 +199,7 @@ function api:cs_commit(csname, rev, format)
tex.error('ERROR: ' .. (err or 'nil'))
end
else
- tex.error('ERROR: \\' .. csname .. ' not defined')
+ tex.error('ERROR: ' .. csname .. ' not defined')
end
end
@@ -196,10 +207,46 @@ function api:cs_last_commit(csname, format)
return self:cs_commit(csname, '-1', format)
end
-function api:cs_for_commit(csname, rev_spec, format)
+local parse_commit_opts = luakeys.define({
+ rev_spec = { pick = 'string' },
+ files = { data_type = 'list' },
+ cwd = { data_type = 'string' },
+ flags = {
+ sub_keys = {
+ merges = { data_type='boolean', exclusive_group='merges' },
+ ['no-merges'] = { data_type='boolean', exclusive_group='merges' }
+ }
+ }
+})
+local function parse_flags(flags_table)
+ local t = {}
+ if flags_table then
+ for k,v in pairs(flags_table) do
+ if v then
+ table.insert(t, k)
+ end
+ end
+ end
+ return t
+end
+function api:cs_for_commit(csname, args, format)
if token.is_defined(csname) then
local tok = token.create(csname)
- local log, err = self.cmd:log(format, rev_spec)
+ local opts = parse_commit_opts(args)
+ -- Something is going wrong with the parsing of rev_spec with pick, which ends up to be missing.
+ -- This is a workaround to ensure the old API would still work.
+ -- This will be fixed after luakeys version >0.13.0
+ if type(opts.rev_spec) ~= 'string' then
+ local i = string.find(args, ',')
+ if i then
+ opts.rev_spec = string.sub(args, 1, i-1)
+ else
+ opts.rev_spec = args
+ end
+ else
+ opts.rev_spec = string.gsub(opts.rev_spec, '[\'"]', '')
+ end
+ local log, err = self.cmd:log(format, opts.rev_spec, parse_flags(opts.flags), opts.cwd, opts['files'])
if log then
for _, commit in ipairs(log) do
tex.print(tok)
@@ -208,10 +255,10 @@ function api:cs_for_commit(csname, rev_spec, format)
end
end
else
- tex.error('ERROR:\\' .. err)
+ tex.error('ERROR: ' .. err)
end
else
- tex.error('ERROR: \\' .. csname .. ' not defined')
+ tex.error('ERROR: ' .. csname .. ' not defined')
end
end
@@ -249,7 +296,7 @@ function api:cs_tag(csname, format_spec, tag, target_dir)
end
end
else
- tex.error('ERROR:\\' .. csname .. ' not defined')
+ tex.error('ERROR: ' .. csname .. ' not defined')
end
end
@@ -265,10 +312,10 @@ function api:cs_for_tag(csname, format_spec, target_dir)
end
end
else
- tex.error('ERROR:\\' .. err)
+ tex.error('ERROR: ' .. err)
end
else
- tex.error('ERROR:\\' .. csname .. ' not defined')
+ tex.error('ERROR: ' .. csname .. ' not defined')
end
end
@@ -286,10 +333,10 @@ function api:cs_for_tag_sequence(csname, target_dir)
end
end
else
- tex.error('ERROR:\\' .. (err or 'Unknown error'))
+ tex.error('ERROR: ' .. (err or 'Unknown error'))
end
else
- tex.error('ERROR:\\' .. csname .. ' not defined')
+ tex.error('ERROR: ' .. csname .. ' not defined')
end
end