fluidthoughts developers' guild

fluid funk

howto / cvs / keywords

Using keyword expansion in CVS

One rather nice feature of cvs is the ability to use keyword expansion (or keyword substitution), this allows for rather nice tracking of stats within the file itself.

One example of using the ID tag can be demonstrated like this:

$Id: keywords.html,v 1.11 2006/03/28 04:37:40 willn Exp $

All that cvs requires is that you insert: $Id: $ all on one line. During the commit process, that keyword is automatically expanded to fill out the proper information. This can be handy in a case where you want to print out the version in case of error:

$debug = "$Id: keywords.html,v 1.11 2006/03/28 04:37:40 willn Exp $";
if ($error) { print "error on line __LINE__\n version: $debug\n"; }

"Id" typically is the most popular tag, but there are others to choose from: https://www.cvshome.org/docs/manual/cvs-1.12.12/cvs_12.html#SEC100

See example of keywords

Treatment of Binary Files

Text files operate differently than binaries. Examples of binary files can include: images, audio, video, PDFs, compiled programs, compressed files, etc. in the hood

If a binary file is added to cvs without being told to restrict the keyword expansion and treat the file as a binary, then weird things can happen.

Randomly, a binary file might contain a line with '$xx: $' where 'xx' just happens to be a member of the keywords tags list. This can mean that the characters which are interpreted as binary, can be swapped to something else that doesn't make sense, potentially corrupting that file.

If this happens, the best thing to do is to remove that file from the cvsroot, and replace it with a fresh copy, then re-add it with the '-kb' flag after the cvs add command.

The tag below shows an example of keyword expansion:

$Id: keywords.html,v 1.11 2006/03/28 04:37:40 willn Exp $

Automatically dealing with filetypes: cvswrappers

The environment variable, $CVSWRAPPERS allows one to point to a file that contains preferences on how to deal with specific filetypes. Various filters can be applied, scripts or programs can be run on different types of files, etc.

Below is an example of how various web graphics files can be ignored upon import, or add:

*.gif    -k 'b' -m 'COPY'
*.jpg    -k 'b' -m 'COPY'
*.pdf    -k 'b' -m 'COPY'
*.png    -k 'b' -m 'COPY'

If you're an administrator, you should be able to add this file as:

$CVSROOT/CVSROOT/cvswrappers

Otherwise, users can add a .cvswrappers file in their home directory, and then define the variable like this:

export $CVSWRAPPERS="$HOME/.cvswrappers"

Much more information can be found in the documentation on the cvshome.org site.

CVS - Concurrent Versioning System