Version Control

From Wiki
Jump to navigation Jump to search

Version control

Version or revision control software like Bazaar, Git and Subversion, is used for managing different versions or revisions of files [1]. This can be used for different reasons. For instance for collaborate editing of files and keeping track of who edits what. Programmers use this kind of software, but it is also useful as a backup mechanism for TeX files.

Stephan Hennig created a version control bundle for TeX and friends [2]. This bundle, meant not only for LaTeX but for TeX and friends, is useful for getting among other things revision number of your project to use it in your TeX-document. Of course you should have Bazaar, Git or Subversion installed and (some of) the files in your directory should be under version control. GNU awk is also required.

The bundle basically consists of some scripts which produce a vc.tex file with some macros which can be used in a ConTeXt file:

input vc

The manual of the bundle is very clear. For your convenience here an example of how to use the macros with Git [3]. Derived from Mark Eli Kalderon [4] and the vc manual.

\enableregime[utf]

%\immediate\write18{sh ./vc} 
\input vc

\starttext 

\startitemize
\item VCRevision = \VCRevision\ current (maximum) working copy revision number
\item VCRevisionMod = \VCRevisionMod\ as VCRevision = \VCRevision, but with an additional note if the working copy contains modified files
\item VCAuthor = \VCAuthor\ author of the last check-in operation
\item VCDateRaw = \VCDateRAW\ date of last check-in in native format of the VCS software
\item VCDateISO = \VCDateISO\ date of last check-in in ISO format YYYY-MM-DD
\item VCDateTEX = \VCDateTEX\ date of last check-in in TeX format YYYY/MM/DD
\item VCTime = \VCTime\ time of last check-in
\item VCModifiedText = \VCModifiedText\ contains the note shown in macro VCRevisionMod = \VCRevisionMod\ if there were modified files.
This macro can be redefined by the user.
\item VCModified = \VCModified\ 0 if there are no modified files in the working copy directory; 1 or 2 if there are modified files.
In general you don't need this macro.
\stopitemize

These macros can be called wherever appropriate. 

Revision: \VCRevision ; Author: \VCAuthor ; Date: \VCDateISO

\startitemize
\item GITHash = \GITHash\ 40-hexdigit SHA1 commit hash
\item GITAbrHash = \GITAbrHash\ abbreviated commit hash  
\item GITParentHashes = \GITParentHashes\ parent hashes
\item GITAbrParentHashes = \GITAbrParentHashes\ abbreviated parent hashes
\item GITAuthorName = \GITAuthorName\ author name
\item GITAuthorEmail = \GITAuthorEmail\ author email
\item GITAuthorDate = \GITAuthorDate\ author date
\item GITCommitterName = \GITCommitterName\ committer name
\item GITCommitterEmail = \GITCommitterEmail\ committer e-mail
\item GITCommitterDate = \GITCommitterDate\ committer date
\stopitemize

\stoptext

A Simple Solution in Mkiv

The vc.tex bundle is certainly nice and powerful, but I found it somewhat difficult to install. If you are using mkiv and just want to typeset some information from your version control system, there is an easier solution: you can typeset the output of system commands via lua code. Here is an example that will print the revision and date of a mercurial system:

\ctxlua{context(os.resultof("hg id -i -r tip"))}: 
\ctxlua{context(os.resultof("hg log -r tip --template '{date|isodate}'"))}

The same would work with any version control system; all you need to do is consult its documentation to figure out the exact syntax to receive the information you want to typeset.