如何防止提交空的 Perforce 变更列表时出错?

发布于 2024-10-18 04:53:31 字数 525 浏览 5 评论 0原文

尝试提交没有文件的变更列表会被 Perforce 视为错误(p4 Submit ... 返回退出代码 1)。这会导致我们的构建服务器上的定期集成构建失败(我们正在使用 Zutubi 的 Pulse 系统); 在这种情况下,我宁愿构建成功,可能会出现警告。

Pulse 具有退出代码重新映射功能,但 Perforce 似乎无法消除提交空变更列表失败和任何其他提交失败(例如验证触发器失败,我确实希望构建失败)之间的歧义。 。

我想到的立即显而易见的(但在我看来,不优雅的)解决方案是将 p4 Submit 的执行包装在一个批处理文件中,该文件首先通过计算以下行来检查目标更改列表是否为空来自p4打开的输出——或者只是解析p4submit的输出以获取“无文件”消息并从批处理文件成功返回。

有没有我没有看到的更好的技术来处理这个问题?

Attempting to submit a changelist with no files is considered by Perforce to be an error (p4 submit ... returns exit code 1). This causes a periodic integration build to fail on our build server (we're using Zutubi's Pulse system); in this case I would rather have the build succeed, possibly with a warning.

Pulse has exit code remapping functionality, but Perforce does not appear to disambiguate between a failure to submit an empty changelist and any other submit failure (such a validation trigger failure, which I do want to fail the build).

The immediately obvious (but, in my mind, inelegant) solution that comes to mind is to wrap execution of p4 submit in a batch file that first checks to see if the target changelist is empty by counting lines of output from p4 opened -- or just parsing the output of p4 submit for the "no files" message and returning successfully from the batch file.

Are there better techniques for handling this that I'm not seeing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不醒的梦 2024-10-25 04:53:32

我最终确实使用这样的方法解析了批处理文件中的输出:

for /f "delims=" %%I in ('p4 submit -d "<message>" 2^>^&1 1^>NUL') do    
set SUBMIT_OUTPUT=%%I
if "%SUBMIT_OUTPUT%"=="No files to submit from the default changelist." exit /b 0

这是必要的,因为 p4 的“无文件”消息实际上正常写入到 stderr。如果输出是我认为“安全”的消息,我会以零退出代码退出,否则脚本将以 p4 命令设置的任何错误级别继续。

请注意,如果您使用的是编号变更列表,则“无文件”消息会略有不同。

I did ultimately end up parsing the output in a batch file, using something like this:

for /f "delims=" %%I in ('p4 submit -d "<message>" 2^>^&1 1^>NUL') do    
set SUBMIT_OUTPUT=%%I
if "%SUBMIT_OUTPUT%"=="No files to submit from the default changelist." exit /b 0

This is necessary since p4's "no files" message is actually writting to stderr normally. If the output is the message I consider "safe" I exit with a zero exit code, otherwise the script will continue with whatever error level was set by the p4 command.

Note that the "no files" message for a numbered changelist is slightly different, if you're using that.

层林尽染 2024-10-25 04:53:31

在尝试提交更改列表之前,您可以先尝试将其删除。

p4 change -d ###

仅当更改列表为空时此操作才会成功,因此不要提交它(您刚刚删除了它)。如果失败,则更改列表中有文件,因此请继续提交它们。

但是,如果您使用作业,这对您不起作用,因为您无法删除附加了作业的变更列表,即使它是空的。

Before attempting to submit a changelist, you could first attempt to delete it.

p4 change -d ###

This operation will only succeed if the changelist is empty, so don't submit it (you have just deleted it). If it fails, there are files in the changelist, so go ahead and submit them.

However, if you use jobs, this won't work for you because you can't delete a changelist that has a job attached to it, even if it's empty.

守不住的情 2024-10-25 04:53:31

如果我正确理解你的问题的话,仅使用 Perforce 可能没有好的技术。正如您所看到的,问题在于 perforce 命令行运行的返回代码是不明确的。提交空变更列表真的是一个错误吗?也许,也许不是——可能取决于你问的是谁。

确实不建议查看“p4”命令的返回代码。正如您所建议的,最好的选择是解析命令的输出,然后从那里执行您需要的操作。

大多数命令现在支持 -ztag 选项(请参阅“p4 帮助用法”),这将使解析输出变得更容易,具体取决于您想要执行的操作。如果您的情况如此,只需查找输出中的文本,然后决定从那里做什么就足够了。

There are probably no good techniques just with Perforce, if I am understanding your problem correctly. The issue, as you have seen, is that the return codes from perforce command line runs are, well, ambiguous. Is a submission of an empty changelist really an error? Maybe, maybe not - might depend on who you ask.

It's is not really that advisable to look at return codes from 'p4' commands. Your best bet as you have suggested is to parse the output of the command and then do what you need to from there.

Most commands now support the -ztag option (see 'p4 help usage'), which will could make parsing the output a bit easier, depending on what you want to do. If your case, it is probably sufficient enough to just look for the text in the output and then decide what to do from there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文