File Compression and Locking with p4 Typemap

The Perforce typemap mechanism enables customization of which filetypes should be treated as binary, which should be treated as text, and which file types should be subject to file locking upon edit.  Perforce will attempt to determine filetypes on its own by looking at the high bit in the bytes at the beginning of the file, but some file types can't be reliably determined this way.

Revisions of binary type files are stored intact but text files are differ with the previous revision and only the changes (deltas) are stored.

Settings in the typemap are applied to files at the time the file is added to the depot.  Any files submitted before the p4 typemap settings are applied will not have the settings applied, and will require the filetype to be applied via the command 'p4 edit -t+Fl filename'.  See the Helix Versioning Engine Administrator Guide:Fundamentals for more information on changing the filetype of files submitted before p4 typemap is configured.

Useful File Type Modifiers

+l  Exclusive open (locking)    
 
	If set only one user at a time will be able to open a file for editing.  Useful for binary file types where multiple users shouldn't make incompatible edits to a single file
 
+F  Perforce stores full file per revision, uncompressed
 
	Useful for large binaries, or for long ASCII files that are not read by users as text, such as Postscript files.
 
+C  Perforce stores the full compressed version of each file revision
 
	Default storage mechanism for binary files and newly-added text, unicode, and utf16 files larger than 10MB.
 

File Locking Considerations

Binary files such as Cadence data, that can't be merged should be identified as requiring an exclusive lock with the +l modifier.  If multiple users were to edit the same file it wouldn't be possible to merge all the changes, meaning some work would be lost.  The example typemap file sets all files in the server to require exclusive locking and to remain uncompressed.

For more information see the P4 Command Reference on p4 typemap.

Configuring Libraries or IPs to Prevent File Locking

File locking is appropriate for binary files, but may not be desirable for text based flows, where merging changes (via p4 integrate) is acceptable. File locking can be turned off on a path by path basis in the Perforce repository by making entries in the typemap template for the repository paths corresponding to those Libraries or IPs. Note repositories organized for Libraries and IPs make this process easier. See the Perforce Command reference on p4 typemap.

Binary File Compression Considerations

By default perforce will compress binary type data, however some file formats are already compressed and having Perforce compress them again will consume server CPU resources to little additional benefit.  Compression of these filetypes can be controlled by via the p4 typemap mechanism.

Large Text File Considerations

Storing text files over 2MB in RCS format is inefficient, such large text files should generally be stored as compressed text (text+C)  to avoid the overhead of computing deltas when editing files or accessing old revisions.

File Locking and Edge Servers

Checkouts of +l type files from edge servers can incur a performance penalty as perforce must check the master server for locks.  The 'p4 edit' command can be run with the '-L' flag which enables the -l files to be batch processed as one argument, which improves the overall performance of the command.  See the perforce knowledge base for more information

p4 edit -L [ files ]

Fixing the Filetype

In cases where the filetype has been manually configured differently than the defaults set in the p4 typemap, it may be necessary to change the file type locking behavior directly on existing files. The current p4 filetype can be found using the 'p4 files', 'p4 open', or 'p4 reopen':

> p4 files ...
//mdx_test/tutorial/padring/TRUNK/cds/padring/CLK_GEN/layout/layout.oa#1 - add change 1 (text)
//mdx_test/tutorial/padring/TRUNK/cds/padring/CLK_GEN/layout/master.tag#1 - add change 1 (text)
//mdx_test/tutorial/padring/TRUNK/cds/padring/CLK_GEN/schematic/data.dm#1 - add change 1 (text)
//mdx_test/tutorial/padring/TRUNK/cds/padring/CLK_GEN/schematic/master.tag#1 - add change 1 (text)
//mdx_test/tutorial/padring/TRUNK/cds/padring/CLK_GEN/schematic/sch.oa#1 - add change 1 (text)
//mdx_test/tutorial/padring/TRUNK/cds/padring/CLK_GEN/symbol/master.tag#1 - add change 1 (text)
//mdx_test/tutorial/padring/TRUNK/cds/padring/CLK_GEN/symbol/symbol.oa#1 - add change 1 (text)

To change these files to binary type and to enforce exclusive locking use the 'p4 retype' command:

> p4 retype -t binary+l ...
//mdx_test/tutorial/padring/TRUNK/cds/padring/CLK_GEN/layout/layout.oa#1 - text now binary+l
//mdx_test/tutorial/padring/TRUNK/cds/padring/CLK_GEN/layout/master.tag#1 - text now binary+l
//mdx_test/tutorial/padring/TRUNK/cds/padring/CLK_GEN/schematic/data.dm#1 - text now binary+l
//mdx_test/tutorial/padring/TRUNK/cds/padring/CLK_GEN/schematic/master.tag#1 - text now binary+l
//mdx_test/tutorial/padring/TRUNK/cds/padring/CLK_GEN/schematic/sch.oa#1 - text now binary+l
//mdx_test/tutorial/padring/TRUNK/cds/padring/CLK_GEN/symbol/master.tag#1 - text now binary+l
//mdx_test/tutorial/padring/TRUNK/cds/padring/CLK_GEN/symbol/symbol.oa#1 - text now binary+l

'p4 files' now reports the correct filetype:

> p4 files ...
//mdx_test/tutorial/padring/TRUNK/cds/padring/CLK_GEN/layout/layout.oa#1 - add change 1 (binary+l)
//mdx_test/tutorial/padring/TRUNK/cds/padring/CLK_GEN/layout/master.tag#1 - add change 1 (binary+l)
//mdx_test/tutorial/padring/TRUNK/cds/padring/CLK_GEN/schematic/data.dm#1 - add change 1 (binary+l)
//mdx_test/tutorial/padring/TRUNK/cds/padring/CLK_GEN/schematic/master.tag#1 - add change 1 (binary+l)
//mdx_test/tutorial/padring/TRUNK/cds/padring/CLK_GEN/schematic/sch.oa#1 - add change 1 (binary+l)
//mdx_test/tutorial/padring/TRUNK/cds/padring/CLK_GEN/symbol/master.tag#1 - add change 1 (binary+l)
//mdx_test/tutorial/padring/TRUNK/cds/padring/CLK_GEN/symbol/symbol.oa#1 - add change 1 (binary+l)