Perforce Public Knowledge Base - Saving the Contents of a Label
Reset Search



Saving the Contents of a Label

« Go Back



How do I preserve the contents of a label? Can I store revisions of a label in Perforce?


While the view of a label can be versioned using a Spec Depot (see Using the Spec Depot) the contents of the label are not versioned.

Because each label has its name, view and file list contained within it, simply save each in a file with a unique name.  The label's name is a good choice for a unique name.  These files can be checked into Perforce in a branch that you create for this purpose.  Because the labels use their names as the filenames, the changes between versions of the labels can be tracked.  The commands below demonstrate how to accomplish these tasks.

Label specifications can be sent to the standard output device with the following command:

p4 label -o

A list of files contained in the label can be found with the following command:

p4 files @labelname

You can easily get a list of labels with a command like the following:

p4 labels | awk '{print $2}'

This type of command can be used to combine the above examples and create a series of files which contain the labels. The following is a bash shell script that does so:

for each in `p4 labels | awk '{print $2}'`
echo $each
p4 label -o $each > $each.label
p4 files @$each > $each.labellist

The resulting .label and .labellist files can then be checked into Perforce. The "labellist" file can be further refined to contain just the file names by adding a command similar to the following into the script above:

p4 files @<label> | awk {'print $1'} > $each.labellist

The above script is a quick example and it does not take into account file names/paths with embedded spaces. A more robust script should include contingencies for such file names.

Note that the client specification used to perform this operation needs to have ALL files visible. Otherwise, files that the client cannot see are not listed by the p4 files command.

You can restore the files from the archived files using the following sequence of commands (given a .label and .labellist file).

cat <label>.label > p4 label -i
for each in `cat bl.labellist`; 
p4 tag -l blackfire-label $each; 

While these commands and scripts are written in a UNIX context, they can easily be adapted for Windows use. All the tools used on this page have Windows equivelants.

Related Links



Was this article helpful?



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

Characters Remaining: 255