3

I recently imported a VSS repository into Perforce. This included hundreds of labels, which the developer that was using VSS (now using Perforce) relies upon. I accidentally deleted them and had to do the import again. To prevent such accidental deletion in the future, I want to lock all the labels, but doing it through P4V would take forever. I would like to write a script to do it for me.

I can get all the labels into a text file with the p4 labels command, and with some text editor macro processing I could build up a script to lock them all. I just need to know the command(s) to do this.

raven
  • 18,004
  • 16
  • 81
  • 112

2 Answers2

3

This can be done by automating the process of editing the label spec. The process is as follows:

  • Send the label spec to standard output with the -o switch.
  • Pipe that output to a utility that can manipulate it and set the label's "Options" to "locked". In this case, the Unix utility sed gets the job done. (I'm on Windows, so I used this port. Others can be found in this answer.)
  • Pipe this updated spec back into the label command with the -i switch.

Put it all together and you get a command that looks like this.

p4 label -o <label name> | sed 's/^Options:.*/Options: locked/' | p4 label -i

Community
  • 1
  • 1
raven
  • 18,004
  • 16
  • 81
  • 112
2

The relevant Perforce doc is here.

To dump a label spec to standard output:

p4 -o *labelname*

To read a label spec from standard input:

p4 -i *labelname*

in between you'll need to process the text to include the 'options: locked' probably by redirecting standard output to a text file e.g. ('p4 -o labelname > labelspect.txt'), process the text file in your chosen manner, and then read the file into standard in ('p4 -i labelname < labelspect.txt')

Josh Heitzman
  • 1,816
  • 1
  • 14
  • 26