Define filetypes with p4 typemap
By default, P4 Server has a way of automatically deciding whether a file is text or binary when it adds the file to the depot. You can customize this behavior. It is also possible to change the filetype for a file already in the depot.
On this page:
Default typemap
P4 Server
uses the filesys.binaryscan configurable to determine how
many bytes to examine when determining if a file is of type
text or binary. By default,
filesys.binaryscan is 65536. If the high bit is clear in the
first 65536 bytes,
P4 Server
assumes it to be text. Otherwise, it is assumed to be
binary.
Files compressed in the .zip format, including .jar files, are also automatically detected and
assigned the type binary+F, where +F is a file type modifier. To learn more, see File type modifiers in P4 CLI Reference.
Filetype detection is usually correct. However there might be exceptions or different user requirements. For example, RTF (Rich Text Format) and Adobe PDF (Portable Document Format) can start with a series of comment fields or other textual data. If these comments are sufficiently long, such files can be erroneously detected by the P4 Server as being of type text.
Change the default filetype detection
To change the default filetype detection, create a typemap with the p4 typemap command. This command enables you to map P4 Server file types to file specifications defined in depot syntax The syntax for specifying the location of files in the P4 Server depot as opposed to in the user's client workspace. Depot syntax begins with //depotName/. When a file is being added and it matches a mapping in the typemap table, the corresponding filetype is assigned. Definitions for the typemap are applied to new files being added.
For example, to treat zip and jar files as
binary instead of binary+F, use p4 typemap to modify the
typemap table:
Typemap:
binary //....zip
binary //....jar
binary+w //...user-lib...
The first three periods (...) in the specification are a P4 Server wildcard specifying all files in all depots are to be included in the mapping.
In lines 2 and 3, the fourth period and the file extension specify that files with the .zip or .jar extension are mapped to binary.
Line 4 specifies that any file with user-lib in its name or path be assigned binary+w as its filetype.
To learn more, see Wildcards in P4 CLI Reference.
Common file extensions
Consider these P4 Server file types and modifiers for common file extensions:
| File type | P4 Server file type | Description |
|---|---|---|
|
|
|
Active server page file. |
|
|
|
Video for Windows file. |
|
|
|
Windows bitmap file. |
|
|
|
Btrieve database file. |
|
|
|
Conference link file. |
|
|
|
Cascading style sheet file. |
|
|
|
Microsoft Word document. |
|
|
|
Microsoft Word template. |
|
|
|
Export file or Microsoft Visual C++ |
|
|
|
GIF graphic file. |
|
|
|
Gzip compressed file. |
|
|
|
HTML file. |
|
|
|
HTML file. |
|
|
|
Icon file. |
|
|
|
Active Server include file. |
|
|
|
Initial application settings file. |
|
|
|
JPEG graphic file. |
|
|
|
JavaScript language source code file. |
|
|
|
Library file. |
|
|
|
Log file. |
|
|
|
MPEG video file. |
|
|
|
Adobe PDF file. |
|
|
|
SAP Power Designer file. |
|
|
|
Microsoft PowerPoint file. |
|
|
|
Unity3D file. |
|
|
|
Microsoft Excel file. |
Example typemap
Use the following p4 typemap table to map file extensions to the
P4 Server
file types recommended in the preceding table.
# Perforce File Type Mapping Specifications.
#
# TypeMap: a list of filetype mappings; one per line.
# Each line has two elements:
# Filetype: The filetype to use on 'p4 add'.
# Path: File pattern which will use this filetype.
# See 'p4 help typemap' for more information.
TypeMap:
text //....asp
binary+F //....avi
binary //....bmp
binary //....btr
text //....cnf
text //....css
binary //....docx
binary //....dotx
binary+w //....exp
binary+F //....gif
binary+F //....gz
text //....htm
text //....html
binary //....ico
text //....inc
text+w //....ini
binary //....jpg
text //....js
binary+w //....lib
text+w //....log
binary+F //....mpg
binary //....pdf
text+w //....pdm
binary //....ppt
binary //....xlsx
If a file type requires the use of more than one file type modifier,
specify the modifiers consecutively. For example,
binary+lFS10 refers to a binary file with
exclusive-open (l), stored in full (F) rather
than compressed, and for which only the most recent ten revisions are
stored (S10).
Specify the filetype at the command line
Regardless of whether you have set up your own typemap or not, you might want to change the filetypes of files that have already been added to the depot. You also might want to manually add files with a different filetype than would occur otherwise.
To override the default filetype detection when opening a file for add, use:
p4 add -t
or
p4 reopen -t
To change the filetype for existing files, use:
p4 edit -t
or
p4 reopen -t
To learn more, see File type modifiers in P4 CLI Reference, which also provides additional information about
Overriding file type with the -t option.