The Quick Start chapter explained the basics of using perforce, but discussion of the practical details were deferred. This chapter, which supplements the Quick Start, 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, form syntax, and mapping depots to client workspaces.
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.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:
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 set in the client view, and it is set with the p4 client
command. When p4 client
is typed, a variation of the following form is displayed:
Client: eds_elm Owner: ed Description: Created by ed. Root: /usr/edk/elm Options: nomodtime noclobber |
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. 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
//depotname/file_specificationThe right-hand side of each mapping describes one or more files within the client workspace, and has the form
//clientname/file_specificationThe 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, perform the same two functions:
In the client view
//depot/elm_proj/... //eds_elm/...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.
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
.
p4 client
maps the entire client workspace tree into an identical directory tree in the depot. For example, the default view
//depot/... //eds_elm/...
would 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. As we've seen, mappings don't need to be direct; 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.
View
field can be changed to point to only the portion of the depot that's relevant.Bettie is rewriting the documentation for Elm, which is found in the depot within it's
doc
subdirectory. Her client is named elm_docs
, and her client root is /usr/bes/docs;
she types p4 client
and sets the View
field as follows:
//depot/elm_proj/doc/... //elm_docs/...
The
elm_proj
subdirectory of the depot contains a directory called doc,
which has all the Elm documents. Included in this directory are four files named elm-help.0
through elm-help.3
. Mike wants to separate these four files from the other documentation files in his client workspace, which is called mike_elm
.To do this, he creates a new directory in his client workspace called
help
; it's located at the same level as his doc
directory. The four elm-help
files will go here; he fills in the View
field of the p4 client
form as follows:
//depot/... //mike_elm/... //depot/elm_proj/doc/elm-help.* //mike_elm/help/elm-help.* |
Any file in the depots
doc
subdirectory will be caught by the later mapping and appear in Mike's workspace's help
directory; all other files are caught by the first mapping and will appear in their normal location. This view will also work when copying files from client workspace to the depot.
-
). Whitespace is not allowed between the minus sign and the mapping.Bill, whose client is named
billm
, wants to view only source code; he's not interested in the documentation files. His client view would look like this:
//depot/elm_proj/... //billm/... -//depot/elm_proj/doc/... //billm/doc/... |
Since later mappings take precedence over earlier ones, no files from the depot's
doc
subdirectory will ever be copied to Bill's client. Conversely, if Bill does have a doc
subdirectory in his client, no files from that subdirectory will ever be copied to the depot.
Mike wants to store the files as above, but he wants to take the
elm-help.
X files in the depot and call them helpfile.
X
in his client workspace. He uses the following mappings:
//depot/elm_proj... //mike_elm/... //depot/elm_proj/doc/elm-help.* //mike_elm/help/helpfile.* |
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.
%d
wildcard can be used to rearrange the order of the matched substrings.Mike wants to change the names of any files with a dot in them in such a way that the file's suffixes and prefixes are reversed within his client workspace. For example, he'd like to call the
Ref.guide
file in the depot guide.Ref
in his client workspace. (Mike can be a bit difficult to work with). He uses the following mappings:
//depot/elm_proj... //mike_elm/... //depot/elm_proj/%1.%2 //mike_elm/help/%2.%1 |
Joe has constructed a mapping as follows:
//depot/elm_proj/... //joe/elm/... //depot/nowhere/* //joe/elm/doc/* |
The file
//depot/elm_proj/doc/help
would map via the first line to //joe/elm/doc/help
, but the same file in the client workspace would map back via the higher-precedence second line to //depot/nowhere/help
. Because the file would be written back to a different location in the depot than where it was read from, perforce doesn't map this name at all.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.
sub/dir/./here/foo.c
).
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.
//...
is occasionally used; it means `all files in all depots'. Providing Files as Arguments to Perforce 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.src/lock.c
file. He can give the p4 edit
command in a number of ways:
p4 edit src/lock.c
· While in the src
subdirectory, he could type
p4 edit lock.c
· While in any directory on the client host, he can type
p4 edit //eds_elm/src/lock.c
or
p4 edit //depot/elm_proj/src/lock.c
or
p4 edit /usr/edk/elm/src/lock.c
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.The main 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 remainder of this manual will use these syntaxes interchangably throughout the example set.
The "
*"
wildcard is used the same way in perforce syntax, all UNIX command shells, and most other command shells. Normally, the shell will match "*"
against the contents of the client directory; to have perforce match the "*"
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'
There is one case in which the "...
" wildcard cannot be used, and that is with the p4 add
command. The "..." wildcard is expanded by the p4d
server, and since the server doesn't know what files you're adding (after all, they're not in the depot yet), it can't expand that wildcard. The "*" wildcard can be used with p4 add
; in this case, it is expanded by the local OS shell, not by the p4d
server. 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 #
. Specifying Older File Revisions
All of the commands and examples we've seen thus far have used only the most recent revisions of particular files, but many perforce commands can act on older file versions. For example, if Ed types p4 get //eds_elm/src/lock.c
, the latest revision, or head revision, of lock.c
is retrieved. Older revisions can be retrieved by tacking a revision specification onto the end of the file name. There are seven types of revision specifications:
In all cases, if a file doesn't exist at the given revision number it appears 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 file that doesn't exist at all.
p4 get //edk/doc/*@30Later, he sets up another client for a different user. The new client should have all of the file revisions that Ed last got. Ed sets up the new client specificatioin and types
p4 get //depot//elm_proj/...@edkHe could have typed
p4 get @edkand the effect would have been the same.
Another client needs all its files deleted, but wants to perforce to know that it still has these files. Ed types
p4 get #noneSome OS shells will treat the
#
as a comment character if it starts a new word. If your shell is one of these, escape the #
before use.
If no revision number or range is given where a revision range is expected, the default is all revisions.
p4 add
a file, perforce first determines if the file is a regular file or a symbolic link, and then examines the first part of the file to try to determine whether is it text or binary. If it finds any non-text characters, the file is considered binary; otherwise, the file is considered text.The detected file type can be overridden by using
p4 add -t
type, where type is one of binary
, text
, ltext
, xbinary
, xtext
, ktext
, kxtext
, resource
or symlink
. Descriptions of these file types are given below.A file's type are inherited from one revision to the next. A file can be opened with a different type for the new revision with
p4 edit -t
type. If a file has already been opened with p4 add
or p4 edit
, its type can be changed with p4 reopen -t
type.perforce must sometimes store the complete version of every file in the depot, but most often it stores only the changes in the file since the previous revision. This is called delta storage, and perforce uses RCS format to store its deltas. Whether full file or delta storage is used is determined by the file type. 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.
The perforce file types are:
To find the type of an existing file, use the
p4 opened
reporting command. 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 EDITOR
. 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. 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.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 command reference in this manual. 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 a file specifier, with or without wildcards, to limit reporting to those files that match the arguments on the command line. Without the file specifier, the reports are generated for all files.
Revision specifiers can be used with all of these reporting commands. For example,
p4 files @clientnamecan be used to report on all the files in the depot that are currently found in client clientname.