Gentoo Archives: gentoo-pms

From: "Ulrich Müller" <ulm@g.o>
To: gentoo-pms@l.g.o
Subject: [gentoo-pms] [PATCH] Change from vc to gitinfo2 for git metadata.
Date: Tue, 01 May 2018 09:48:41
Message-Id: 23272.14322.114537.895248@a1i15.kph.uni-mainz.de
1 The vc bundle is not included with TeXLive, unmaintained upstream
2 (last release in 2008), and local modifications keep accumulating.
3 ---
4 .gitignore | 2 +-
5 Makefile | 40 +++++++++++++--------
6 eapi-cheatsheet.tex | 6 ++--
7 pms.cls | 15 ++++----
8 vc | 24 -------------
9 vc-git.awk | 85 ---------------------------------------------
10 6 files changed, 38 insertions(+), 134 deletions(-)
11 delete mode 100644 vc
12 delete mode 100644 vc-git.awk
13
14 diff --git a/.gitignore b/.gitignore
15 index 6d150b7..cb749b5 100644
16 --- a/.gitignore
17 +++ b/.gitignore
18 @@ -18,7 +18,7 @@
19 *.tmp
20 *.toc
21 *.xref
22 -vc.tex
23 +gitHeadLocal.gin
24
25 # Emacs backup files and locks
26 *~
27 diff --git a/Makefile b/Makefile
28 index d10a65a..e68b6e4 100644
29 --- a/Makefile
30 +++ b/Makefile
31 @@ -1,5 +1,6 @@
32 -LATEXFILES := $(filter-out vc.tex,$(wildcard *.tex)) pms.cls
33 -SOURCES = $(LATEXFILES) pms.bib vc vc-git.awk Makefile
34 +LATEXFILES := $(wildcard *.tex) pms.cls
35 +SOURCES = $(LATEXFILES) pms.bib Makefile
36 +COMMITINFO = gitHeadLocal.gin
37
38 TWOSIDE =
39
40 @@ -10,7 +11,7 @@ all: pms.pdf
41
42 html: pms.html
43
44 -pms.pdf eapi-cheatsheet.pdf: $(LATEXFILES) pms.bbl vc.tex
45 +pms.pdf eapi-cheatsheet.pdf: $(LATEXFILES) pms.bbl $(COMMITINFO)
46 $(aux-clean)
47 set -e; \
48 while true; do \
49 @@ -32,7 +33,7 @@ eapi-cheatsheet-nocombine.pdf: pms.pdf
50 grep -q 'Warning.*Rerun' eapi-cheatsheet-nocombine.log || break; \
51 done
52
53 -pms.dvi: $(LATEXFILES) pms.bbl vc.tex
54 +pms.dvi: $(LATEXFILES) pms.bbl $(COMMITINFO)
55 $(aux-clean)
56 set -e; \
57 while true; do \
58 @@ -40,7 +41,7 @@ pms.dvi: $(LATEXFILES) pms.bbl vc.tex
59 grep -q 'Warning.*Rerun' pms.log || break; \
60 done
61
62 -pms.html: $(LATEXFILES) pms.bbl vc.tex
63 +pms.html: $(LATEXFILES) pms.bbl $(COMMITINFO)
64 set -e; sum=''; \
65 while true; do \
66 mk4ht xhlatex pms xhtml,fn-in; \
67 @@ -58,26 +59,37 @@ pms.html: $(LATEXFILES) pms.bbl vc.tex
68 @# remove redundant span elements
69 LC_ALL=C sed -i -e ':x;/<span\(\s\+[^>]*\)\?$$/{N;bx;};:y;s/\(<span\s\+[^>]*>\)\([^<]*\)<\/span>\1/\1\2/;ty' $@
70
71 -pms.bbl: pms.bib $(LATEXFILES) vc.tex
72 +pms.bbl: pms.bib $(LATEXFILES) $(COMMITINFO)
73 $(aux-clean)
74 latex pms
75 bibtex pms
76
77 -vc.tex: $(SOURCES)
78 - /bin/sh ./vc -m
79 -
80 -dist: $(SOURCES) vc.tex pms.pdf pms.html
81 +$(COMMITINFO): $(SOURCES)
82 + @# see documentation of gitinfo2.sty
83 + reltag=$$(git describe --tags --long --always --dirty='-*' \
84 + --match='eapi-*-approved*' 2>/dev/null); \
85 + if test -n "$${reltag}"; then \
86 + TZ=UTC git log -1 --date=short-local --decorate=short \
87 + --pretty="format:\usepackage[%%%n shash={%h},%n lhash={%H},%n\
88 + authname={%an},%n authemail={%ae},%n authsdate={%ad},%n\
89 + authidate={%ai},%n authudate={%at},%n commname={%cn},%n\
90 + commemail={%ce},%n commsdate={%cd},%n commidate={%ci},%n\
91 + commudate={%ct},%n refnames={%d},%n reltag={$${reltag}}%n\
92 + ]{gitexinfo}%n" > $@; \
93 + fi
94 +
95 +dist: $(SOURCES) $(COMMITINFO) pms.pdf pms.html
96 PV='$(PV)'; \
97 if test -z "$${PV}"; then \
98 current_eapi=$$(sed -n 's/.*CurrentEAPIIs{\(.*\)}.*/\1/p' pms.tex); \
99 vc_date=$$(sed -n \
100 - 's/.*VCDateISO{\([0-9]*\)-\([0-9]*\)-\([0-9]*\)}.*/\1\2\3/p' \
101 - vc.tex); \
102 + 's/.*commsdate={\([0-9]*\)-\([0-9]*\)-\([0-9]*\)}.*/\1\2\3/p' \
103 + $(COMMITINFO)); \
104 PV=$${current_eapi}_p$${vc_date}; \
105 fi; \
106 echo "PV = $${PV}"; \
107 tar -cJf pms-"$${PV}".tar.xz --transform="s%^%pms-$${PV}/%" \
108 - $(SOURCES) vc.tex && \
109 + $(SOURCES) $(COMMITINFO) && \
110 tar -cJf pms-"$${PV}"-prebuilt.tar.xz --transform="s%^%pms-$${PV}/%" \
111 pms.pdf eapi-cheatsheet.pdf pms*.html pms.css
112
113 @@ -90,7 +102,7 @@ clean:
114 *.lot *.out *.html *.css *.png *.4ct *.4tc *.idv *.lg *.tmp *.xref
115
116 maintainer-clean: clean
117 - rm -f vc.tex
118 + rm -f $(COMMITINFO)
119
120 .PHONY: all html dist upload clean maintainer-clean
121
122 diff --git a/eapi-cheatsheet.tex b/eapi-cheatsheet.tex
123 index 61481d0..038d7ab 100644
124 --- a/eapi-cheatsheet.tex
125 +++ b/eapi-cheatsheet.tex
126 @@ -10,6 +10,7 @@
127 courier
128 }
129 \usepackage[orig,english]{isodate}
130 +\usepackage[local]{gitinfo2}
131 \usepackage[scaled=.90]{helvet}
132 \usepackage[nohyphen]{underscore}
133 \newcommand{\code}[1]{\texttt{#1}}
134 @@ -28,12 +29,11 @@
135 Ulrich Müller \\
136 \href{mailto:ulm@g.o}{ulm@g.o}
137 }
138 -\input{vc.tex}
139 -\ifthenelse{\equal{\VCDateISO}{}}
140 +\ifthenelse{\equal{\gitCommitterDate}{(None)}}
141 {
142 \date{Version \version{}, generated on: \\\today}
143 }{
144 - \date{Version \version\\\printdate{\VCDateISO}}
145 + \date{Version \version\\\printdate{\gitCommitterDate}}
146 }
147 \CutLine*{1}
148 \CutLine*{3}
149 diff --git a/pms.cls b/pms.cls
150 index 66e1828..2b45029 100644
151 --- a/pms.cls
152 +++ b/pms.cls
153 @@ -12,6 +12,7 @@
154 \LoadClass{\ClassToLoad}
155 \PassOptionsToPackage{T1}{fontenc}
156 \PassOptionsToPackage{orig,english}{isodate}
157 +\PassOptionsToPackage{local}{gitinfo2}
158 % Dimensions of the text area. Define a narrow left margin to make
159 % room for margin notes in the right (outer) margin
160 \PassOptionsToPackage{textwidth=400pt,textheight=700pt,
161 @@ -30,6 +31,7 @@
162 \RequirePackage{%
163 fontenc, % Load extended font sets
164 isodate, % Date formatting and conversions
165 + gitinfo2, % Metadata from git
166 geometry, % Set page layout
167 inputenc, % Allow input methods apart from ASCII
168 booktabs, % Nicer formatting of tables
169 @@ -58,9 +60,6 @@
170 }
171 \ClassInfo{pms}{Capsulation of LaTeX stuff for the Package Manager
172 Specification, loaded baseclass: \ClassToLoad\MessageBreak}
173 -% Contains information over the source control system, generated
174 -% through Makefile
175 -\input{vc.tex}
176
177 % Make processing with TeX4HT possible
178 \newboolean{TEX4HT-HACKS}
179 @@ -160,15 +159,17 @@
180 }
181 % Reads the last commit date from the Git repository and even succeeds
182 % when none is available
183 -\ifthenelse{\equal{\VCDateISO}{}}
184 +\ifthenelse{\equal{\gitCommitterDate}{(None)}}
185 {
186 \date{Generated on: \today}
187 \newcommand{\commitinfo}{}
188 }{
189 - \date{\printdate{\VCDateISO}}
190 + \date{\printdate{\gitCommitterDate}}
191 \newcommand{\commitinfo}{%
192 - This version corresponds to commit \VCRevision
193 - \ifthenelse{\VCModified=0}{}{ with local changes}.
194 + This version corresponds to commit \gitAbbrevHash
195 + \ifthenelse{\equal{\gitBranch}{\detokenize{master}}}{}%
196 + { on branch \gitBranch}%
197 + \ifthenelse{\equal{\gitDirty}{}}{}{ with local changes}.%
198 }
199 }
200
201 diff --git a/vc b/vc
202 deleted file mode 100644
203 index 4ad591e..0000000
204 --- a/vc
205 +++ /dev/null
206 @@ -1,24 +0,0 @@
207 -#!/bin/sh
208 -# This is file 'vc' from the vc bundle for TeX.
209 -# The original file can be found at CTAN:support/vc.
210 -# This file is Public Domain.
211 -
212 -# Parse command line options.
213 -full=0
214 -mod=0
215 -while [ -n "$(echo $1 | grep '-')" ]; do
216 - case $1 in
217 - -f ) full=1 ;;
218 - -m ) mod=1 ;;
219 - * ) echo 'usage: vc [-f] [-m]'
220 - exit 1
221 - esac
222 - shift
223 -done
224 -# English locale.
225 -LC_ALL=C
226 -TZ=UTC git --no-pager log -1 HEAD --pretty=format:"Hash: %H%nAbr. Hash: %h%nParent Hashes: %P%nAbr. Parent Hashes: %p%nAuthor Name: %an%nAuthor Email: %ae%nAuthor Date: %ad%nCommitter Name: %cn%nCommitter Email: %ce%nCommitter Date: %cd%n" --date=iso-local | gawk -v script=log -v full=$full -f vc-git.awk > vc.tex
227 -if [ "$mod" = 1 ]
228 -then
229 - git status --porcelain |gawk -v script=status -f vc-git.awk >> vc.tex
230 -fi
231 diff --git a/vc-git.awk b/vc-git.awk
232 deleted file mode 100644
233 index 8b9b052..0000000
234 --- a/vc-git.awk
235 +++ /dev/null
236 @@ -1,85 +0,0 @@
237 -# This is file 'vc-git.awk' from the vc bundle for TeX.
238 -# The original file can be found at CTAN:support/vc.
239 -# This file is Public Domain.
240 -BEGIN {
241 -### Process output of "git status".
242 - if (script=="status") {
243 - modified = 0
244 - }
245 -}
246 -
247 -
248 -
249 -### Process output of "git log".
250 -script=="log" && /^Hash:/ { Hash = substr($0, 2+match($0, ":")) }
251 -script=="log" && /^Abr. Hash:/ { AbrHash = substr($0, 2+match($0, ":")) }
252 -script=="log" && /^Parent Hashes:/ { ParentHashes = substr($0, 2+match($0, ":")) }
253 -script=="log" && /^Abr. Parent Hashes:/ { AbrParentHashes = substr($0, 2+match($0, ":")) }
254 -script=="log" && /^Author Name:/ { AuthorName = substr($0, 2+match($0, ":")) }
255 -script=="log" && /^Author Email:/ { AuthorEmail = substr($0, 2+match($0, ":")) }
256 -script=="log" && /^Author Date:/ { AuthorDate = substr($0, 2+match($0, ":")) }
257 -script=="log" && /^Committer Name:/ { CommitterName = substr($0, 2+match($0, ":")) }
258 -script=="log" && /^Committer Email:/ { CommitterEmail = substr($0, 2+match($0, ":")) }
259 -script=="log" && /^Committer Date:/ { CommitterDate = substr($0, 2+match($0, ":")) }
260 -
261 -### Process output of "git status".
262 -### Changed index?
263 -script=="status" && /^[MADRC]/ { if (modified == 0) modified = 1 }
264 -### Unstaged modifications?
265 -script=="status" && /^.[MD]/ { modified = 2 }
266 -
267 -
268 -
269 -END {
270 -### Process output of "git log".
271 - if (script=="log") {
272 -### Standard encoding is UTF-8.
273 - if (Encoding == "") Encoding = "UTF-8"
274 -### Extract relevant information from variables.
275 - LongDate = substr(CommitterDate, 1, 25)
276 - DateRAW = substr(LongDate, 1, 10)
277 - DateISO = DateRAW
278 - DateTEX = DateISO
279 - gsub("-", "/", DateTEX)
280 - Time = substr(LongDate, 12, 14)
281 -### Write file identification to vc.tex.
282 - print "%%% This file has been generated by the vc bundle for TeX."
283 - print "%%% Do not edit this file!"
284 - print "%%%"
285 -### Write Git specific macros.
286 - print "%%% Define Git specific macros."
287 - print "\\gdef\\GITHash{" Hash "}%"
288 - print "\\gdef\\GITAbrHash{" AbrHash "}%"
289 - print "\\gdef\\GITParentHashes{" ParentHashes "}%"
290 - print "\\gdef\\GITAbrParentHashes{" AbrParentHashes "}%"
291 - print "\\gdef\\GITAuthorName{" AuthorName "}%"
292 - print "\\gdef\\GITAuthorEmail{" AuthorEmail "}%"
293 - print "\\gdef\\GITAuthorDate{" AuthorDate "}%"
294 - print "\\gdef\\GITCommitterName{" CommitterName "}%"
295 - print "\\gdef\\GITCommitterEmail{" CommitterEmail "}%"
296 - print "\\gdef\\GITCommitterDate{" CommitterDate "}%"
297 -### Write generic version control macros.
298 - print "%%% Define generic version control macros."
299 - print "\\gdef\\VCRevision{\\GITAbrHash}%"
300 - print "\\gdef\\VCAuthor{\\GITAuthorName}%"
301 - print "\\gdef\\VCDateRAW{" DateRAW "}%"
302 - print "\\gdef\\VCDateISO{" DateISO "}%"
303 - print "\\gdef\\VCDateTEX{" DateTEX "}%"
304 - print "\\gdef\\VCTime{" Time "}%"
305 - print "\\gdef\\VCModifiedText{\\textcolor{red}{with local modifications!}}%"
306 - print "%%% Assume clean working copy."
307 - print "\\gdef\\VCModified{0}%"
308 - print "\\gdef\\VCRevisionMod{\\VCRevision}%"
309 - }
310 -
311 -### Process output of "git status".
312 - if (script=="status") {
313 - print "%%% Is working copy modified?"
314 - print "\\gdef\\VCModified{" modified "}%"
315 - if (modified==0) {
316 - print "\\gdef\\VCRevisionMod{\\VCRevision}%"
317 - } else {
318 - print "\\gdef\\VCRevisionMod{\\VCRevision~\\VCModifiedText}%"
319 - }
320 - }
321 -}
322 --
323 2.17.0