diff options
author | Christian Faulhammer <fauli@gentoo.org> | 2009-02-18 09:30:46 +0100 |
---|---|---|
committer | Ciaran McCreesh <ciaran.mccreesh@googlemail.com> | 2009-02-20 16:47:36 +0000 |
commit | 70c5dbab3e126f92ed7d9650224bec15feb9ead9 (patch) | |
tree | 0c4ecb0c4c6307091fe3f4f1ccb1ee3e978ecc88 | |
parent | Add prefixes to labels. (diff) | |
download | pms-70c5dbab3e126f92ed7d9650224bec15feb9ead9.tar.gz pms-70c5dbab3e126f92ed7d9650224bec15feb9ead9.tar.bz2 pms-70c5dbab3e126f92ed7d9650224bec15feb9ead9.zip |
Use date from VC system
Make the \date command aware of the version control system by adding the
vc package (public-domain) and thus display date of last commit and not
of generation as long as a Git repository is available.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 9 | ||||
-rw-r--r-- | pms.tex | 11 | ||||
-rw-r--r-- | vc | 24 | ||||
-rw-r--r-- | vc-git.awk | 89 |
5 files changed, 130 insertions, 4 deletions
@@ -10,3 +10,4 @@ *.lox *.out *.dvi +vc.tex @@ -3,13 +3,13 @@ html : pms.html clean : rm -f *~ *.pdf *.dvi *.log *.aux *.bbl *.blg *.toc *.lol *.loa *.lox \ - *.lot *.out *.html *.css *.png *.4ct *.4tc *.idv *.lg *.tmp *.xref || true + *.lot *.out *.html *.css *.png *.4ct *.4tc *.idv *.lg *.tmp *.xref vc.tex || true LATEXFILES = $(shell ls *.tex) LISTINGFILES = $(shell ls *.listing) SOURCEFILES = $(LATEXFILES) $(LISTINGFILES) -pms.pdf: $(SOURCEFILES) pms.bbl +pms.pdf: $(SOURCEFILES) pms.bbl vc.tex pdflatex pms pdflatex pms pdflatex pms @@ -27,10 +27,13 @@ pms.html: $(SOURCEFILES) pms.bbl @# align algorithm line numbers properly sed -i -e '/<span class="ALCitem">/{N;s/\n\(class="[^"]\+">\)\([0-9]:\)<\/span>/\1\ \2/}' pms.html -pms.bbl: pms.bib pms.tex +pms.bbl: pms.bib pms.tex vc.tex latex pms bibtex pms +vc.tex: pms.tex + /bin/sh ./vc + pms.dvi: $(SOURCEFILES) pms.bbl latex pms latex pms @@ -1,4 +1,5 @@ \documentclass[a4paper]{report} +\input{vc} % Definition of fonts, choose T1 encoding for fonts \usepackage[T1]{fontenc} % @@ -19,6 +20,7 @@ algorithm, algorithmic } +\usepackage[orig,english]{isodate} \usepackage[DIV13]{typearea} \usepackage[position=top]{caption} \usepackage[utf8]{inputenc} @@ -103,10 +105,17 @@ pdfkeywords={Gentoo, package manager, specification}, pdfproducer={pdfLaTeX and hyperref}, } - \title{Package Manager Specification} \author{Stephen P. Bennett\\\url{spb@exherbo.org} \and Ciaran McCreesh\\\url{ciaran.mccreesh@googlemail.com}} +% Make the build succeed even when no Git repository is available +\ifthenelse{\equal{\VCDateISO}{}} +{ + \date{Generated on: \today} +}{ + \date{\printdate{\VCDateISO}} +} + \pagestyle{myheadings} \markboth{\scshape Package Manager Specification}{\scshape Package Manager Specification} @@ -0,0 +1,24 @@ +#!/bin/sh +# This is file 'vc' from the vc bundle for TeX. +# The original file can be found at CTAN:support/vc. +# This file is Public Domain. + +# Parse command line options. +full=0 +mod=0 +while [ -n "$(echo $1 | grep '-')" ]; do + case $1 in + -f ) full=1 ;; + -m ) mod=1 ;; + * ) echo 'usage: vc [-f] [-m]' + exit 1 + esac + shift +done +# English locale. +LC_ALL=C +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: %ai%nCommitter Name: %cn%nCommitter Email: %ce%nCommitter Date: %ci%n" |gawk -v script=log -v full=$full -f vc-git.awk > vc.tex +if [ "$mod" = 1 ] +then + git status |gawk -v script=status -f vc-git.awk >> vc.tex +fi diff --git a/vc-git.awk b/vc-git.awk new file mode 100644 index 0000000..66b3526 --- /dev/null +++ b/vc-git.awk @@ -0,0 +1,89 @@ +# This is file 'vc-git.awk' from the vc bundle for TeX. +# The original file can be found at CTAN:support/vc. +# This file is Public Domain. +BEGIN { + +### Process output of "git status". + if (script=="status") { + modified = 0 + } + +} + + + +### Process output of "git log". +script=="log" && /^Hash:/ { Hash = substr($0, 2+match($0, ":")) } +script=="log" && /^Abr. Hash:/ { AbrHash = substr($0, 2+match($0, ":")) } +script=="log" && /^Parent Hashes:/ { ParentHashes = substr($0, 2+match($0, ":")) } +script=="log" && /^Abr. Parent Hashes:/ { AbrParentHashes = substr($0, 2+match($0, ":")) } +script=="log" && /^Author Name:/ { AuthorName = substr($0, 2+match($0, ":")) } +script=="log" && /^Author Email:/ { AuthorEmail = substr($0, 2+match($0, ":")) } +script=="log" && /^Author Date:/ { AuthorDate = substr($0, 2+match($0, ":")) } +script=="log" && /^Committer Name:/ { CommitterName = substr($0, 2+match($0, ":")) } +script=="log" && /^Committer Email:/ { CommitterEmail = substr($0, 2+match($0, ":")) } +script=="log" && /^Committer Date:/ { CommitterDate = substr($0, 2+match($0, ":")) } + +### Process output of "git status". +### Changed index? +script=="status" && /^# Changes to be committed:/ { modified = 1 } +### Unstaged modifications? +script=="status" && /^# Changed but not updated:/ { modified = 2 } + + + +END { + +### Process output of "git log". + if (script=="log") { +### Standard encoding is UTF-8. + if (Encoding == "") Encoding = "UTF-8" +### Extract relevant information from variables. + LongDate = substr(AuthorDate, 1, 25) + DateRAW = substr(LongDate, 1, 10) + DateISO = DateRAW + DateTEX = DateISO + gsub("-", "/", DateTEX) + Time = substr(LongDate, 12, 14) +### Write file identification to vc.tex. + print "%%% This file has been generated by the vc bundle for TeX." + print "%%% Do not edit this file!" + print "%%%" +### Write Git specific macros. + print "%%% Define Git specific macros." + print "\\gdef\\GITHash{" Hash "}%" + print "\\gdef\\GITAbrHash{" AbrHash "}%" + print "\\gdef\\GITParentHashes{" ParentHashes "}%" + print "\\gdef\\GITAbrParentHashes{" AbrParentHashes "}%" + print "\\gdef\\GITAuthorName{" AuthorName "}%" + print "\\gdef\\GITAuthorEmail{" AuthorEmail "}%" + print "\\gdef\\GITAuthorDate{" AuthorDate "}%" + print "\\gdef\\GITCommitterName{" CommitterName "}%" + print "\\gdef\\GITCommitterEmail{" CommitterEmail "}%" + print "\\gdef\\GITCommitterDate{" CommitterDate "}%" +### Write generic version control macros. + print "%%% Define generic version control macros." + print "\\gdef\\VCRevision{\\GITAbrHash}%" + print "\\gdef\\VCAuthor{\\GITAuthorName}%" + print "\\gdef\\VCDateRAW{" DateRAW "}%" + print "\\gdef\\VCDateISO{" DateISO "}%" + print "\\gdef\\VCDateTEX{" DateTEX "}%" + print "\\gdef\\VCTime{" Time "}%" + print "\\gdef\\VCModifiedText{\\textcolor{red}{with local modifications!}}%" + print "%%% Assume clean working copy." + print "\\gdef\\VCModified{0}%" + print "\\gdef\\VCRevisionMod{\\VCRevision}%" + } + +### Process output of "git status". + if (script=="status") { + print "%%% Is working copy modified?" + print "\\gdef\\VCModified{" modified "}%" + if (modified==0) { + print "\\gdef\\VCRevisionMod{\\VCRevision}%" + } else { + print "\\gdef\\VCRevisionMod{\\VCRevision~\\VCModifiedText}%" + } + } + +} |