Perforce 99.2 Command Line User Guide (99.2.ug.2)
<< Previous Chapter
Perforce Basics:
Quick Start

Table of Contents
Glossary
Perforce on the Web
Next Chapter >>
Perforce Basics:
Resolving File Conflicts


Chapter 4
Perforce Basics:
The Details

The Quick Start chapter explained the basics of using Perforce, but discussion of the practical details was deferred. This chapter, which supplements the Quick Start chapter, covers the dry Perforce rules. The topics discussed include views, mapping depots to client workspaces, Perforce wildcards, rules for referring to older file revisions, file types, and form syntax.

It is assumed that the material in the Quick Start chapter has been read and properly digested.

Description of the Client Workspace


A Perforce client workspace is a collection of source files managed by Perforce on a host. Each such collection is given a name which identifies the client workspace to the Perforce server. The name is by default simply the host's name but that can be overridden by the environment variable P4CLIENT. There can be more than one Perforce client workspace on a client host.

All files within a Perforce client workspace share a common root directory, called the client root. In the degenerate case, the client root can be the host's root, but in practice the client root is the lowest level directory under which the managed source files will sit.

Perforce manages the files in a client workspace in a few direct ways. It creates, updates, or deletes files when the user requests Perforce to synchronize the client workspace with the depot; it turns on write permission when the user requests to edit a file; and turns off write permission and submits updated versions back to the depot when the user is finished editing the file.

The entire Perforce client workspace state is tracked by the Perforce server. The server knows what files a client workspace has, where they are, and which files have write permission turned on.

Perforce's management of a client workspace requires a certain amount of cooperation from the user. Since client files are just plain files with write permission turned off, willful users can circumvent the system by turning on write permission, directly deleting or renaming files, or otherwise modifying the file tree supposedly under Perforce's control. Perforce counters this with two measures: first, Perforce has explicit commands to verify that the client workspace state is in accord with the server's recording of that state; second, Perforce tries to make using Perforce at least as easy as circumventing it. For example: to make a temporary modification to a file, it is easier to use Perforce than it is to copy and restore the file manually.

Files not managed by Perforce may also be under a client's root, and they are largely ignored by Perforce. For example, Perforce may manage the source files in a client workspace, while the workspace also holds compiled objects, libraries, executables, as well as a developer's temporary files.

In addition to accessing the client files, the p4 client program sometimes creates temporary files on the client host. Otherwise, Perforce neither creates nor uses any files on the client host.

Wildcards


Perforce uses three wildcards for pattern matching. Any number and combination of these can be used in a single string:

Wildcard
Meaning

*

Matches anything except slashes, matches only within a single directory.

...

Matches anything including slashes; matches across multiple directories

%d

Used for parametric substitution in views. See "Changing the Order of Filename Substrings" on page 29 for a full explanation

The "..." wildcard is passed by the p4 client program to the p4d server, where it is expanded to match the corresponding files known to p4d. The * wildcard is expanded locally by the OS shell before the p4 command is sent to the server, and the files that match the wildcard are passed as multiple arguments to the p4 command. To have Perforce match the * wildcard against the contents of the depot, it must be escaped, usually with quotes or a backslash. Most command shells don't interfere with the other two wildcards.

Wildcards and "p4 add"

The "..." wildcard can't be used with the p4 add command. The "..." wildcard is expanded by the p4d server, and since the server doesn't know what files are being added (after all, they're not in the depot yet), it can't expand that wildcard. The * wildcard may be used with p4 add; it's expanded by the local OS shell, not by the p4d server.

Mapping the Depot to the Client Workspace


Just as a client name is nothing more than an alias for a particular directory on the client machine, a depot name is an alias for a directory on the Perforce server. The relationship between files in the depot and files in the client workspace is described in the client view, and it is set with the p4 client command.

When you type p4 client,Perforce displays a variation of the following form:

Client: eds_elm
Owner: edk
Description:
Created by ed.
Root: /usr/edk/elm
Options: nomodtime noclobber
View:
//depot/... //eds_elm/...

The contents of the View: field determine where client files get stored in the depot, and where depot files are copied to in the client.

Note

The p4 client form has more fields then are described here. For a full discussion, please see our Command Reference.

Multiple Depots

By default, there is a single depot in each Perforce server, and the name of the depot is depot. However, the Perforce system administrator can create multiple depots on the same Perforce server.

If your system administrator has done this, then the default client view will look something like this:

View:
//depot/... //eds_elm/depot/...
//user_depot/...//eds_elm/user_depot/...
//projects/... //eds_elm/projects/...

The Perforce System Adminstrator's Guide explains how to create multiple depots.

Using Views

Views consist of multiple lines, or mappings, and each mapping has two parts. The left-hand side specifies one or more files within the depot, and has the form

The right-hand side of each mapping describes one or more files within the client workspace, and has the form

The left-hand side of a client view mapping is called the depot side; the right-hand side is the client side.

The default view in the example above is quite simple: it maps the entire depot to the entire client workspace. But views can contain multiple mappings, and can be much more complex. All client views, no matter how elaborate, performs the same two functions:

To determine the exact location of any client file on the host machine, substitute the value of the p4 client form's Root: field for the client name on the client side of the mapping. For example, if the p4 client form's Root: field for the client eds_elm is set to /usr/edk/elm, then the file //eds_elm/doc/elm-help.1 will be found on the client host in /usr/edk/elm/doc/elm-help.1.

95/98/NT

On Windows machines, the Perforce client must be specified in a slightly different way if it is to span multiple drives. For details, please see the Windows release notes at <http://www.perforce.com/perforce/technical.html>.

.

Wildcards in Views

Any wildcard used on the depot side of a mapping must be matched with an identical wildcard in the mapping's client side. Any string matched by the wildcard will be identical on both sides.

In the client view

the single mapping contains Perforce's "..." wildcard, which matches everything, including slashes. The result is that any file in the eds_elm client workspace will be mapped to the same location within the depot's elm_proj file tree. For example, the file //depot/elm_proj/nls/gencat/README will be mapped to the client workspace file //eds_elm/nls/gencat/README.

Types of Mappings

By changing the View: field, it's possible to map only part of a depot to a client workspace. It's even possible to map files within the same depot directory to different client workspace directories, or to have files named differently in the depot and the client workspace. This section discusses Perforce's mapping methods.

Direct Client-to-Depot Views

The default view in the form presented by p4 client maps the entire client workspace tree into an identical directory tree in the depot. For example, the default view

indicates that any file in the directory tree under the client eds_elm will be stored in the identical subdirectory in the depot. This view is usually considered to be overkill; most users only need to see a subset of the files in the depot.

Mapping the Full Client to only Part of the Depot

Usually only a portion of the depot is of interest to a particular client. The left-hand side of the View: field can be changed to point to only the portion of the depot that's relevant.

Mapping Files in the Depot to a Different Part of the Client

Views can consist of multiple mappings, which are used to map portions of the depot file tree to different parts of the client file tree. If there is a conflict in the mappings, later mappings have precedence over the earlier ones.

Excluding Files and Directories from the View

Exclusionary mappings allow files and directories to be excluded from a client workspace; this is accomplished by prefacing the mapping with a minus sign ( - ). Whitespace is not allowed between the minus sign and the mapping.

Allowing Filenames in the Client to differ from Depot Filenames

Mappings can be used to make the filenames in the client workspace differ from those in the depot.

Each wildcard on the depot side of a mapping must have a corresponding wildcard on the client side of the same mapping. The wildcards are replaced in the copied-to direction by the substring that the wildcard represents in the copied-from direction.

There can be multiple wildcards; the n-th wildcard in the depot specification corresponds to the n-th wildcard in the client description.

Changing the Order of Filename Substrings

The %d wildcard matches strings similarly to the * wildcard, but %d can be used to rearrange the order of the matched substrings.

Two Mappings Can Conflict and Fail

It is possible for multiple mappings in a single view to lead to a situation in which the name does not map the same way in both directions. When a file doesn't map the same way in both directions, the file is ignored.

In older versions of Perforce, this was often used as a trick to exclude particular files from the client workspace. Because Perforce now has exclusionary mappings, this type of mapping is no longer useful, and should be avoided.

Editing Existing Client Specifications


p4 client can be used at any time to change the client workspace specification. Just as when a client specification is created, changing a specification has no immediate effect on the locations of any files; the location of files in the depot and workspace is affected only when the client specification is used in subsequent commands. To update the files in your client workspace, follow these procedures:

Deleting an Existing Client Specification

An existing client workspace specification can be deleted with p4 client -d clientname. Deleting a client specification has no effect on any files in the client workspace or depot; it simply removes the p4d server's record of the mapping between the depot and the client workspace. To delete existing files from a client workspace, use p4 sync #none (described on page 32) on the files before deleting the client specification, or use the standard local OS deletion commands after deleting the client specification.

Referring to Files on Command Lines


File names provided as arguments to Perforce commands can be referred in one of two ways: by using the names of the files in the client workspace, or by providing the names of the files in the depot. When providing client workspace file names, the user may give the name in either local or Perforce syntax.

Local Syntax

Local syntax is simply a file's name as specified by the local shell or OS. This name may be an absolute path, or may be specified relative to the current directory, although it can only contain relative components at the beginning of the file name (i.e. it doesn't allow sub/dir/./here/foo.c). On UNIX, Ed could refer to the README file at Elm's top level as /usr/edk/elm/README, or in a number of other ways.

Perforce Syntax

Perforce provides its own filename syntax which remains the same across operating systems. Filenames specified in this way begin with two slashes and the client or depot name, followed by the path name of the file relative to the client or depot root directory. The components of the path are separated by slashes.

Examples of Perforce syntax

//depot/...

//elm_client/docs/help.1

Perforce syntax is sometimes called depot syntax or client syntax, depending on whether the file specifier refers to a file in the depot or on the client. But the syntax is the same in either case.

The specifier //... is occasionally used; it means `all files in all depots'.

Providing Files as Arguments to Commands

Because the client view provides a one-to-one mapping between any file in the client workspace and any file in the depot, any file can be specified within any Perforce command in client syntax, depot syntax, or local syntax. A depot's file specifier can be used to refer to a file in the client, and vice-versa. Perforce will do the necessary mapping to determine which file is actually used.

Any filenames provided to Perforce commands can be specified in any valid local syntax, or in Perforce syntax by depot or client. If a client filename is provided, Perforce uses the client view to locate the corresponding file in the depot. If a depot filename is given, the client view is used to locate the corresponding file in the client workspace.

Client names and depot names in a single Perforce server share the same namespace, so Perforce will never confuse a client name with a depot name. Client workspace names and depot names can never be the same.

95/98/NT

The point of this section is worth repeating: any file can be specified within any Perforce command in client syntax, depot syntax, or local syntax. The examples in this manual will use these syntaxes interchangeably.

Wildcards and Perforce Syntax

Perforce wildcards may be mixed with both local or Perforce syntax. For example:

Wildcard
Meaning

J*

Files in the current directory starting with J

*/help

All files called help in current subdirectories

...

All files under the current directory and its subdirectories

.../*.c

All such files ending in .c

/usr/edk/...

All files under /usr/edk

//weasel/...

All files on client (or depot) weasel

//depot/...

All files in the depot named depot

//...

All files in all depots

Name and String Limitations


File Names

Because of Perforce's naming conventions, certain characters cannot be used in file names. These include unprintable characters, the above wildcards, and the Perforce revision characters @ and #.

Name and Description Lengths

Descriptions in the forms used by p4 client, p4 branch, etc, may be of any length. All names given to Perforce objects such as branches, clients, etc can contain no more than 1024 characters.

Using Spaces in Perforce Names

Spaces are allowed in almost any Perforce object: filenames can include spaces, as can branch names, client names, label names, etc. When you provide a space as part of a branch, client, group, user, label, job, or depot name, Perforce translates the space to an underscore. If you use spaces in a client view or client root, quote the string that the space is included within. Make sure not to quote spaces that divide two separate strings; for example, a client mapping containing a space within the client side would be quoted like this:

How to Specify Older File Revisions


All of the commands and examples we've seen thus far have been used to operate only on the most recent revisions of particular files, but many Perforce commands can act on older file versions. For example, if Ed types p4 sync //eds_elm/src/lock.c, the latest revision, or head revision, of lock.c is retrieved, but older revisions can be retrieved by tacking a revision specification onto the end of the file name.

!Warning!

Some OS shells will treat the revision character # as a comment character if it starts a new word. If your shell is one of these, escape the # before use.

Revision Specifier
Meaning
Examples

file#n

Revision number

p4 sync lock.c#3

Refers to revision 3 of file lock.c

file@n

A change number

p4 sync lock.c@126

Refers to the version of lock.c when changelist 126 was submitted, even if it was not part of the change.

p4 sync //depot/...@126

Refers to the state of the entire depot at changelist 126 (numbered changelists are explained in chapter 7).

file@labelname

A label name

p4 sync lock.c@beta

The revision of lock.c in the label called beta (labels are explained in chapter 8).

file@clientname

A client name. The revision of file last taken into client workspace clientname.

p4 sync lock.c@lisag_ws

The revision of lock.c last taken into client workspace lisag_ws

file#none

The nonexistent revision.

p4 sync lock.c#none

Says that there should be no version of lock.c in the client workspace, even if one exists in the depot.

file#head

The head revision, or latest version, of the file.

p4 sync lock.c#head

Except for explicitly noted exceptions, this is identical to referring to the file with no revision specifier.

file#have

The revision on the current client. This is synonymous to @client where client is the current client name.

p4 sync lock.c#have

The revision of lock.cfound in the current client.

file@date

The head revision of the file at 00:00:00 on the morning of that date. Dates are specified as YYYY/MM/DD.

p4 sync lock.c@1998/05/18

The head revision of lock.c as of 00:00:00, May 18, 1998.

file@"date time"

The head revision of the file in the depot on the given date at the given time. The date is specified as above; the time is specified as HH:MM:SS.

p4 sync lock.c@"1998/05/18 15:21:34"

The head revision of lock.c as of May 18, 1998, at 3:21:34 pm

The date and the time must be separated by a single space, and the entire string should be quoted. The time is specified on the 24-hour clock.

! Warning ! Perforce allows you to search on dates with two-digit years; but these years are assumed to fall in the twentieth century. For safety's sake, use four-digit years.

In all cases, if a file doesn't exist at the given revision number, it will appear as if the file doesn't exist at all. Thus, using a label to refer to a file that isn't in the label is indistinguishable from referring to a file that doesn't exist at all.

Using Revision Specifications without Filenames

Revision specifications can be provided without file names. This limits the command's action to the specified revision of all files in the depot or in the client's workspace. Thus, #head refers to the head revisions of all files in the depot, and @labelname refers to the revisions of all files in the named label.

Revision Ranges


A few Perforce client commands can limit their actions to a range of revision numbers, rather than just a single revision. A revision range is two revision specifications, separated by a comma. If only a single revision is given where a revision range is expected, the named revision specifies the end of the range, and the start of the range is assumed to be 1. If no revision number or range is given where a revision range is expected, the default is all revisions.

The commands that accept revision range specifications are:

p4 changes

p4 file

p4 integrate

p4 jobs

p4 print

p4 sync

p4 verify

File Types


Perforce supports four base file types: text files, compressed binary files, Macintosh resource forks, and symbolic links. A host of file type modifiers allow these base types to be extended to include RCS keywords, file compression, and more.

Perforce attempts to determine the type of the file automatically: when a file is opened with p4 add, Perforce first decides if the file is a regular file or a symbolic link, and then examines the first part of the file to determine whether it's text or binary. If any non-text characters are found, the file is assumed to be binary; otherwise, the file is assumed to be text.

A file's type is normally inherited from one revision to the next, but can be overridden or changed with the -t flag:

The filetype argument is specified as basetype+modifiers. For example, to change an open file foo's type to executable text with RCS keyword expansion, use p4 edit -t text+kx foo. Full listings of the base file types and their modifiers are provided below.

The type of an existing file can be determined with p4 opened or p4 files.

File revisions of binary files are normally stored in full within the depot, but only changes made to text files since the previous revision are normally stored. This is called delta storage, and Perforce uses RCS format to store its deltas. The file's type determines whether full file or delta storage is used. When delta storage is used, file merges and file compares can be performed. Files that are stored in their full form can't be merged or compared. (RCS format and delta storage are described in more detail at the start of the next chapter).

Some of the file types are compressed to gzip format for storage in the depot. The compression occurs during the submission process, and decompression happens while syncing. The client workspace will always contain the file as it was submitted.

!Warning!

Do not try to fool Perforce into storing binary files in delta storage by changing the file type to text! If you add a file that that contains a ^Z as text from a Windows client, only the part of the file up to the ^Z will be stored in the depot.

95/98/NT

Versions of Perforce prior to 99.1 used a very different, somewhat limited, set of file types. These have been maintained for backwards compatability.

Mappings between the old and new file types are described in our Command Reference.

The base Perforce file types are:

Keyword
Description
Comments
Server Storage Type

text

Text file

Treated as text on the client. Line-ending translations are performed automatically on Windows and Macintosh clients.

delta

binary

Non-text file

Accessed as binary files on the client. Stored compressed within the depot.

full file, compressed

symlink

Symbolic link

UNIX clients access these as symbolic links; non-UNIX clients treat them as (small) text files.

delta

apple

Multi-forked Macintosh file

AppleSingle storage of Mac data fork, resource fork, file type and file creator. New to Perforce 99.2. For details, please see the Mac client release notes at http://www.perforce.com/perforce/technical.html

AppleSingle, full file,
compressed.

resource

Macintosh resource fork

The only file type for Mac resource forks in Perforce 99.1 and before. Still supported, but we recommend using the new apple file type instead.

For full details, please see the Mac client release notes at http://www.perforce.com/perforce/technical.html

full file,
compressed

The file type modifiers are:

Modifier
Description
Comments

+x

Execute bit set on client

Use for executable files.

+w

File is always writable on client

+k

RCS keyword expansion

Expands the RCS keywords $Id$ and $Header$

+C

Server stores the full compressed version of each file revision

Default server storage mechanism for binary files

+D

Server stores deltas in RCS format

Default server storage mechanism for text files

+F

Server stores full file per revision

Useful for long ASCII files that aren't read by users as text, such as PostScript files.

+S

Only the head revision is stored on the server

Older revisions are overwritten within the depot. Useful for executable or .obj files.

Forms and Perforce Commands


Certain Perforce commands, such as p4 client and p4 submit, present a form to the user to be filled in with values. This form is displayed in the editor defined in the environment variable P4EDITOR. When the user changes the form and exits the editor, the form is parsed by Perforce, checked for errors, and used to complete the command operation. If there are errors, Perforce gives an error message and you must try again.

The rules of form syntax are simple: keywords must be against the left margin and end with a colon, and values must either be on the same line as the keyword or indented on the lines beneath the keyword. Only the keywords already present on the form are recognized. Some keywords, such as the Client: field in the p4 client form, take a single value; other fields, such as Description: , take a block of text; and others, like View: , take a list of lines.

Certain fields, like Client: in p4 client, can't have their values changed; others, like Description: in p4 submit, must have their values changed. If you don't change a field that needs to be changed, or vice-versa, the worst that will happen is that you'll get an error. We've done our best to make these cases as self-evident as possible; when in doubt, consult the User Guide or use p4 help command.

Reading Forms from Standard Input;
Writing Forms to Standard Output

Any commands that require the user to fill in a form, such as the p4 client and p4 submit commands, can read the form from standard input with the -i flag. Similarly, the -o flag can be used to write a form specification to standard output. These two flags are primarily used in scripts that access Perforce: use the -o flag to read a form, process the strings representing the form within your script, and finally, use the -i flag to send the processed form back to Perforce.

For example, to create a new job within a script you could first use p4 job -o > tempfile to read a blank job specification, then add information to the proper lines in tempfile, and finally use
p4 job -i < tempfile to store the new job in Perforce.

The commands that display forms and can therefore use these flags are:

p4 branch

p4 change

p4 client

p4 job

p4 label

p4 protect

p4 submit*

p4 user

* p4 submit can take the -i flag, but not the -o flag.

General Reporting Commands


Many reporting commands have specialized functions, and these are discussed in later chapters. The following reporting commands give the most generally useful information; all these commands can take file name arguments, with or without wildcards, to limit reporting to specific files. Without the file arguments, the reports are generated for all files.

These reports always generate information on depot files, not files within the client workspace. As with any other Perforce command, when a client file is provided on the command line, Perforce maps it to the proper depot file.

Command
Meaning

p4 filelog

Generates a report on each revision of the file(s), in reverse chronological order.

p4 files

Lists file name, latest revision number, file type, and other information about the named file(s).

p4 sync -n

Tells you what p4 sync would do, without doing it.

p4 have

Lists all the revisions of the named files within the client that were last gotten from the depot. Without any files specifier, it lists all the files in the depot that the client has.

p4 opened

Reports on all files in the depot that are currently open for edit, add, delete, branch, or integrate within the client workspace.

p4 print

Lists the contents of the named file(s) to standard output.

p4 where

Given a file argument, display the mapping of that file within the depot, the client workspace, and the local OS.

Revision specifiers can be used with all of these reporting commands, for example p4 files @clientname can be used to report on all the files in the depot that are currently found in client clientname. The reporting chapter, chapter 11, contains a more detailed discussion of each of these commands.


Perforce 99.2 Command Line User Guide (99.2.ug.2)
<< Previous Chapter
Perforce Basics:
Quick Start

Table of Contents
Glossary
Perforce on the Web
Next Chapter >>
Perforce Basics:
Resolving File Conflicts

Please send comments and questions about this manual to [email protected].
Copyright 1997, 1998, 1999, 2000 Perforce Software. All rights reserved.
Last updated: 02/16/00