2

I am using RCS source control and need to check in an binary file (gif image and a jar file) how do I add an $Header$ keyword so that the version information is replaced in this file during check in and get revealed when I issue "ident" command.

For text files like Java, XML etc we usually add the RCS header comments and public strings but no idea about binary files.

Neil
  • 5,919
  • 15
  • 58
  • 85

2 Answers2

2

Basically, you don't.

Binary file formats don't typically have a way to have a variable-length chunk of arbitrary data. Even if there's a region of the file that can contain arbitrary data, the length of the expansion can vary from one checkout to another (e.g., if it goes from version 1.9 to 1.10), and that's likely to mess up the file.

For this to work, the binary format would have to tolerate a change in the size of the header string. For example, if the version number changes from 1.9 to 1.10, the RCS co command (which has no knowledge of the binary file format) will replace the string in-place, changing the offset of all data following the string. If the file format has a comment section, and that section's size is stored as a number, co isn't going to update that number.

Compiler-generated object and executable files often have RCS version information in them, but it's usually generated from the source file(s); objects and executables themselves typically aren't stored in a version control system.

Before the initial checkin of a binary file, you should run rcs -i -kb filename, so that the RCS co command doesn't attempt to do keyword replacement (just in case the file happens to accidentally contain something that looks like an RCS keyword).

If you have a binary file that you've checked out of an RCS system, and you want to know which version it is, you'll have to compare it to each of the versions in RCS. (My own get-versions might be useful for this.)

If you have a way of storing textual metadata in the file, you could also consider annotating your binary file with a timestamp. You can then correlate the timestamp with the revision by looking at the RCS log.

You mentioned Excel files. I just tried some experiments. The new .xlsx format is really a zip file; anything you put in the Comment section will be compressed, and not visible to ident. The older .xls format, at least for the small file I tried, does store the Comment section in readable text, so ident works -- but when I checked in a file, RCS expanded the Comment from "$Header:$" to "$Header: /home/kst/2012-12-06/RCS/foo.xls,v 1.1 2012-12-06 11:47:48-08 kst Exp kst $"; when I tried to open it with Excel, I got:

Excel found unreadable content in 'foo.xls'.

and it was unable to recover the contents.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • I have to source control the images and archives which would change over the time. I remember I used to check in MS Excel files after entering the RCS header in the File Properties->Comment section in windows. – Neil Dec 06 '12 at 11:12
  • @NeilGhosh: Depending on how MS Excel represents the Comment section, that's likely to fail. See my updated answer. – Keith Thompson Dec 06 '12 at 19:22
  • If you have full control over the source file and can embed a placeholder of exactly the right length and format, you could get lucky. – tripleee Dec 06 '12 at 19:39
  • @tripleee: But RCS can change the size of the placeholder every time it updates the version number, which will change the offset of all data following the string and most likely break the binary format. – Keith Thompson Dec 06 '12 at 19:52
  • Yes, you need to be able to predict the size of the updated header. But maybe you can, either by controlling the circumstances (say, force all user names to be the same length, and start numbering versions at 1.10000; disallow branches and RCS keywords, etc) or by figuring out what will change. – tripleee Dec 06 '12 at 20:08
  • @tripleee: Possibly. It sounds error-prone, and more trouble than it's worth. If you can predict exactly what the new version number is *going* to be, you can set it as a comment before checking in the file -- but it still won't be visible to `ident` if it's a `.xlsx` file, or any format that doesn't store comments as plain text. – Keith Thompson Dec 06 '12 at 20:15
0

In general you can't, but certain binaries has a ASCII slot to place RCS headers.

For example ZIP files

% zip -z archive.zip
 $Header$

And then, after CVS handling:

% unzip -l archive.zip 
$Header: /cygdrive/c/cvsroot/archive.zip,v 1.2 2020/10/14 13:46:06 omg Exp $

There are dozen of extensions extensions that are actually a zip file where you can do this: odt, pdf, ... but use carefully and prefer short RCS headers like Version or Date, because RCS don't know the slot size, and may corrupt the file.

RSG
  • 384
  • 3
  • 7