Perforce 2002.1 User's Guide
<< Previous Chapter
Connecting to the
Perforce Server

Table of Contents
Index
Perforce on the Web
Next Chapter >>
Perforce Basics:
The Details


Chapter 3
Perforce Basics:
Quick Start

This chapter teaches basic Perforce usage. You'll learn how to set up a workspace, populate it with files from the common file repository (the depot), edit these files and submit the changes back to the repository, back out of any unwanted changes, and the basic Perforce reporting commands.

This chapter gives a broad overview of these concepts and commands; for details, see Chapter 4, Perforce Basics: The Details.

Underlying concepts


The basic ideas behind Perforce are quite simple: files are created, edited, and deleted in the user's own directories, which are called client workspaces. Perforce commands are used to move files to and from a shared file repository known as the depot. Perforce users can retrieve files from the depot into their own client workspaces, where they can be read, edited, and resubmitted to the depot for other users to access. When a new revision of a file is stored in the depot, the old revisions are kept and remain accessible.

Perforce was written to be as unobtrusive as possible, so that very few changes to your normal work habits are required. Files are still created in your own directories with your tool of choice; Perforce commands supplement your normal work actions instead of replacing them.

Perforce commands are always entered in the form p4 command [arguments].

File configurations used in the examples

This manual makes extensive use of examples based on the source code set for a program called Elm. The Elm examples used in this manual are set up as follows:

Setting up a client workspace


To move files between a client workspace and the depot, the Perforce server requires two pieces of information:

Naming the client workspace

To name your client workspace, or to use a different workspace, set the environment variable P4CLIENT to the name of the client workspace

Each operating system or shell has its own method of defining environment variables. See the "Environment Variables" section of the Perforce Command Reference for details.

Describing the client workspace to the Perforce server

Once the client workspace has been named, it must be identified and described to the Perforce server with the p4 client command. Typing p4 client brings up the client definition form in a standard text editor; once the form is filled in and the editor exited, the Perforce server is able to move files between the depot and the client workspace.

Note

Many p4 commands, including p4 client, display a form for editing in a standard text editor. You can define the editor your client uses through the P4EDITOR environment variable.

The p4 client form has a number of fields; the two most important are the Root and View. The meanings of these fields are as follows:

Field
Meaning

Root:

Identifies the top subdirectory of the client workspace. This should be the lowest-level directory that includes all the files and directories that you'll be working with.

View:

Describes which files and directories in the depot are available to the client workspace, and where the files in the depot will be located within the client workspace.

The read-only Client: field contains the string stored in the P4CLIENT environment variable. The Description: can be filled with anything at all; it's a place where you can enter text that describes the contents of this client workspace. The View: describes the relationship between files in the depot and files in the client workspace.

Creating a client specification has no immediate visible effect; no files are created when a client specification is created or edited. The client specification simply indicates where files will be located when subsequent Perforce commands are used.

You'll also use p4 client to change existing client specifications. This is described in "Perforce Basics: The Details" on page 33.

Copying depot files into your workspace


Use p4 sync to retrieve files from the depot into a client workspace.

Note

If you're setting up a brand new depot, p4 sync won't do anything, since there are no files in the depot to copy to the client workspace yet.

If this is the case, start by copying files from your client workspace to the depot with p4 add, as described in "Adding files to the depot" on page 25.

The p4 sync command maps depot files through the client view, compares the result against the current client contents, and then adds, updates, or deletes files in the client workspace as needed to bring the client contents in sync with the depot. p4 sync can take filenames as parameters, with or without wildcards, to limit the files it retrieves.

If a file exists within a particular subdirectory in the depot, but that directory does not yet exist in the client workspace, the directory is created within the client workspace at sync time.

The job of p4 sync is to match the state of the client workspace to that of the depot; thus, if a file has been deleted from the depot, p4 sync deletes it from the client workspace.

Updating the depot with files from your workspace


Any file in a client workspace can be added to, updated in, or deleted from the depot. This is accomplished in two steps:

  1. Perforce is told the new state of client workspace files with the commands p4 add filenames, p4 edit filenames, or p4 delete filenames. When these commands are given, the corresponding files are listed in a Perforce changelist, which is a list of files and operations on those files to be performed in the depot.

  2. The operations are performed on the files in the changelist when the p4 submit command is given.

    Note

    This chapter discusses only the default changelist, which is automatically maintained by Perforce. Changelists can also be created by the user; for a full discussion, see Chapter 7, Changelists.

The commands p4 add, p4 edit, and p4 delete do not immediately add, edit, or delete files in the depot. Instead, the affected file and the corresponding operation are listed in the default changelist, and the files in the depot are affected only when this changelist is submitted to the depot with p4 submit. This allows a set of files to be updated in the depot all at once: when the changelist is submitted, either all of the files in the changelist are affected, or none of them are.

When a file has been opened with p4 add, p4 edit, or p4 delete, but the corresponding changelist has not yet been submitted in the depot, the file is said to be open in the client workspace.

Adding files to the depot

To add a file or files to the depot, type p4 add filename(s). The p4 add command opens the file(s) for add and lists them in the default changelist, but they won't be added to the depot until the p4 submit command is given.

At this point, the files he wants to add to the depot have been added to his default changelist. However, the files are not actually stored in the depot until the p4 submit command is given.

The Description: field contents must be changed, or the depot update won't be accepted. Lines can be deleted from the Files: field; any files deleted from this list will carry over to the next default changelist, and will appear again the next time p4 submit is performed.

Adding more than one file at once

Multiple file arguments can be provided on the command line.

If the directory containing a new file does not exist in the depot, it is automatically created within the depot at submit time.

The operating system's write permission on submitted files is turned off in the client workspace when p4 submit is performed. This helps ensure that file editing is done with Perforce's knowledge. The write permissions are turned back on by p4 edit, which is described below.

You might have noticed in the example above that the filenames are displayed as filename#1. Perforce always displays filenames with a #N suffix; the #N indicates that this is the Nth revision of this file. Revision numbers are always assigned sequentially.

Warning!

If a submit fails, the default changelist will be assigned a number, and you'll need to submit that changelist in a slightly different way.

Please see Chapter 5, Perforce Basics: Resolving File Conflicts for instructions on resolving file conflicts.

Populating empty depots

In Perforce, there's no difference between adding files to an empty depot and adding files to a depot that already contains other files. For this reason, populate new, empty depots by adding files from a client workspace with p4 add, as described above.

Editing files in the depot

To open a file for edit, use p4 edit. This has two effects:

Since the files must have their write permission turned back on before they can be edited, you must give the p4 edit command before attempting to edit the file.

To save the new file revision in the depot, use p4 submit, as described above.

Note

Before a file can be opened for edit, it must already have been added to the depot with p4 add, or copied into the client workspace from the depot with p4 sync.

Deleting files from the depot

Files are deleted from the depot in a way similar to the way in which they are added and edited.

The p4 delete command opens the file for delete in the default changelist, and then p4 submit is used to delete the file from the depot. The p4 delete command also deletes the file from the client workspace; this occurs when the p4 delete command is given. The deletion of the file in the depot occurs only after the changelist with the delete operation is submitted.

Once the changelist is submitted, it appears as if the file has been deleted from the depot; however, old file revisions are never actually removed. This makes it possible to read older revisions of "deleted" files back into the client workspace.

Submitting with multiple operations

Multiple files can be included in any changelist. Submitting the changelist to the depot works atomically: either all the files are updated in the depot, or none of them are. (In Perforce's terminology, this is called an atomic change transaction). Changelists can be used to keep files together that have a common purpose.

Files can be deleted from the Files: field; these files are moved into the next default changelist, and appear again the next time p4 submit is performed.

Backing out: reverting files to their unopened states


Any file opened for add, edit, or delete can be removed from its changelist with p4 revert. This command reverts the file in the client workspace back to its unopened state, and any local modifications to the file are lost.

If p4 revert is used on a file that had been opened with p4 delete, it will appear back in the client workspace immediately. If p4 add was used to open the file, p4 revert removes it from the changelist, but leaves the client workspace file intact. If the reverted file was originally opened with p4 edit, the last synced version will be written back to the client workspace, overwriting the newly-edited version of the file. In this case, you may want to save a copy of the file before running p4 revert.

Basic reporting commands


Perforce provides some 20+ reporting commands. Each chapter in this manual ends with a description of the reporting commands relevant to the chapter topic. All the reporting commands are discussed in greater detail in Chapter 11, Reporting and Data Mining.

The most basic reporting commands are p4 help and p4 info.

Command
Meaning

p4 help commands

Lists all Perforce commands with a brief description of each.

p4 help command

For any command provided, gives detailed help about that command. For example, p4 help sync provides detailed information about the p4 sync command.

p4 help usage

Describes command-line flags common to all Perforce commands.

p4 help views

Gives a discussion of Perforce view syntax

p4 help

Describes all the arguments that can be given to p4 help.

p4 info

Reports information about the current Perforce system: the server address, client root directory, client name, user name, Perforce version, and a few other tidbits.

Two other reporting commands are used quite often:

Command
Meaning

p4 have

Lists all file revisions that the Perforce server knows you have in the client workspace.

p4 sync -n

Reports what files would be updated in the client workspace by p4 sync without actually performing the sync operation.


Perforce 2002.1 User's Guide
<< Previous Chapter
Connecting to the
Perforce Server

Table of Contents
Index
Perforce on the Web
Next Chapter >>
Perforce Basics:
The Details

Please send comments and questions about this manual to [email protected].
Copyright 1997-2002 Perforce Software. All rights reserved.
Last updated: 04/03/02