summaryrefslogtreecommitdiff
path: root/macros/luatex
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2024-04-12 03:01:16 +0000
committerNorbert Preining <norbert@preining.info>2024-04-12 03:01:16 +0000
commit230773c2e42cd0257e4150d0b500aa7ca6c1c02a (patch)
treebe69af5c4925af979fe367b30051daa2458042a9 /macros/luatex
parentd0af7e48198e8633e9bc60a77a66515bf39ad69f (diff)
CTAN sync 202404120301
Diffstat (limited to 'macros/luatex')
-rw-r--r--macros/luatex/latex/gitinfo-lua/README.md18
-rw-r--r--macros/luatex/latex/gitinfo-lua/doc/gitinfo-lua-init.lua7
-rw-r--r--macros/luatex/latex/gitinfo-lua/doc/gitinfo-lua.pdfbin116004 -> 122453 bytes
-rw-r--r--macros/luatex/latex/gitinfo-lua/doc/gitinfo-lua.tex95
-rw-r--r--macros/luatex/latex/gitinfo-lua/doc/latexmkrc5
-rw-r--r--macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua-cmd.lua29
-rw-r--r--macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua-recorder.lua32
-rw-r--r--macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua.lua73
-rw-r--r--macros/luatex/latex/gitinfo-lua/tex/gitinfo-lua.sty13
9 files changed, 196 insertions, 76 deletions
diff --git a/macros/luatex/latex/gitinfo-lua/README.md b/macros/luatex/latex/gitinfo-lua/README.md
index 463e764fa1..702eb62fa7 100644
--- a/macros/luatex/latex/gitinfo-lua/README.md
+++ b/macros/luatex/latex/gitinfo-lua/README.md
@@ -5,19 +5,23 @@
A LaTeX package which provides macros integrated with LuaTeX and the commandline tool `git`.
## Installation
-In order to install this package the right way, one should create the release tarball first with `make package`.
-Afterward be sure to unpack the contents of the release tarball anywhere where TeX will find it, i.e. `~/texmf`.
+The recommended way of installing is using `tlmgr install gitinfo-lua`.
+If you can't update/install packages with `tlmgr`, you can download the latest `gitinfo-lua-<version>.tds.tar.gz` from the [releases page](https://github.com/Xerdi/gitinfo-lua/releases) and then unpack it in your `TEXMFHOME`.
+To find out where your `TEXMFHOME` is, you can consult `kpsewhich --var-value TEXMFHOME` on the commandline.
## Documentation
-The documentation can be built using `make` or manually using `lualatex`:
+A prerequisite is that you have the [texmf-packaging](https://github.com/Xerdi/texmf-packaging) available in your `TEXMFHOME`.
+The documentation can be built using `make build clean` or manually using `lualatex`:
```bash
-make build clean
-# Or manually
+# Using the original TEXMFHOME and the project directory
+CNF_LINE="TEXMFHOME={$(pwd),$(kpsewhich --var-value TEXMFHOME)}"
cd doc
-lualatex -shell-escape gitinfo-lua.tex
+lualatex --lua=gitinfo-lua-init.lua --cnf-line $CNF_LINE gitinfo-lua
makeindex -s gind.ist gitinfo-lua.idx
-lualatex -shell-escape gitinfo-lua.tex
+lualatex --lua=gitinfo-lua-init.lua --cnf-line $CNF_LINE gitinfo-lua
```
+To do the same as the Lua initialization script, commandline option `--shell-restricted` should be passed and `git` should be added to `shell_escape_commands` in your `texmf.cnf`.
+The `texmf.cnf` file to edit can be found with `kpsewhich texmf.cnf`.
See the [releases section](https://github.com/Xerdi/gitinfo-lua/releases) for getting the latest manual.
diff --git a/macros/luatex/latex/gitinfo-lua/doc/gitinfo-lua-init.lua b/macros/luatex/latex/gitinfo-lua/doc/gitinfo-lua-init.lua
new file mode 100644
index 0000000000..1877fbab12
--- /dev/null
+++ b/macros/luatex/latex/gitinfo-lua/doc/gitinfo-lua-init.lua
@@ -0,0 +1,7 @@
+-- Global texconfig should already be available when executed with lualatex
+local texconfig = texconfig or require('texconfig')
+
+-- Use restricted shell_escape with git as only command.
+-- Add others where needed, separated with a comma (no spaces in between)
+texconfig.shell_escape = 'p'
+texconfig.shell_escape_commands = 'git'
diff --git a/macros/luatex/latex/gitinfo-lua/doc/gitinfo-lua.pdf b/macros/luatex/latex/gitinfo-lua/doc/gitinfo-lua.pdf
index 693b905da3..c3d5652315 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 fe7bdd4e97..a865389e0c 100644
--- a/macros/luatex/latex/gitinfo-lua/doc/gitinfo-lua.tex
+++ b/macros/luatex/latex/gitinfo-lua/doc/gitinfo-lua.tex
@@ -17,14 +17,20 @@
% gitinfo-cmd.lua and gitinfo-lua.lua
\documentclass{ltxdoc}
\usepackage[english]{babel}
-\usepackage[titlepage,authors]{gitinfo-lua}
+\usepackage[titlepage,authors,rootdir]{gitinfo-lua}
\usepackage{listings}
\lstset{
- basicstyle=\ttfamily,
columns=fullflexible,
+ basicstyle=\ttfamily\lst@ifdisplaystyle\small\fi,
+ commentstyle={\slshape},
+ showspaces=false,
+ showstringspaces=false,
breaklines=true,
- breakatwhitespace=false
+ breakatwhitespace=true,
+ breakindent=1em,
+ prebreak=\raisebox{0ex}[0ex][0ex]
+ { \ensuremath{_{\kern-2.2pt\hookleftarrow}}}
}
\usepackage{calc}
\usepackage{multicol}
@@ -59,7 +65,7 @@
\begin{abstract}
This project aims to display git project information in PDF documents.
- It's mostly written in Lua for executing the \texttt{git} commands, therefore making this package only applicable for \texttt{lualatex} with \texttt{shell escape} enabled.
+ It's mostly written in Lua for executing the \texttt{git} commands, therefore making this package only applicable for \texttt{lualatex}.
If \texttt{lualatex} isn't working for you, you could try \href{https://ctan.org/pkg/gitinfo2}{gitinfo2} instead.
For \LaTeX{} it provides a set of standard macros for displaying basic information or setting the project directory, and a set of advanced macros for formatting commits and tags.
\end{abstract}
@@ -100,8 +106,24 @@ lualatex -shell-escape main
# Generate and keep watching with LaTeXMK
latexmk -pvc -lualatex -shell-escape main
\end{lstlisting}
- Note that in both cases option \texttt{-shell-escape} is required.
+ Note that in both cases option \texttt{--shell-escape} is required.
This is required for issuing \texttt{git} via the commandline.
+ If using \texttt{--shell-restricted} mode, which is the default, make sure to add \texttt{git} to the CSV variable \texttt{shell\_escape\_commands} in either your \texttt{texmf.cnf} or using a Lua initialization script, like:
+ \lstinputlisting[language={[5.3]Lua},caption={Lua initialization script},frame=single]{gitinfo-lua-init.lua}
+
+ \noindent
+ The Lua initialization script can be used as follows:
+ \begin{lstlisting}[language=bash,frame=single,caption={With Lua initialization script},morekeywords=lualatex]
+lualatex --lua=gitinfo-lua-init.lua main
+ \end{lstlisting}
+ For using the script with \texttt{latexmk}, this can be achieved with the \texttt{-lualatex="COMMAND"} option or specifying the \texttt{\$lualatex} command using a \texttt{latexmkrc} configuration file:
+ \begin{lstlisting}[language=bash,frame=single,caption={Overriding Lua\LaTeX\ on commandline},morekeywords=latexmk]
+latexmk --lualatex --lualatex="lualatex --lua=gitinfo-lua-init.lua %O %S" main
+ \end{lstlisting}
+ \begin{lstlisting}[language=perl,frame=single,caption={Overriding Lua\LaTeX\ in \texttt{latexmkrc}}]
+$lualatex = "lualatex --lua=gitinfo-lua-init.lua %O %S";
+ \end{lstlisting}
+ Keep in mind that both the Lua initialization script and \texttt{latexmkrc} need to be placed within the same directory as the main file.\\
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.
@@ -114,18 +136,22 @@ latexmk -pvc -lualatex -shell-escape main
\texttt{\textbraceleft gitinfo-lua\textbraceright}\index[pkgopts]{gitinfo-lua(.sty)}
This package provides some options for default formatting purposes.
The author sorting is one of them.
- If the options contain \meta{contrib} the authors will be sorted based on their contributions, otherwise the authors will be sorted alphabetically, which is the default option \meta{alpha}.
- Another option is the \meta{titlepage} option, which sets the \cmd{\author} and \cmd{\date} macros accordingly.
- By default, it sets the local git author, equivalent to option \meta{author}.
- Pass option \meta{authors} to set all git authors of the project instead.
+ If the options contain \texttt{contrib} the authors will be sorted based on their contributions; otherwise, the authors will be sorted alphabetically, which is the default option \texttt{alpha}.
+ Another option is the \texttt{titlepage} option, which sets the \cmd{\author} and \cmd{\date} macros accordingly.
+ By default, it sets the local git author, equivalent to option \texttt{author}.
+ Pass the option \texttt{authors} to set all git authors of the project based on commit history instead.
+
+ Another option, more concerning directory management, \texttt{rootdir}, sets the current working directory to the root directory of the current project for all \texttt{git} commands that are executed, similar to what \cmd{\gitdirectory} does.
+ If you're using recording of files, this option comes in handy when the main file is in a subdirectory of the project.
+ Otherwise, if the root directory isn't set appropriately, you'll receive the warning `\texttt{Warning: couldn't read HEAD from git project directory}'.
\subsection{Basic macros}\label{sub:tex-basic}
- By default the main file's directory is used as git project directory.
+ By default, the main file's directory is used as git project directory.
This directory can be manipulated with \DescribeMacro{\gitdirectory}\cmd{\gitdirectory}\marg{path}.
- This is only tested with relative paths on Linux.
- \DescribeMacro{\gitunsetdirectory} To undo this operation and switch back to the main file's directory use \cmd{\gitunsetdirectory}.\\
+ The foremost difference between using the \texttt{rootdir} option and the \cmd{gitdirectory} macro, is that the macro can specify a git directory which is part of another project.
+ The main reason for this macro to exist is its usage in the project example in section~\ref{sec:project}.
+ \DescribeMacro{\gitunsetdirectory} To undo an operation done with \cmd{\gitdirectory} and switch back to the main file's directory, use \cmd{\gitunsetdirectory}.\\
- \noindent
\DescribeMacro{\gitversion} The current version can be display by using \cmd{\gitversion} and is equivalent to \texttt{git describe --tags --always}, working for both lightweight and annotated tags.
For this project \cmd{\gitversion} results in \gitversion.
When the version is dirty it will be post fixed with \texttt{-<commit count>-<short ref>}.
@@ -140,10 +166,10 @@ latexmk -pvc -lualatex -shell-escape main
These values are based on \texttt{git config user.name} and \texttt{git config user.email}.
\subsection{Multiple Authors}
- When projects having multiple authors this package can help with the \DescribeMacro{\dogitauthors}\break\cmd{\dogitauthors}\oarg{conj} and \DescribeMacro{\forgitauthors}\cmd{\forgitauthors}\oarg{conj}\marg{csname} macro.
- Where \cmd{\dogitauthors} executes a default formatting implementation of \break\cmd{\git@format@author} and \cmd{\forgitauthors} executes the given \meta{csname} for every author available.
+ When projects having multiple authors, this package can help with the \DescribeMacro{\dogitauthors}\cmd{\dogitauthors}\oarg{conj} and \DescribeMacro{\forgitauthors}\cmd{\forgitauthors}\oarg{conj}\marg{csname} macro.
+ Where \cmd{\dogitauthors} executes a default formatting implementation of \cmd{\git@format@author} and \cmd{\forgitauthors} executes the given \meta{csname} for every author available.
The optional \meta{conj} conjunction makes it possible to even integrate it further.
- For example, when setting the authors in pdfx, the conjunction would be \texttt{[\textbackslash\textbackslash sep\textasciitilde]}, so that the authors are properly separated in the document properties\footnote{See package documentation of \texttt{pdfx}: \url{https://ctan.org/pkg/pdfx}}.
+ For example, when setting the authors in pdfx, the conjunction would be \texttt{[\textbackslash\textbackslash sep ]}, so that the authors are properly separated in the document properties\footnote{See package documentation of \texttt{pdfx}: \url{https://ctan.org/pkg/pdfx}}.
\gitdirectory{../../git-test-project}%
\setlength\xample{4.6cm-5pt}%
@@ -175,12 +201,13 @@ latexmk -pvc -lualatex -shell-escape main
For this section the git project of this document is used due to the fact that there are references to revisions.
The test project's revisions change for every user, since they get recreated every time \texttt{test-scenario.sh} is executed (see section~\ref{sec:project}).\\
+ \clearpage
\noindent
\DescribeMacro{\gitcommit}\oarg{format}\marg{csname}\marg{revision}\\
For displaying commit data \cmd{\gitcommit} can be used.
The optional \texttt{format} takes variables separated by a comma.
The default \texttt{format} is \texttt{h,an,ae,as,s,b}.
- The \texttt{csname} is a user defined command accepting every variable as argument.
+ The \texttt{csname} is a user defined command accepting every variable as argument.\\
\setlength\xample{3.5cm}%
\setlength\xamplesep{0pt}%
\noindent%
@@ -207,9 +234,13 @@ latexmk -pvc -lualatex -shell-escape main
Consult \texttt{man git-log} for possible format variables and omit the \% for every variable.\\
\noindent
- \DescribeMacro{\forgitcommit}\oarg{format}\marg{csname}\marg{rev\_spec}\\
+ \DescribeMacro{\forgitcommit}\oarg{format}\marg{csname}\marg{rev\_spec, files=\{...\}, flags=\{...\}, cwd=...}\\
For displaying multiple commits the~\cmd{\forgitcommit} is used, which has the same arguments as \cmd{\gitcommit}, but only this time the \texttt{csname} is executed for every commit.
- The last argument \texttt{rev\_spec} this time, however, can have no argument or a sequence.
+ The last argument, which originally only took a \texttt{rev\_spec}, now also supports some additional `named' arguments.
+ The argument \meta{files} takes a list of file names relative from the root of the git project.
+ When \meta{files} is given, all commits will be filtered out accordingly.
+ Currently, for \meta{flags}, only \texttt{merges} and \texttt{no-merges} are supported, which includes or excludes merge commits.
+ The \meta{cwd} option is like \cmd{\gitdirectory}, but only for this call.
\noindent\setlength\xample{4.5cm}\setlength\xamplesep{0pt}
\begin{minipage}[t]{\linewidth-\xample-\xamplesep}
@@ -241,7 +272,7 @@ latexmk -pvc -lualatex -shell-escape main
\end{minipage}\\
\gitdirectory{../../git-test-project}
- \clearpage
+% \clearpage
\subsection{Tags}
In this section the \texttt{git-test-project} is used.
@@ -276,7 +307,7 @@ latexmk -pvc -lualatex -shell-escape main
{formattags}
\end{itemize}
}}
- \end{minipage}\\
+ \end{minipage}\\[1em]
This example shows that the versions used are mixed.
This is, of course, a horrible way to manage a project's version, though, we'll continue on with this hard objective.
For example, if we wish to display the author of the lightweight and annotated tag, we can do so by specifying a format using the if-then-else feature of the format specification.
@@ -284,24 +315,27 @@ latexmk -pvc -lualatex -shell-escape main
Here the \texttt{taggername} will show up, or if not present, the \texttt{authorname} will be shown instead.
The default format specification is like the \cmd{\forgitcommit} format, but then again, some bit more complex:\\
- \texttt{refname:short,(taggername)(taggername,taggeremail,taggerdate:short)\\(authorname,authoremail,authordate:short),subject,body}.
- This is a robust example of getting all information, being it a lightweight- or annotated tag.\\
+
+ \hfill\parbox{\linewidth-\parindent}{\texttt{refname:short,(taggername)(taggername,taggeremail,taggerdate:short)\\(authorname,authoremail,authordate:short),subject,body}}\\
+
+ \noindent
+ This is a robust example of getting all information, being it either a lightweight- or annotated tag.\\
For displaying commits in between tags, there's a \DescribeMacro{\forgittagseq}\cmd{\forgittagseq}\marg{csname}.
The \meta{csname} takes exactly three arguments, namely, the \meta{current}, \meta{next tag} and \meta{rev spec}.
- The last iteration gives an empty value for \meta{next tag} and the \meta{rev spec} is identical to \meta{current}.
+ The last iteration gives an empty value for \meta{next tag} and the \meta{rev spec} is identical to \meta{current}.\\
Afterward tag info can be fetched using the \DescribeMacro{\gittag} \cmd{\gittag}\oarg{format}\marg{csname}\marg{tag}.
This macro takes the same formatting specification as \cmd{\fotgittag}.
Beware of using \cmd{\gittag} for the \meta{next tag} parameter in \cmd{\forgittagseq}.
All these macros put together are demonstrated in listing~\ref{lst:changelog} (see next page).
- \clearpage
+% \clearpage
\subsection{Changelog}
This example demonstrates the generation of a changelog.
For simplicity’s sake, every tag is displayed in a \texttt{description} environment's item and within an \texttt{enumerate} environment displaying commits in between.
\begin{lstlisting}[language={[LaTeX]TeX},numbers=left,captionpos=t,caption={Formatting a changelog},label={lst:changelog},morekeywords={commitline,formatversion,gittag,forgitcommit,forgittagseq,printdate}]
-\section*{Changelog}
+\section*{Change History}
\newcommand{\commitline}[1]{\item #1}
\newcommand{\formatversion}[3]{%
\item[#1]
@@ -330,23 +364,24 @@ latexmk -pvc -lualatex -shell-escape main
\noindent
\fbox{
\parbox{\linewidth-8pt-2\fboxsep}{
- {\bfseries\Large Changelog}
+ {\bfseries\Large Change History}
\begin{description}
\forgittagseq{formatversion}%
\end{description}
}
- }\\
+ }\\[1em]
+ \noindent
For displaying the tagline (see line 5) we use the existing \cmd{\printdate} macro of package \texttt{isodate}, which also takes exactly one argument
For every version sequence the commits in between are displayed (see line 7), where the last sequence having the initial commit as second argument plays well with the \cmd{\forgitcommit} macro and makes it possible to show the whole sequence of history.
- \clearpage
\section{Project Example}\label{sec:project}
This documentation uses an example \texttt{project} which gets created by the \texttt{git-scenario.sh} script (see listing~\ref{lst:scenario}).
It creates some commits having dates in the past and different authors set.
Lastly it creates a `lightweight-' and `annotated' tag.
- To set up this scenario either do \texttt{make scenario} or \texttt{bash scenario.sh}.
+ To set up this scenario either do \texttt{make scenario} or execute \texttt{bash git-scenario.sh} in an initialized \texttt{git} repository.
+ Keep in mind that when executing with Bash directly, you may need to specify the path to the Bash file.
\lstinputlisting[language=bash,numbers=left,frame=single,label={lst:scenario},caption={git-scenario.sh},captionpos=t,morekeywords={git,alice,bob,charlie,mkdir,rm,curl,set\_author}]{git-scenario.sh}
\end{document}
diff --git a/macros/luatex/latex/gitinfo-lua/doc/latexmkrc b/macros/luatex/latex/gitinfo-lua/doc/latexmkrc
new file mode 100644
index 0000000000..5683a8b2b1
--- /dev/null
+++ b/macros/luatex/latex/gitinfo-lua/doc/latexmkrc
@@ -0,0 +1,5 @@
+# Adds the gind.ist style, which is required
+$makeindex = "makeindex %O -o %D -s gind.ist %S";
+
+# Cleanup extra auxiliary files
+push @generated_exts, "glo";
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 68ac3c09a9..32d59de180 100644
--- a/macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua-cmd.lua
+++ b/macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua-cmd.lua
@@ -38,12 +38,25 @@ function api.trim(s)
return (s:gsub("^%s*(.-)%s*$", "%1"))
end
-function api:exec(command, do_caching, target_dir)
- local cmd = self.executable .. ' ' .. command
+function api:exec(command, do_caching, target_dir, no_recording, path_spec)
local cwd = target_dir or self.cwd
- api.recorder.record_head(cwd)
+ local cmd = self.executable
if cwd then
- cmd = 'cd ' .. cwd .. ' && ' .. cmd
+ cmd = cmd .. ' -C ' .. cwd
+ end
+ cmd = cmd .. ' ' .. command
+ if not no_recording then
+ api.recorder.record_head(cwd)
+ end
+ if path_spec then
+ if type(path_spec) == 'table' then
+ cmd = cmd .. ' --'
+ for _,path in ipairs(path_spec) do
+ cmd = cmd .. ' ' .. path
+ end
+ elseif type(path_spec) == 'string' then
+ cmd = cmd .. ' -- ' .. path_spec
+ end
end
if do_caching then
local found, result = cache:seek(cmd)
@@ -53,7 +66,7 @@ function api:exec(command, do_caching, target_dir)
end
local f = io.popen(cmd)
if f == nil then
- return nil, "Couldn't execute git command.\n\tIs option '-shell-escape' turned on?"
+ return nil, "Couldn't execute git command.\n\tIs option '--shell-escape' turned on?"
end
local s = f:read('*a')
if f:close() then
@@ -62,7 +75,7 @@ function api:exec(command, do_caching, target_dir)
end
return s
else
- return nil, 'Error executing git command'
+ return nil, 'Error executing git command\n\t"' .. cmd .. '"'
end
end
@@ -142,7 +155,7 @@ function api:parse_response(buffer)
return results
end
-function api:log(format_spec, revision, options, target_dir)
+function api:log(format_spec, revision, options, target_dir, path_spec)
local format, err = self:parse_format_spec(format_spec)
if err then
return nil, err
@@ -155,7 +168,7 @@ function api:log(format_spec, revision, options, target_dir)
if revision and revision ~= '' then
cmd = cmd .. ' ' .. revision
end
- local response, err = self:exec(cmd, true, target_dir)
+ local response, err = self:exec(cmd, true, target_dir, false, path_spec)
if not response then
return nil, err
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
index 8d4aa78af2..4fc798ca69 100644
--- a/macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua-recorder.lua
+++ b/macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua-recorder.lua
@@ -30,7 +30,7 @@ local api = {
function api.record_head(git_directory)
local head_path = '.git/HEAD'
if git_directory then
- head_path = git_directory .. head_path
+ head_path = git_directory .. '/' .. head_path
end
if not api.record_list[head_path] then
api.record_list[head_path] = true
@@ -45,20 +45,24 @@ function api.record_head(git_directory)
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)
+ if i and j then
+ 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('Warning: couldn\'t read ref file: ' .. ref_path)
+ texio.write_nl('Warning: didn\'t find any ref in .git/HEAD')
end
else
texio.write_nl('Couldn\'t open input file ' .. head_path)
diff --git a/macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua.lua b/macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua.lua
index cba19b19d7..8c346ec3be 100644
--- a/macros/luatex/latex/gitinfo-lua/scripts/gitinfo-lua.lua
+++ b/macros/luatex/latex/gitinfo-lua/scripts/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
diff --git a/macros/luatex/latex/gitinfo-lua/tex/gitinfo-lua.sty b/macros/luatex/latex/gitinfo-lua/tex/gitinfo-lua.sty
index c9ab3a4cd6..779f246ed4 100644
--- a/macros/luatex/latex/gitinfo-lua/tex/gitinfo-lua.sty
+++ b/macros/luatex/latex/gitinfo-lua/tex/gitinfo-lua.sty
@@ -16,9 +16,7 @@
% This work consists of the files gitinfo-lua.sty gitinfo-lua.pdf
% gitinfo-lua-cmd.lua, gitinfo-lua-recorder.lua and gitinfo-lua.lua
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{gitinfo-lua}[2024/04/02 1.0.3 Xerdi's Git Package]
-
-\RequirePackage{luacode}
+\ProvidesPackage{gitinfo-lua}[2024/04/11 1.1.0 Xerdi's Git Package]
\directlua{git = require('gitinfo-lua')}
@@ -26,6 +24,7 @@
\newif\ifgit@multipleauthors
\newif\ifgit@setmacros
+\newif\ifgit@toroot
\pgfkeys{/gitinfo-lua/.is family,
/gitinfo-lua,
author sort/.default=false,
@@ -39,7 +38,9 @@
authors/.style={multiple authors=true},
set title page macros/.is if=git@setmacros,
set title page macros=false,
- titlepage/.style={set title page macros=true}
+ titlepage/.style={set title page macros=true},
+ rootdir/.is if=git@toroot,
+ rootdir=false
}
\ProcessPgfPackageOptions*
@@ -81,6 +82,10 @@
}
\newcommand{\forgittagseq}[1]{\directlua{git:cs_for_tag_sequence('#1')}}
+\ifgit@toroot
+ \directlua{git:dir_to_root()}
+\fi
+
\ifgit@setmacros
\ifgit@multipleauthors
\author{\dogitauthors[\\\\]}