Friday, October 1, 2010

Controlling Perforce RCS field expansion

Perforce RCS keyword expansion is an immensely useful feature. It allows a developer to quickly apprehend the version and branch information. However, when used with scripts that decorate variables with $, some very odd, unexpected expansions can happen.

Perl scripts are particularly susceptible to this e.g. $Find::file::dir, will almost always be mangled.

I stumbled on the following page that talks a little bit about the issues, but doesn't provide a complete solution.
http://sial.org/howto/perforce/

However, this feature can be turned off or controlled in P4 by changing the file type modifiers. By specifying +ko, the keyword expansion is limited to only $Id:$ and $Header:$.


p4 -c your_cspec reopen -t 'text+ko' your_file


Alternatively, Jeremy Mates was kind enough to point the way:


Change the variable to be incompatible with what Perforce is looking for, while still being valid Perl:

$File -> ${File}

Or change the name of the variable in the Perl script.

No comments: