Debian Codegraph @

texmf-dist/doc/latex/gitinfo/gitinfo.tex

raw
1 % gitinfo.tex
2 % Copyright 2011 Brent Longborough
3 %
4 % This work may be distributed and/or modified under the
5 % conditions of the LaTeX Project Public License, either version 1.3
6 % of this license or (at your option) any later version.
7 % The latest version of this license is in
8 % http://www.latex-project.org/lppl.txt
9 % and version 1.3 or later is part of all distributions of LaTeX
10 % version 2005/12/01 or later.
11 %
12 % This work has the LPPL maintenance status `maintained'.
13 % The Current Maintainer of this work is Brent Longborough.
14 %
15 % This work consists of these files:
16 % gitinfo.sty, gitsetinfo.sty, gitinfo.tex, gitinfo.pdf,
17 % post-git-sample.txt, and gitHeadInfo.gin
18 % -----------------------------------------------------
19 \documentclass[a4paper,12pt,twoside,openany]{memoir}
20 \usepackage[pcount,footinfo,grumpy]{gitinfo}
21 \usepackage{tgpagella}
22 \usepackage{tgadventor}
23 \usepackage{fontspec}
24 \defaultfontfeatures{Ligatures=TeX}
25 \setmainfont[Numbers={Proportional,OldStyle}]{TeX Gyre Pagella}
26 \setsansfont[Numbers={Proportional,OldStyle}]{TeX Gyre Adventor}
27 \setmonofont{Consolas}
28 \setulmarginsandblock{0.11111\paperwidth}{0.22222\paperwidth}{*}
29 \setlrmarginsandblock{0.11111\paperwidth}{0.22222\paperwidth}{*}
30 \setheadfoot{1.2\baselineskip}{0.0849\paperwidth}
31 \setmarginnotes{0.125\foremargin}{0.75\foremargin}{\onelineskip}
32 \setheaderspaces{*}{*}{0.618}
33 \checkandfixthelayout[fixed]
34 \tightlists
35 \chapterstyle{bringhurst}
36 \pagestyle{ruled}
37 \settocdepth{section}
38 \setsecnumdepth{none}
39 \newcommand{\sfit}[1]{\textit{#1}}
40 \newcommand{\git}{\sfit{git}}
41 \newcommand{\tpname}{\sfit{gitinfo}}
42 \newcommand{\tpfname}{\textsf{gitinfo.sty}}
43 \newcommand{\ginname}{gitHeadInfo.gin}
44 \newcommand{\metaname}{\texttt{\ginname}}
45 % -----------------------------------------------------
46 \usepackage[%
47 bookmarksnumbered,
48 bookmarksopen,
49 linktocpage,
50 ]{hyperref}
51 \hypersetup{
52 pdfauthor={Brent Longborough},
53 pdftitle={The gitinfo package: git metadata for LaTeX},
54 pdfkeywords={git;metadata;dvcs},
55 }
56 \begin{document}
57 % -----------------------------------------------------
58 \title{%
59 \Huge \tpfname\\[2ex]%
60 \Large A package for accessing metadata\\from the \git\ \textsc{dvcs}
61 }
62 \author{Brent Longborough}
63 \date{29th August, 2011}
64 \maketitle
65
66 {\centering
67 Version:\gitVtagn\\
68 }
69 %\vspace*{2\baselineskip}
70 % -----------------------------------------------------
71 \begingroup
72 \aliaspagestyle{chapter}{empty}
73 \setlength{\afterchapskip}{20pt}
74 \let\clearpage\relax
75 \let\chaptitlefont\Large\bfseries
76 \vspace*{5\baselineskip}
77 \tableofcontents*
78 \clearpage
79 \endgroup
80 % -----------------------------------------------------
81 \chapter{Introduction}
82 More and more, writers are using version control systems
83 to manage the progress of their works.
84 One popular distributed version control system commonly used today
85 is \git.
86
87 Among other blessings, \git provides
88 some useful metadata concerning the history of the developers'
89 work, and, in particular, about the current state of that work.
90
91 \tpname\ allows writers to incorporate some of this metadata
92 into their documents, to show from which point in their development
93 a given formatted copy was produced.
94
95 % - - - - - - - - - - - - - - - - - - - - - - - - - - -
96 \section{How \tpname\ works}
97 \begin{enumerate}
98 \item Whenever you commit work or check out a branch in \git,
99 \git\ executes a \textit{post-commit} or \textit{post-checkout hook}.
100 \item The \tpname\ package includes a sample hook
101 (placed in your \git\ hooks directory),
102 which extracts metadata from \git\ and writes it to a \TeX\ file,
103 named \metaname\ (`gin' for \textbf{g}it \textbf{in}fo).
104 \item When you format your document, \tpname\ reads
105 \metaname\ and stores the metadada
106 in a series of \LaTeX\ commands.
107 \item You may use these commands to insert
108 the metadata you need at any point in the document.
109 \end{enumerate}
110
111 It is important to note that \tpname\ reads the metadata
112 with the equivalent of \texttt{\textbackslash input\{./\ginname\}}.
113 This is necessary to avoid possible future confusion in a
114 \TeX distribution where more than one package includes its
115 metadata in this way; but it requires that for every document which
116 uses \tpname, a \metaname\ must be generated in the same directory.
117
118 If you actually want to use \tpname, then please read on.
119 But you may just be reading this to see whether it will be useful;
120 in this case,
121 please skip the next chapter and go on to (Using the package)
122 on page \pageref{ch:using}.
123 If you like what you see, you can come back to
124 read (Setup) later.
125 % -----------------------------------------------------
126 \chapter{Setup}
127 \tpname\ will be installed by your favourite package or distribution manager,
128 but before you can start to use it,
129 you need to configure each of your \git\ working copies
130 by setting up hooks to capture the metadata.
131 Every document in your working copy that uses \tpname\
132 will need a copy of \metaname\ in the same directory.
133
134 These copies can be generated by the \git\ post-hooks,
135 which need to be configured once, at the start.
136
137 If you're familiar with tweaking \git, you can probably work it out for yourself.
138 If not, I suggest you follow these steps:
139
140 \begin{enumerate}
141
142 \item First, you need a \git\ repository and working tree.
143 For this example, let's suppose that the root of the working tree is in
144 \texttt{\textasciitilde/compsci}
145
146 \item Copy the file \texttt{post-xxx-sample.txt} as \texttt{post-checkout}
147 into the \git\ hooks directory in your working copy.
148 In our example case, you should end up with a file called
149 \texttt{\textasciitilde/compsci/.git/hooks/post-checkout}
150
151 \item With your favourite editor, edit the file you have just created.
152 Very near the start of the file, you will see two lines:
153 \vspace{0.5\baselineskip}
154
155 \noindent\texttt{prefixes=". test docs"\\
156 prefixes="."}
157 \vspace{0.5\baselineskip}
158
159 The first line is an example of how you might configure for multiple
160 copies of \metaname; the second is the default,
161 and means ``the working copy root''.
162
163 If all of your documents will be kept in the root of the working copy,
164 you may leave this file alone.
165 If not, you should delete the line \verb!prefixes="."!, and edit
166 the other line to include the paths, relative to the working copy root,
167 where the documents that need access to \tpname\ are kept.
168
169 Suppose, for example, that you have a project called `compsci'.
170 Your working copy is \texttt{\textasciitilde/compsci}
171 with two paths containing documents,
172 \texttt{\textasciitilde/compsci/docs/essays} and
173 \texttt{\textasciitilde/compsci/docs/reference}.
174 Then you might set up the prefixes like this:
175 \vspace{0.5\baselineskip}
176
177 \noindent\texttt{prefixes="docs/essays docs/reference"}
178 \vspace{0.5\baselineskip}
179
180 which will cause copies of the metadata to be saved in
181 just those two directories.
182 In this example, it will not be accessible to documents
183 kept in the working copy's root
184 (designated by ``.'', omitted in this case),
185
186 \item Test your setup with ``git checkout master''
187 (or another suitable branch name).
188 This should generate copies of \metaname\ in the directories
189 you intended.
190
191 \item Now make two more copies of this file in the same directory (\texttt{hooks}), calling them
192 \texttt{post-commit} and \texttt{post-merge}, and you're done.
193 \end{enumerate}
194 % -----------------------------------------------------
195 \chapter{Using the package}
196 \label{ch:using}
197 Once you've set up your \git hooks, and done your first commit,
198 merge, or checkout to drive them,
199 you can start incorporating the metadata into your document.
200
201 The \tpname\ package is loaded in the usual way:\\[0.5\baselineskip]
202 \texttt{\textbackslash usepackage[$<options>$]\{gitinfo\}}
203
204 % - - - - - - - - - - - - - - - - - - - - - - - - - - -
205 \section{Package options}
206
207 The following options are available:\\[0.5\baselineskip]
208
209 \noindent
210 \begin{tabularx}{\textwidth}{@{}>{\ttfamily\bfseries}lX@{}}
211 grumpy&
212 By default, If \tpname\ can't find \metaname\ (the metadata file),
213 it will set all the metadata to a common value, ``(None)'',
214 issue a package warning, and carry on.
215 If the \texttt{grumpy} option is used,
216 this warning becomes an error, and processing stops.
217 \\
218 \texttt{missing=\textit{text}}&
219 If \tpname\ can't find \metaname (the metadata file),
220 it will normally set all the metadata to a default common value, ``(None)''.
221 If you wish, you can change this value to something else with, say
222 \texttt{missing=Help!} or \texttt{missing=\{What a mess\}}.
223
224 If you have complex needs, as in the second example,
225 don't forget to enclose your text in \{\}s.
226 \\
227 footinfo&
228 For \sfit{memoir} users, \tpname\ will set certain items of metadata into
229 some memoir page footer categories,
230 provided that (a) the memoir package is loaded,
231 and (b) this option is given.
232
233 No warning is given, and no action taken,
234 if this parameter is used with another document class.
235 More detail is given below (For \textit{memoir} users).
236 \\
237 pcount&
238 For \sfit{memoir} users, this option, when used together with \texttt{footinfo},
239 will, in the affected footers, replace the folio with one of the form \textit{x/y},
240 where \textit{x} is the folio and \textit{y} is the page count.
241
242 No warning is given, and no action taken,
243 if this parameter is used with another document class,
244 or if the \texttt{footinfo} option is omitted.
245 More detail is given below (For \textit{memoir} users).
246 \end{tabularx}
247 % - - - - - - - - - - - - - - - - - - - - - - - - - - -
248 \clearpage
249 \section{The metadata}
250 The \git\ metadata, for the current HEAD commit,
251 is made available in the document
252 as a series of parameter-less \LaTeX commands.
253 Here they are:
254 \vspace{0.5\baselineskip}
255
256 \noindent
257 \begin{tabularx}{\textwidth}{@{}>{\ttfamily\bfseries\textbackslash}lX@{}}
258 gitAbbrevHash&
259 The seven-hex-char abbreviated commit hash
260 \\
261 gitHash&
262 The full 40-hex-character commit hash
263 \\
264 gitAuthorName&
265 The name of the author of this commit
266 \\
267 gitAuthorEmail&
268 The email address of the author of this commit
269 \\
270 gitAuthorDate&
271 The date this change was committed by the author,
272 in the format \textit{yyyy-mm-dd}
273 \\
274 gitAuthorIsoDate&
275 The date and time this change was committed by the author,
276 in ISO format, e.g. \textit{2011-08-29 13:05:54 +0100}
277 \\
278 gitAuthorUnixDate&
279 The date and time this change was committed by the author,
280 as a Unix timestamp, e.g \textit{1314619554}
281 \\
282 gitCommitterName&
283 The name of the committer of this commit
284 \\
285 gitCommitterEmail&
286 The email address of the committer of this commit
287 \\
288 gitCommitterDate&
289 The date this change was committed by the committer,
290 in the format \textit{yyyy-mm-dd}
291 \\
292 gitCommitterIsoDate&
293 The date and time this change was committed by the committer,
294 in ISO format, e.g. \textit{2011-08-29 13:05:54 +0100}
295 \\
296 gitCommitterUnixDate&
297 The date and time this change was committed by the committer,
298 as a Unix timestamp, e.g \textit{1314619554}
299 \\
300 gitReferences&
301 A list of any \git\ references (tags, branches) associated
302 with this commit, e.g. \textit{ (HEAD, master)}
303 \\
304 \end{tabularx}
305
306 \vspace{0.5\baselineskip}
307 Three more commands are available, but their use should be considered
308 experimental. \tpname\ searches the \git\ references metadata for
309 anything (probably a \git\ tag) that looks like a number with a decimal point.
310 The first such number it finds is taken as a ``Version Number''
311 and made available in three different formats, explained here:
312 \vspace{0.5\baselineskip}
313
314 \noindent
315 \begin{tabularx}{\textwidth}{@{}>{\ttfamily\bfseries\textbackslash}lX@{}}
316 gitVtag&
317 The version number, without any decorations. If no version number is found,
318 empty (i.e. zero width).
319 \\
320 gitVtags&
321 The version number, with a leading space. If no version number is found,
322 empty.
323 \\
324 gitVtagn&
325 The version number, with a leading space.
326 If no version number is found, a space,
327 followed by the default or specified value of
328 the \texttt{missing} package option.
329 \\
330 \end{tabularx}
331
332 % - - - - - - - - - - - - - - - - - - - - - - - - - - -
333 \section{For \sfit{memoir} users}
334 If you use \sfit{memoir}, \tpname provides some preset page
335 headers and footers for you,
336 if you specify the \texttt{footinfo} option as described above.
337
338 With the \texttt{footinfo} option, \tpname\ redefines
339 the \sfit{plain},\sfit{ruled}, and \sfit{headings} pagestyles.
340
341 For the \sfit{plain} and \sfit{ruled} pagestyles,
342 the folio is moved from the centre to the outer margin of the footer,
343 and a revision stamp is placed in the inner margin.
344
345 For the \sfit{headings} pagestyle,
346 the folio is moved from the outer margin of the header
347 to the outer margin of the footer,
348 and a revision stamp is placed in the inner margin of the footer.
349
350 If, as well, you use the \texttt{pcount} option, a solidus, and the page count,
351 are appended to the folio.
352
353 The revision stamp id generated by this fragment:
354 \vspace{0.5\baselineskip}
355
356 \noindent
357 \verb!Revision\gitVtags: \gitAbbrevHash{} (\gitAuthorDate)!
358 \vspace{0.5\baselineskip}
359
360 \noindent
361 which is set at tiny in the sans-serif font.
362 You can see an example in the footer of this page.
363 % -----------------------------------------------------
364 \chapter{Etc}
365 \section{Acknowledgements \& dependencies}
366
367 The \href{http://tex.stackexchange.com}{\TeX.SE community}
368 has been a constant source of help, inspiration, and amazement.
369 In particular, I'd like to thank
370 \href{http://tex.stackexchange.com/users/73/joseph-wright}{Joseph Wright},
371 who rescued me from the jaws of the TeX parser by explaining
372 \textbackslash expandafter.
373
374 I's also like to register my thanks to the owners of the packages on which
375 \tpname\ depends: etoobox, kvoptions, and xstring.
376
377 The failings, of course, are all mine.
378 % - - - - - - - - - - - - - - - - - - - - - - - - - - -
379 \section{Copyright \& licence}
380 Copyright \copyright\ 2011, Brent Longborough.
381
382 This work --- \tpname\ --- may be distributed and/or modified under the
383 conditions of the LaTeX Project Public License: either version 1.3
384 of this license, or (at your option) any later version.
385
386 The latest version of this license is at
387 \url{http://www.latex-project.org/lppl.txt},
388 and version 1.3 or later is part of all distributions of \LaTeX
389 version 2005/12/01 or later.
390
391 This work has the LPPL maintenance status `maintained';
392 the Current Maintainer of this work is Brent Longborough.
393
394 This work consists of the files
395 gitinfo.sty, gitsetinfo.sty, gitinfo.tex, gitinfo.pdf,
396 post-git-sample.txt, and \ginname.
397 % - - - - - - - - - - - - - - - - - - - - - - - - - - -
398 \section{From the author}
399 Although my limitations as a \TeX nician
400 mean that I've implemented \tpname\ in a rather simplistic way
401 that needs some setup that is more complicated than I wanted,
402 I hope you find the package useful.
403 I'll be very happy to receive your comments by email.\\[\baselineskip]
404 Brent Longborough\\[\baselineskip]
405 \textsf{brent+gitinfo (at) longborough (dot) org}\\
406 and at \href{http://tex.stackexchange.com/users/344/brent-longborough}{\TeX.SE}
407 % -----------------------------------------------------
408 \end{document}