15 articles

Backup, Recovery & Optimization Scripts

Published by Marco on in Perforce

Perforce servers have a checkpointing mechanism in order to back up the server metadata. That checkpoint, along with the depot data and a journal file (for changes made since the checkpoint was taken) are enough to restore a Perforce database.

Here at Encodo, we take a checkpoint every evening right before the depot files are backed up. We retain a few days worth of these checkpoints, just in case. Since our server runs on Debian Etch (Linux), we have a Bash script to do all of this (included below). The comments in the script should be enough to get a gist of what’s going on; adjust the values of the variables at the top of the script to correspond to your installation.



# Verify the depot
$P4 -p $HOST -u $USER -P $PASSWORD verify -q //… > /dev/null
$P4 -p $HOST -u $USER -P $PASSWORD verify -u -q //… > /dev/null 2> /dev/null

# Take a... [More]

Missing Menu Entries in P4V

Published by Marco on in Perforce

The P4V client for Perforce gets better with each version and is in many ways much better than its predecessor on Windows, P4Win. However, if you’ve upgraded through several versions – possibly including beta versions – you may not be seeing the full client. On both Windows Vista and Windows XP, we’ve noticed that shortcut menu entries are missing on some clients. That is, a user on one machine sees ten commands available when right-clicking on a file whereas another user sees only five.

After writing to Perforce support, we got this nearly immediate response:

“Can you please try deleting your “.p4qt” directory, which can be found normally in “C:\Users\<user>\”, replacing <user> with your Windows user name[?] Another thing to check is that the P4V client is using the correct version of the QT DLL’s. Can you please search your system for any DLL’s containing “QT” and let me know what you find.”

The .p4qt directory contains all of your client settings, including windows sizes,... [More]

Perforce Branching Specification Typo

Published by Marco on in Perforce

At Encodo, we use the Perforce source control system. Recently, I created a branch specification in order to maintain bug fixes in a released product. See below:

//depot/branches/customername/versionnumber/projects/encodo/quino... //depot/projects/encodo/quino/...

Naturally, the next thing I did was to branch the files under //depot/projects/encodo/quino/ to the branch, using the P4V client. It displayed the new changelist, but did not update the statuses of the files therein (there were only a couple of hundred files). Strange. Stopping the command progress and refreshing manually also didn’t help and, within a few seconds, complaints rained in from coworkers that Perforce had stopped responding.

Even stranger.

I’ve been using Perforce for at least a dozen years and the server has never crashed or hung. That’s why you can let your support contract lapse for years without suffering any consequences.

A quick look into the processes list on the server showed several forks of... [More]

Rolling Back a File

Published by Marco on in Perforce

How to you revert in Perforce? If you want to roll back to a previous version, use the following instructions.

The following instructions apply to the Windows client (P4WIN) only.

  1. Select the file you wish to roll back (If you want to recover a deleted file, select Show deleted depot files from the View menu).
  2. Right-click and select Revision History.
  3. Select the file revision version you want to recover.
  4. Click the Sync button at the top of the dialog.
  5. Exit the revision history dialog.
  6. Open the file for edit; Perforce will ask which version you want to edit.
  7. Select Edit Current to avoid syncing to the head revision.
  8. Find the file in your changelist.
  9. Right-click and select Resolve => Schedule file for resolve.
  10. Right-click and select Resolve => Resolve interactively.
  11. Select Accept yours from the dialog and click OK.
  12. Submit the file to complete the rollback.

Labelling an Old Release

Published by Marco on in Perforce

With Perforce, it’s not the end of the world if you forget to label a release before checking in more changes. As long as you know the last changelist number that belonged to the release, you can always make the label anyway. In fact, you can follow the instructions for Creating a Label, but alter them in the following way:

  1. Once you have the final dialog open (After step 4), do not click Ok immediately.
  2. Instead, click the radio button at the top for Add/Replace only the following files.
  3. Click the Other radio button below, select Changelist from the drop-down and enter the number. Files will be added to the label with the revision they had at the time that changelist was submitted.
  4. Click Ok to commit changes.

Working Offline

Published by Marco on in Perforce

What happens when changes are made to files that need to applied to a Perforce depot? This usually happens for one of the following reasons:

  • You have been working offline—on a notebook without an internet connection.
  • You have a new version of third-party code that must be uploaded.

The following instructions apply to the Windows client (P4WIN) only; other clients and operation systems will have to use the longer instructions located at How do you work disconnected from the Perforce Server?

  1. Select the folder in the depot.
  2. From the menu, select File => More => Check Consistency.
  3. Perforce will (eventually) show a dialog with changed or deleted files.
  4. Select the changelist to which you’d like to add them and click Ok.
  5. Follow instructions for Adding New Files to add all new files to in that folder.
  6. Perforce now knows about all the changes that have been made “offline”.
  7. Submit the changes to update the depot.

Excluding Files

Published by Marco on in Perforce

Perforce maps files in the depot to a workspace using a view. The view is composed of single lines, each of which has a depot path and a workspace path (see Using Wildcards for some examples). You can also exclude files from the mapping by prepending a ‘-’ to the line.

Here are some handy excludes to use:


-//depot/…/Thumbs.db //marco-sten/…/Thumbs.db


-//depot/…/*.~* //marco-sten/…/*.~*
-//depot/…/*.dcu //marco-sten/…/*.dcu 
-//depot/…/*.ddp //marco-sten/…/*.ddp 
-//depot/…/*.bak //marco-sten/…/*.bak
-//depot/…/*.dsk //marco-sten/…/*.dsk
-//depot/…/*.dcr //marco-sten/…/*.dcr


This one is handy if you need to work with open-source libraries that have CVS junk littered all over the place. Replace CVS with SVN to prevent Perforce from seeing Subversion files.

-//depot/…/CVS/… //marco-sten/…/CVS/… 
-//depot/…*.cvs* //marco-sten/…*.cvs*

Syncing with a Label

Published by Marco on in Perforce

Sometimes you need to go back and fix a bug in older release. This means you need to somehow get to the source code you had when that version was released and download it. With Perforce, you don’t need to make zip files or other backups &mdash; you only need to have made a label or to know which changelist you’d like to sync with.

The following instructions apply to the Windows client (P4WIN) only.

The easiest way to get an old version back is to use a label:

  1. Select the label from the Labels pane
  2. Right-click to bring up the shortcut menu
  3. Select Sync specific files to bring up a sync dialog
  4. Click Select All
  5. Click Ok

If you don’t have a label or you only need to sync the files from a particular changelist, do the following:

  1. Find the changelist in the list of submitted changes (If the changelist is very old, it may not be in the list, see instructions below for showing more changelists).
  2. Right-click the changelist
  3. Select Sync to Changelist ####
  4. Choose Sync all… if you want to... [More]

Creating a Label

Published by Marco on in Perforce

Labels are separate objects in Perforce and contain a list of files at specific revisions. You can use a label to revert to previous release (See Syncing with a Label for more information).

The following instructions apply to the Windows client (P4WIN) only.

  1. Click the label toolbar button to show the labels page.
  2. Make a new label (right-click in the list); Give it a useful description.
  3. Restrict the View to that needed by the project being labelled (See Using Wildcards and Excluding Files for examples).
  4. Drag the project files from the depot over to the label; Select Add/Replace Files Listed in Label… from the popup menu. Perforce will open a dialog offering to replace the contents of the label.
  5. Click Ok to add the files.

Using Wildcards

Published by Marco on in Perforce

Perforce can interpret a rich wildcard syntax, but it can only be specified from the command line. An easy way to get to the correct directory is to do the following:

The following instructions apply to the Windows client (P4WIN) only.

  1. Right-click the desired starting folder
  2. Select Command Prompt from the shortcut menu

Now that you’re at a command prompt, you can use wildcards to open files for edit (or delete/revert, etc.). All of the standard symbols are interpreted as expected, with one additional operator “…”.

  • “.” is the current directory
  • “..” is one directory higher
  • “*” is zero or more characters
  • “?” is one character
  • “…” is all files in this directory and all files in all subdirectories

The path and directory names can be either those from the workspace (local) or those from the depot (server). In most cases, those are the same, but Perforce does not use implicit relative paths: you must preface all relative paths with “./” if you want Perforce to understand it... [More]