【问题标题】:How to sync to a label with p4java如何使用 p4java 同步到标签
【发布时间】:2016-03-08 18:54:59
【问题描述】:

我在网上看到过使用 Perforce 的 p4java api 将客户端工作区与最新文件同步的示例。例如:

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

但是如何指定它以同步到特定标签?例如,在命令行中相当于:

p4 sync @labelname

是否可能通过使用 SyncOptions 的替代方法?

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

我查看了 SyncOptions,但没有看到任何在其中指定标签的方法。

【问题讨论】:

  • 一般来说,标签只是一种FileSpec。

标签: perforce p4java


【解决方案1】:

FileSpec 是 IFileSpec 的一个实现,它有一个 label 字段:

protected  String   label

还有以下方法:

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

取自以下链接:

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

【讨论】:

  • 嗯,好的,提到 FileSpec 让我朝着正确的方向前进。原来我可以通过调用 FileSpecBuilder.makeFileSpecList("//path/to/project/...@labelname") 来指定一个标签,然后我可以将它作为第一个参数输入到 sync(filespeclist, . ..) 方法。
【解决方案2】:

根据上面的建议查看 fileSpecs 参数,我发现这种方法对我有用:

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

【讨论】:

    猜你喜欢
    • 2013-04-12
    • 1970-01-01
    • 2017-11-29
    • 1970-01-01
    • 1970-01-01
    • 2015-07-16
    • 2018-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多