How to store binary files

There are two issues with using cvsnt to store binary files. The first is that cvsnt by default converts line endings between the canonical form in which they are stored in the repository (linefeed only), and the form appropriate to the operating system in use on the client (for example, carriage return followed by line feed for Windows).

The second is that a binary file might happen to contain data which looks like a keyword (Chapter 13, Keyword substitution), so keyword expansion must be turned off.

The third is that storing differences (deltas) between binary files can be very inefficient.

The -kb option available with some cvsnt commands insures that neither line ending conversion nor keyword expansion will be done.

Here is an example of how you can create a new file using the -kb flag:

$ echo '$Id$' > kotest
$ cvs add -kb -m"A test file" kotest
$ cvs ci -m"First checkin; contains a keyword" kotest

If a file accidentally gets added without -kb, one can use the cvs admin command to recover. For example:

$ echo '$Id$' > kotest
$ cvs add -m"A test file" kotest
$ cvs ci -m"First checkin; contains a keyword" kotest
$ cvs update -kb kotest
# For non-unix systems:
# Copy in a good copy of the file from outside CVS
$ cvs commit -fm "make it binary" kotest

When you check in the file kotest the file is not preserved as a binary file, because you did not check it in as a binary file. The cvs update -kb command sets the current keyword substitution method for this file, but it does not alter the working copy of the file that you have. If you need to cope with line endings (that is, you are using cvsnt on a non-unix system), then you need to check in a new copy of the file, as shown by the cvs commit command above.

Older versions of CVS/CVSNT didn't properly version control the expansion option, and had an admin -kb option.

You can also set a default for whether cvs add and cvs import treat a file as binary based on its name; for example you could say that files who names end in .exe are binary. the section called “The cvswrappers file”. There is currently no way to have cvsnt detect whether a file is binary based on its contents. The main difficulty with designing such a feature is that it is not clear how to distinguish between binary and non-binary files, and the rules to apply would vary considerably with the operating system.

The -kB solves the inefficiency problem by using a special binary delta algorithm to store the files. The function is similar to -kb except it is more efficient, and some functions that rely on text deltas, such as cvs annotate do not work with it.

Normally CVS assumes that every file (whether binary or not) is a text file of some sort. This makes sense for most files that you would normally use during development, and the storage of such files is highly efficient.

However, if you are storing pure binary files (libraries, or perhaps Word documents) it is very inefficient to treat them as text files. CVSNT solves this problem with the -kB option. This tells CVSNT to switch to an alternate algorithm to store such files.