gpt4 book ai didi

java - 使用 API 时如何创建单独的更改列表?

转载 作者:行者123 更新时间:2023-11-30 08:40:08 25 4
gpt4 key购买 nike

我正在尝试创建一个 Groovy 脚本,该脚本从我们的主干中获取更改列表的列表,并将它们一次一个地合并到一个发布分支中。我想在本地拥有所有更改列表,因为我想在提交上游之前运行测试构建。但是,每当我运行脚本时,我发现当我查看 P4V 时,所有合并都已放置在默认更改列表中。我怎样才能将它们分开?

我的代码(在 Groovy 中但使用 Java API)如下:

final changeListNumbers = [ 579807, 579916, 579936 ]
final targetBranch = "1.0.7"

changeListNumbers.each { changeListNumber ->
final existingCl = server.getChangelist( changeListNumber )
final cl = new Changelist(
IChangelist.UNKNOWN,
client.getName(),
server.userName,
ChangelistStatus.NEW,
new Date(),
"${existingCl.id} - ${existingCl.description}",
false,
server
);

cl.fileSpecs = mergeChangeListToBranch( client, cl, changeListNumber, targetBranch )
}

def List<IFileSpec> mergeChangeListToBranch( final IClient client, final IChangelist changeList, final srcChangeListNumber, final String branchVersion ){
final projBase = '//Clients/Initech'
final trunkBasePath = "$projBase/trunk"
final branchBasePath = "$projBase/release"

final revisionedTrunkPath = "$trunkBasePath/...@$srcChangeListNumber,$srcChangeListNumber"

final branchPath = "$branchBasePath/$branchVersion/..."
println "trunk path: $revisionedTrunkPath\nbranch path is: $branchPath"
mergeFromTo( client, changeList, revisionedTrunkPath, branchPath )
}

def List<IFileSpec> mergeFromTo( final IClient client, final IChangelist changeList,final String sourceFile, final String destFile ){
mergeFromTo(
client,
changeList,
new FileSpec( new FilePath( FilePath.PathType.DEPOT, sourceFile ) ),
new FileSpec( new FilePath( FilePath.PathType.DEPOT, destFile ) )
)
}

def List<IFileSpec> mergeFromTo( final IClient client, final IChangelist changeList, final FileSpec sourceFile, final FileSpec destFile ){
final resolveOptions = new ResolveFilesAutoOptions()
resolveOptions.safeMerge = true

client.resolveFilesAuto(
client.integrateFiles( sourceFile, destFile, null, null ),
// client.integrateFiles( changeList.id, false, null, null, sourceFile, destFile ),
resolveOptions
)
}

如果我尝试 IChangeList.update() 我会收到以下错误:

Caught: com.perforce.p4java.exception.RequestException: Error in change specification.
Error detected at line 7.
Invalid status 'new'.

如果不是使用 IChangelist.UNKNOWNexistingCl.id + 10000 (它大于当前正在使用的任何现有更改列表编号),那么我会得到

Caught: com.perforce.p4java.exception.RequestException: Tried to update new or default changelist

最佳答案

要在服务器中创建更改列表,请调用 IClient.createChangelist():

final existingCl = server.getChangelist( changeListNumber )
cl = new Changelist(
IChangelist.UNKNOWN,
... snip ...
);
cl = client.createChangelist(cl);
cl.fileSpecs = mergeChangeListToBranch( client, cl, ...

然后整合到这个特定的变化中:

IntegrateFilesOptions intOpts = new IntegrateFilesOptions()
intOpts.setChangelistId( cl.getId())

client.integrateFiles( sourceFile, destFile, null, intOpts)

integrateFiles() 返回集成文件,因此检查返回的 IFileSpec.getOpStatus() 是否为 FileSpecOpStatus.VALID .

关于java - 使用 API 时如何创建单独的更改列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35806407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com