Perforce Public Knowledge Base - Enforcing Workspace Naming Conventions
Reset Search



Enforcing Workspace Naming Conventions

« Go Back



How can I provide a workspace name template? How do I enforce a naming convention on user workspaces that makes them easily identifiable?


You can use a "form-out" trigger to provide users with a standard workspace naming convention when they run "p4 client" or its GUI equivalent. The form-out trigger can verify that a user-provided workspace specification name complies with a particular naming convention, or modify the workspace name to comply with the naming convention.

The form-out script can be written to provide a template for the naming convention of your choice. In the following example script, the trigger script forces all client workspace names to begin with a Perforce user name and an underscore ("username_workspacename") :

#!/usr/bin/perl -w

$user     = $ARGV[0];
$formName = $ARGV[1];
$formFile = $ARGV[2];

$curr_client = $formName;
$client_name = $user . "_" . $curr_client;

# Let things continue if client already exists:
open (CLIENTS, "p4 clients |") or die "Couldn't get workspace list";
while (<CLIENTS>)
	if (/^Client \Q$formName\E .*/) {exit 0;}

# If the current client name already begins with username, bail:
if ($curr_client =~ m/^$user/) {exit 0;}

# Create modified client spec based on servers form:
$modifiedForm = "";

open (FORM, "<$formFile") 
	or die ("Trigger could not open form file for read");
while (<FORM>)
	if (/^Client:/) {$_ = "Client: $client_name";}
	if (/(^.*\/\/)$curr_client(.*)/) {$_ = "$1" . "$client_name" . 
	$modifiedForm .= $_;

# Write modified form file over servers version:
open (MODFORM, ">$formFile") 
	or die ("Trigger could not open form file for write");
print MODFORM "$modifiedForm";
exit 0;

Warning: The above script is an example only and should be tested thoroughly and modified as needed before being used in a production environment.

To use this script, you need to add a line to the triggers table (by running 'p4 triggers') to invoke the trigger. For example:

   clientNameCheck form-out client "/path_to/ %user% %formname% %formfile%"

Note: All lines in the triggers table must be preceded with a tab or space.

Enforcing Form Naming Conventions

The form-out trigger outputs a client workspace form that complies with a particular naming convention. However, it is possible that end users could modify the workspace name prior to saving the form. To prevent modification of form names, use a "form-in" trigger to ensure that the client workspace form that is being saved also satisfies the same naming convention as the form-out template.
For example, if the form-out trigger pre-pends a user name to a workspace name, then the form-in trigger should ensure that the user name is still pre-pended when the form is saved.
Related Links



Was this article helpful?



Please tell us how we can make this article more useful.

Characters Remaining: 255