Working with Multiple Depots and/or Client Workspaces

A typical configuration of Perforce is handled by setting the P4PORT, P4USER and P4CLIENT environment variables. These variables point at the desired depot, identify the user and select a client workspace.

To quickly switch between different depots or client workspaces I make sure the P4CONFIG environment variable specifies the name of a configuration file. On my Windows XP system this is done by running the command p4 set P4CONFIG=p4config.txt. The p4 command will recognize that this variable is set and will attempt to locate a configuration file each time it is launched. The search begins in the current directory and searches all parent directories until it reaches the root directory for the current drive.

I place a p4config.txt file in each workspace root directory. The file is formatted as a series of lines where each line contains name=value. For example, one of my p4config.txt files looks like this:

P4EDITOR=C:\Program Files\Vim\vim63\vim.exe

My installation of Perforce is configured to use the ticket-based authentication system so I can login to the depot by issuing the p4 login command from a directory below the workspace root. I will be prompted for the password and a ticket will be issued. From this point on I can simply issue p4 commands and the appropriate depot and workspace will be automatically selected.

This technique can be applied to multiple client workspaces at the same time by setting up multiple p4config.txt files and logging into each depot. Then it is a simple matter of changing directories in my command window to switch between depots and/or client workspaces.

On Unix and Mac OS X I set P4CONFIG to point at a file called @.p4config@. The file contents are similar to the Windows example earlier in this post.

Configuring a Perforce Depot on Mac OS X 10.4 (Tiger) Server

Download the latest version of Perforce from their web site ( To setup the server you really only need to download the command-line tools p4 and p4d. Here are links to the versions I used when setting up my server in January 2006.

You may also wish to install the graphical tools P4V and P4Merge. These are part of a single disk image.

Perforce recommends that p4d not be run as root so I created a new user account called p4admin. I also created a new group called perforce. I decided to install the software in the /usr/local/bin directory and to place the depot on a separate drive that is mounted under the /Depot directory.

Automatically starting p4d when the system boots is handled through the utility launchd. Configuring this is done by editing a plist file and then loading it with the utility launchctl. Attached is a copy of the plist file I used. I placed the plist file in the directory /Library/LaunchDaemons. The file is called perforce.plist.

Once the file exists use the launchctl application to tell the launchd program about it. The command I used was:

$ sudo launchctl load /Library/LaunchDaemons/perforce.plist

If you make changes to the plist file and want to reload it use the command below to unload the existing one. Then repeat the above command to load the changed plist.

$ sudo launchctl unload /Library/LaunchDaemons/perforce.plist

Perforce recommends setting up a regular job to create a checkpoint and a backup of the depot. The script p4backup illustrates how to handle this. Use the p4backup.plist file to teach launchd about this script so it will run on a regular basis. On my server I run this script every night. The backup is done using a copy from the /Depot directory to the /Depot.Backup directory, which is on a separate filesystem.

perforce.plist GroupName perforce Label com.perforce.p4d OnDemand Program /usr/local/bin/p4d ProgramArguments /usr/local/bin/p4d -r /Depot -p 1666 -J /Depot/journal -L /Depot/p4err RunAtLoad ServiceDescription Perforce Daemon StandardErrorPath /Depot/p4d.stderr.txt StandardOutPath /Depot/p4d.stdout.txt UserName p4admin WorkingDirectory /Depot