P4Ruby Library: Scripts/Modules for use with P4Ruby

Introduction

I've started to put together some commonly used/requested scripts both to provide examples of good scripting using P4Ruby and also to solve some common problems in what I hope is an efficient way.

I hope that over time, this will grow into a fairly broad range of resources for Perforce users.

All of these scripts require you to install Ruby and P4Ruby

Library Contents

  1. Triggers
  2. Library Modules
  3. General Purpose Scripts

Support

If you have any problems or questions with these scripts you can contact me at tony@perforce.com or tony@smee.org. These scripts are not supported by Perforce Software, but by me personally. I'll answer questions as quickly as I can.

Triggers

These are some example trigger scripts. The documentation for all of these scripts is
available here.

Common files

Script Description
P4Triggers.rb A generalised framework for implementing Perforce triggers used by all of the other scripts. If you're going to use these scripts at all, you'll need this file to be installed in the same directory as the scripts themselves.

Pre-Submit Triggers

Script Description
checkjob.rb Ensures that all changelists are associated with a job before they can be submitted. This is the simplest example of using my trigger framework.
checktype.rb Ensures that new files being added/branched have the correct Perforce filetypes. Whilst "p4 typemap" goes a long way towards ensuring filetype consistency, it's easily overridden. Since a user cannot override a trigger, sysadmins who want more enforcement may want to use this trigger.
checkcase.rb Script to ensure that new files being added/branched respect the case of existing directories in the path. For example, if //depot/test/fileA already exists, then this script will reject an attempt to add //depot/TEST/fileB or //Depot/test/fileB for that matter.

This is very useful if you have Windows clients or if your Perforce server runs on Windows. In an all Unix environment it's not so much of a problem.

Post-Submit (Commit) Triggers (2004.2 and later)

Script Description
autointeg.rb A script for keeping a slave branch in sync with its master. Whenever a change is submitted to the master branch, it's automatically propagated to the slave via this commit trigger. The files that are integrated can be limited both by the trigger spec, and by the branch spec used.

Spec Triggers (2004.2 and later)

Script Type Description
defaultclient.rb out A small script to ensure that the default client view for all new clients that are created are based on the view of an existing template client. This allows system administrators to define a default client mapping only a small section of the depot, and by default that's all new users will see when they create their clients.

Library Modules

Useful library modules you may want to use in your apps

Module Description
p4table.rb

A module that allows you to use a Perforce repository as a database. Using Perforce as a database is surprisingly powerful. You get a fast database engine capable of storing anything and with automatic indexing of record fields.

p4table.rb stores the fields for every record as a job and then versions the job in the depot. It also allows you to attach files to records and versions them too. Using Perforce jobs ensures that all records are indexed and searchable.

See the Documentation for more information.

General Purpose Scripts

These are some useful non-trigger scripts

Script Description
integrename.rb A script to integrate changes using a branch view and attempt to follow renames in both the source and target branches. Early alpha state at the moment.
oldclients.rb A script to find the oldest <n> clients - useful to locate candidates for deletion.
reversechange.rb A script to back out a specified change. Handles many cases, but may be defeated by older changes. See the notes in the script for more information.