summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/gitinfo-lua
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2024-04-04 03:02:05 +0000
committerNorbert Preining <norbert@preining.info>2024-04-04 03:02:05 +0000
commit00e667637a3a526b577b05c4d9fead45d65c4c57 (patch)
treec5488d29362ed4d6c10b2271fdf0b54676f18a1e /macros/luatex/latex/gitinfo-lua
parente0bd7da7a67c4cd2c53d232fb0f5cfccc4c37743 (diff)
CTAN sync 202404040301
Diffstat (limited to 'macros/luatex/latex/gitinfo-lua')
-rw-r--r--macros/luatex/latex/gitinfo-lua/doc/gitinfo-lua.pdfbin115812 -> 116004 bytes
-rw-r--r--macros/luatex/latex/gitinfo-lua/doc/gitinfo-lua.tex1
-rw-r--r--macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua-cmd.lua8
-rw-r--r--macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua-recorder.lua79
-rw-r--r--macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua.lua60
-rw-r--r--macros/luatex/latex/gitinfo-lua/tex/gitinfo-lua.sty6
6 files changed, 92 insertions, 62 deletions
diff --git a/macros/luatex/latex/gitinfo-lua/doc/gitinfo-lua.pdf b/macros/luatex/latex/gitinfo-lua/doc/gitinfo-lua.pdf
index 02edd681a7..693b905da3 100644
--- a/macros/luatex/latex/gitinfo-lua/doc/gitinfo-lua.pdf
+++ b/macros/luatex/latex/gitinfo-lua/doc/gitinfo-lua.pdf
Binary files differ
diff --git a/macros/luatex/latex/gitinfo-lua/doc/gitinfo-lua.tex b/macros/luatex/latex/gitinfo-lua/doc/gitinfo-lua.tex
index ef7781dd01..fe7bdd4e97 100644
--- a/macros/luatex/latex/gitinfo-lua/doc/gitinfo-lua.tex
+++ b/macros/luatex/latex/gitinfo-lua/doc/gitinfo-lua.tex
@@ -103,6 +103,7 @@ latexmk -pvc -lualatex -shell-escape main
Note that in both cases option \texttt{-shell-escape} is required.
This is required for issuing \texttt{git} via the commandline.
+ When utilizing the continuous compilation option \texttt{-pvc} with \texttt{latexmk}, it's important to note that only committed changes will be detected, while tag changes, unfortunately, won't be recognized.
\section{LaTeX Interface}
diff --git a/macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua-cmd.lua b/macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua-cmd.lua
index 5aa0dc56e5..68ac3c09a9 100644
--- a/macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua-cmd.lua
+++ b/macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua-cmd.lua
@@ -1,5 +1,5 @@
-- gitinfo-lua-cmd.lua
--- Copyright 2023 E. Nijenhuis
+-- Copyright 2024 E. Nijenhuis
--
-- This work may be distributed and/or modified under the
-- conditions of the LaTeX Project Public License, either version 1.3c
@@ -14,14 +14,15 @@
-- The Current Maintainer of this work is E. Nijenhuis.
--
-- This work consists of the files gitinfo-lua.sty gitinfo-lua.pdf
--- gitinfo-cmd.lua and gitinfo-lua.lua
+-- gitinfo-lua-cmd.lua, gitinfo-lua-recorder.lua and gitinfo-lua.lua
local api = {
cwd = nil,
executable = 'git',
default_sort = '',
attribute_separator = '\\pop',
- record_separator = '\\end'
+ record_separator = '\\end',
+ recorder = require('gitinfo-lua-recorder')
}
local cache = {}
function cache:seek(_key)
@@ -40,6 +41,7 @@ end
function api:exec(command, do_caching, target_dir)
local cmd = self.executable .. ' ' .. command
local cwd = target_dir or self.cwd
+ api.recorder.record_head(cwd)
if cwd then
cmd = 'cd ' .. cwd .. ' && ' .. cmd
end
diff --git a/macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua-recorder.lua b/macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua-recorder.lua
new file mode 100644
index 0000000000..8d4aa78af2
--- /dev/null
+++ b/macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua-recorder.lua
@@ -0,0 +1,79 @@
+-- gitinfo-lua-recorder.lua
+-- Copyright 2024 E. Nijenhuis
+--
+-- This work may be distributed and/or modified under the
+-- conditions of the LaTeX Project Public License, either version 1.3c
+-- of this license or (at your option) any later version.
+-- The latest version of this license is in
+-- http://www.latex-project.org/lppl.txt
+-- and version 1.3c or later is part of all distributions of LaTeX
+-- version 2005/12/01 or later.
+--
+-- This work has the LPPL maintenance status ‘maintained’.
+--
+-- The Current Maintainer of this work is E. Nijenhuis.
+--
+-- This work consists of the files gitinfo-lua.sty gitinfo-lua.pdf
+-- gitinfo-lua-cmd.lua, gitinfo-lua-recorder.lua and gitinfo-lua.lua
+
+local kpse = kpse or require('kpse')
+local texio = texio or require('texio')
+
+local api = {
+ record_list = {}
+}
+
+---record_head
+---Records .git/HEAD and .git/refs/heads/<branch> respectively,
+---in order to trigger a rebuild in LaTeX.
+---@param git_directory string
+function api.record_head(git_directory)
+ local head_path = '.git/HEAD'
+ if git_directory then
+ head_path = git_directory .. head_path
+ end
+ if not api.record_list[head_path] then
+ api.record_list[head_path] = true
+ if kpse.in_name_ok(head_path) then
+ local head_file = io.open(head_path, 'rb')
+ if not head_file then
+ texio.write_nl('Warning: couldn\'t read HEAD from git project directory')
+ return
+ end
+ kpse.record_input_file(head_path)
+ texio.write_nl('Info: recording input file ' .. head_path)
+ local head_info = head_file:read('*a')
+ head_file:close()
+ local i, j = string.find(head_info, '^ref: .+\n$')
+ local ref_path = string.sub(head_info, i + 5, j-1)
+ if not ref_path then
+ texio.write_nl('Warning: couldn\'t find ref of HEAD')
+ return
+ end
+ ref_path = '.git/' .. ref_path
+ if git_directory then
+ ref_path = git_directory .. ref_path
+ end
+ if kpse.in_name_ok(ref_path) then
+ kpse.record_input_file(ref_path)
+ texio.write_nl('Info: recording input file ' .. ref_path)
+ else
+ texio.write_nl('Warning: couldn\'t read ref file: ' .. ref_path)
+ end
+ else
+ texio.write_nl('Couldn\'t open input file ' .. head_path)
+ end
+ end
+end
+
+
+
+local gitinfo_recorder = {}
+local gitinfo_recorder_mt = {
+ __index = api,
+ __newindex = nil
+}
+
+setmetatable(gitinfo_recorder, gitinfo_recorder_mt)
+
+return gitinfo_recorder
diff --git a/macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua.lua b/macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua.lua
index 0f3a1315d3..cba19b19d7 100644
--- a/macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua.lua
+++ b/macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua.lua
@@ -1,5 +1,5 @@
-- gitinfo-lua.lua
--- Copyright 2023 E. Nijenhuis
+-- Copyright 2024 E. Nijenhuis
--
-- This work may be distributed and/or modified under the
-- conditions of the LaTeX Project Public License, either version 1.3c
@@ -14,7 +14,7 @@
-- The Current Maintainer of this work is E. Nijenhuis.
--
-- This work consists of the files gitinfo-lua.sty gitinfo-lua.pdf
--- gitinfo-cmd.lua and gitinfo-lua.lua
+-- gitinfo-lua-cmd.lua, gitinfo-lua-recorder.lua and gitinfo-lua.lua
if not modules then
modules = {}
@@ -23,8 +23,8 @@ end
local module = {
name = 'gitinfo-lua',
info = {
- version = '1.0.2', --TAGVERSION
- date = '2024/02/23', --TAGDATE
+ version = '1.0.3', --TAGVERSION
+ date = '2024/04/02', --TAGDATE
comment = "Git info Lua — Git integration with LaTeX",
author = "Erik Nijenhuis",
license = "free"
@@ -81,58 +81,6 @@ function api:escape_str(value)
return buf
end
--- experimental
-function api:get_tok()
- if self.cur_tok == nil then
- self.cur_tok = token.get_next()
- end
- return self.cur_tok
-end
-
--- experimental
-function api:parse_opts()
- local tok = self:get_tok()
- if tok.cmdname == 'other_char' then
- --token.put_next(tok)
- local opts = token.scan_word()
- self.cur_tok = nil
- -- todo: parse []
- return opts
- end
-end
-
--- experimental
-function api:parse_arguments(argc)
- local result_list = {}
- for _ = 1, argc do
- local tok = self:get_tok()
- if tok.cmdname == 'left_brace' then
- token.put_next(tok)
- table.insert(result_list, token.scan_argument())
- self.cur_tok = nil
- else
- tex.error("Expected left brace")
- return
- end
- end
- return table.unpack(result_list)
-end
-
--- experimental
-function api:parse_macro()
- --tex.print('\\noexpand')
- local tok = self:get_tok()
- if (tok.cmdname == 'call') or tok.cmdname == 'long_call' then
- self.cur_tok = nil
- return tok
- else
- tex.error("Expected Macro")
- for i = 1, 5 do
- local _tok = token.get_next()
- end
- end
-end
-
function api:dir(path)
self.cmd.cwd = path
end
diff --git a/macros/luatex/latex/gitinfo-lua/tex/gitinfo-lua.sty b/macros/luatex/latex/gitinfo-lua/tex/gitinfo-lua.sty
index 3f850a1146..c9ab3a4cd6 100644
--- a/macros/luatex/latex/gitinfo-lua/tex/gitinfo-lua.sty
+++ b/macros/luatex/latex/gitinfo-lua/tex/gitinfo-lua.sty
@@ -1,5 +1,5 @@
%% gitinfo-lua.sty
-%% Copyright 2023 E. Nijenhuis
+%% Copyright 2024 E. Nijenhuis
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
@@ -14,9 +14,9 @@
% The Current Maintainer of this work is E. Nijenhuis.
%
% This work consists of the files gitinfo-lua.sty gitinfo-lua.pdf
-% gitinfo-cmd.lua and gitinfo-lua.lua
+% gitinfo-lua-cmd.lua, gitinfo-lua-recorder.lua and gitinfo-lua.lua
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{gitinfo-lua}[2024/02/23 1.0.2 Xerdi's Git Package]
+\ProvidesPackage{gitinfo-lua}[2024/04/02 1.0.3 Xerdi's Git Package]
\RequirePackage{luacode}