| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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:
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'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 are being added (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.
| 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 p4 client is typed, a variation of the following form is displayed: |
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_specification The right-hand side of each mapping describes one or more files within the client workspace, and has the form //clientname/file_specification 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. Any client view, no matter how elaborate, performs the same two functions:
Wildcards in ViewsAny 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.//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. Types of MappingsBy 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 ViewsThe 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 viewindicates 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 DepotUsually 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.
Bettie is rewriting the documentation for Elm, which is found in the depot within its 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/... Mapping Files in the Depot to a Different Part of the ClientViews 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.
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:
Any file whose name starts with elm-help within the depot's 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. Conversely, any files beginning with elm-help within Mike's client workspace help subdirectory will be mapped to the doc subdirectory of the depot. Excluding Files and Directories from the ViewExclusionary 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.
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: |
Since later mappings have 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. Allowing Filenames in the Client to be Different than Depot FilenamesMappings can be used to make the names of files different in the client workspace than they are in 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: |
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 SubstringsThe %d wildcard matches strings similarly to the * wildcard, but %d 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 within his doc
subdirectory in such a way that the file's suffixes and prefixes are reversed in his client
workspace. For example, he'd like to rename the Elm.cover file in the depot cover.Elm
in his client workspace. (Mike can be a bit difficult to work with). He uses the following
mappings: |
Two Mappings Can Conflict and FailIt 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.
Joe has constructed a view as follows: |
The depot file //depot/elm_proj/doc/help would map to //joe/elm/doc/help, but the same file in the client workspace would map back to the depot 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.
| 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 SyntaxLocal 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). For example, 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 SyntaxPerforce 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.
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 CommandsBecause 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.
Ed wants to delete the src/lock.c file. He can give the p4 delete command in a
number of ways:
|
· While in the src subdirectory, he could type
| · While in any directory on the client host, he can type p4 delete //eds_elm/src/lock.c p4 delete //depot/elm_proj/src/lock.c p4 delete /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. Wildcards and Perforce SyntaxPerforce wildcards may be mixed with both local or Perforce syntax. For example:
| Name and String Limitations
| File NamesBecause 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 LengthsLabel, branch, user, and client workspace names and descriptions no longer have any practical limit on their lengths.
| Specifying 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. There are nine types of revision specifications:
|
|
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 FilenamesRevision 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 @label refers to the revisions of all files in the named label.
Ed wants to retrieve all the doc files into his Elm doc subdirectory, but he wants to see
only those revisions that existed at change number 30. He types
| Later, he creates another client for a different user. The new client should have all of the file revisions that Ed last synced. Ed sets up the new client specification and types p4 sync //depot//elm_proj/...@eds_elm and the effect would have been the same. Another client needs all its files removed, but wants Perforce to know that it still contains those files. Ed sets P4CLIENT to the correct clientname, and types
| 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:
| File Types
Perforce supports normal text files as well as binary, "large text" files, keyword text files, Macintosh resource forks, and symbolic links. Perforce attempts to determine the type of the file automatically: when a file is opened with p4 add, Perforce first determines if the file is a regular file or a symbolic link, and then examines the first part of the file to determine whether is it 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.
| The detected file type can be overridden with p4 add -t type; the file types and descriptions of these types are listed below.
A file's type is 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. 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. 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.
|
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.
| 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, use p4 help command.
| 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.
Revision specifiers can be used with all of these reporting commands, for example can be used to report on all the files in the depot that are currently found in client clientname. Chapter 12, the reporting chapter, contains a more detailed discussion of each of these commands.
|
Please send comments and questions about this manual to
[email protected]. |
Copyright 1997, 1998 Perforce Software. All rights reserved. Last updated: 08/09/98 |