How to sync to a label with p4java

484 Views Asked by At

I've seen examples online of using Perforce's p4java api to sync a client workspace with the latest files. Eg:

public List<IFileSpec> sync(List<IFileSpec> fileSpecs,
                        boolean forceUpdate,
                        boolean noUpdate,
                        boolean clientBypass,
                        boolean serverBypass)

But how do I specify it to sync to a specific label? Eg, the equivalent of this at the command-line:

p4 sync @labelname

Is it perhaps via the alternate method that uses SyncOptions?

public List<IFileSpec> sync(List<IFileSpec> fileSpecs,
                        SyncOptions syncOpts)

I had a look at SyncOptions, but didn't see any way to specify a label in there.

2

There are 2 best solutions below

0
On BEST ANSWER

After advice above to look into the fileSpecs parameter, I discovered that this method worked for me:

List<IFileSpec> fileSpecsSet = 
    FileSpecBuilder.makeFileSpecList("//path/to/project/...@labelname");
client.sync(fileSpecsSet, true, false, false, false);
1
On

FileSpec which is an implementation of IFileSpec has a label field :

protected  String   label

and the following method :

 void   setLabel(String label)
      Set the label associated with this file spec.

taken from the following link :

https://www.perforce.com/perforce/r15.1/manuals/p4java-javadoc/com/perforce/p4java/impl/generic/core/file/FileSpec.html