Mike's Perforce Scripts

In order to make Perforce fit better with my preferred workflow I've developed various scripts. Initially they were just shell scripts (running under Cygwin but those have a number of failings so eventually I'm working my way round to rewriting them in Ruby using P4API.


This script is used to generate diffs suitable for applying with patch. It can generate a diff containing all pending changes, only those in a specific (including the default) changelist or for a specific set of files using standard Perforce syntax.

Unlike just running P4DIFF=diff p4 diff -du this script also deals with integrations, added and deleted files in the same way as passing -N to diff.

I use this script before submitting changes to see if anything unnecessary (such as gratuitous whitespace changes) has snuck in and to aid me in writing a good log message. I also use it when I need to archive work in progress and perhaps undo it temporarily with patch -R.

The script does not currently support generating patches for submitted changelists.

Download mkp4patch.rb. Ruby version (requires Ruby P4API.)

Download mkp4patch.sh. Original shell version - does not have all the features described above.


This shell script can be used to generate a zip file from pending changes. If used on a specific changelist the current log message is written to the archive too as a file named DESCRIPTION.txt. It's useful for sending changed files for review to people who can't read a unified diff.

Download mkp4zip


This Ruby script shows all the files or directories it finds that aren't known to Perforce. It processes .p4ignore files to identify files or patterns for files that aren't expected to be in Perforce and should be ignored. The .p4ignore file behaves similarly to .cvsignore.

Download show-non-p4.rb

Mike Crowe
Last modified: Mon Jan 21 15:41:45 GMT 2008