From e1ef39c5cc171543f57f2aebfb900b00f0703afb Mon Sep 17 00:00:00 2001 From: Christian Faulhammer Date: Wed, 18 Feb 2009 09:30:46 +0100 Subject: [PATCH] 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. --- Makefile | 9 ++++-- pms.tex | 11 +++++++- vc | 24 ++++++++++++++++ vc-git.awk | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 vc create mode 100644 vc-git.awk diff --git a/Makefile b/Makefile index 774fc39..8b49437 100644 --- a/Makefile +++ b/Makefile @@ -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 '//{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 diff --git a/pms.tex b/pms.tex index 6fd03cb..8a14f30 100644 --- a/pms.tex +++ b/pms.tex @@ -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@...} \and Ciaran McCreesh\\\url{ciaran.mccreesh@...}} +% 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} diff --git a/vc b/vc new file mode 100644 index 0000000..5c5a1b3 --- /dev/null +++ b/vc @@ -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}%" + } + } + +} -- 1.6.0.6