Using RCS* Keywords

How do you use RCS* keywords in Perforce? Which RCS keywords are supported?

Info & Tags

Article #:
54
Created:
04/25/07
Modified:
01/09/08

Related Articles

Task

How do you use RCS* keywords in Perforce?  Which RCS keywords are supported?

Solution

Files of Perforce type text+k or text+ko can have RCS-style keyword strings inserted in them. All keyword strings are bounded by the $ character. When files of this type are synced to a Perforce client workspace, the keywords strings are replaced with new text strings denoting file properties such as pathname and date.

As of Release 2000.1, Perforce expands the following keywords in text+k (ktext) files:

  • $Id$
  • $Header$
  • $Date$
  • $DateTime$
  • $Change$
  • $File$
  • $Revision$
  • $Author$

Prior to Release 2000.1, Perforce supported only two keywords, $Id$ and $Header$.

When upgrading a pre-2000.1 release server to version 2000.1 or greater, files of type text+k (ktext) from are automatically migrated to type text+ko. The text+ko type on the 2000.1+ server is equivalent to the text+k of pre-2000.1 servers.

See the P4 Command Reference section on File Types under Keyword Expansion for more details.

Example

Change file "main.c" into a ktext file using the -t flag in p4 add or p4 edit.

        p4 edit -t +k main.c
//depot/test/main.c#9 - opened for edit

The file "main.c" is now of Perforce type text+k. This file contains all of the available RCS keywords, entered one per line. Using a Perforce version 2000.1 (or later) Server and Client, the keywords expand as follows:

"main.c" file before submission to server:

	$Id$
$Header$
$Date$
$DateTime$
$Change$
$File$
$Revision$
$Author$

Submitting "main.c"

	p4 submit main.c
Checking that "main.c" is ktext

	p4 files main.c
//depot/test/main.c#10 - edit change 1745 (ktext)

"main.c" file after sync and refresh in client workspace:

	$Id: //depot/test/main.c#10 $
$Header: //depot/test/main.c#10 $
$Date: 2006/06/21 $
$DateTime: 2006/06/21 17:42:19 $
$Change: 1745 $
$File: //depot/test/main.c $
$Revision: #10 $
$Author: michael $

* RCS is an acronym for Revision Control System, a file versioning system authored by Walter F. Tichy in the early 1980s. RCS is included with most Unix/GNU/Linux distributions. Perforce does not implement the full range of keywords present in RCS. Perforce and RCS keywords of the same name might expand differently.