SVN::客户端提交注释/消息选项



我正在尝试使用 perlSVN::Client模块自动执行一些 svn 任务。

不幸的是,我找不到提交带有提交消息的文件的选项。 目前我正在使用以下方法。

$client->commit($targets, $nonrecursive, $pool);

有谁知道如何使用 SVN::Client 在 svn 提交中添加评论/消息? perl 有什么替代选项可以做到这一点吗?

提前谢谢。

SVN::Client 的文档说你需要使用log_msg回调。

$client->commit($targets, $nonrecursive, $pool);

提交目标引用的文件或目录。将使用log_msg回调获取提交的日志消息。

这是文档对log_msg的评价。

$client->log_msg(\&log_msg)

设置客户端的log_msg回调 传递给的代码引用的上下文。它总是返回 当前代码引用集。

将调用此 coderef 指向的子例程以获取 将向存储库提交修订的任何操作的日志消息。

它接收 4 个参数。第一个参数是对 回调应在其中放置log_msg的标量值。如果你 希望取消提交,您可以将此标量设置为 undef。第二届 value 是可能保存该日志的任何临时文件的路径 消息,或者如果不存在这样的文件,则取消定义(尽管,如果log_msg是 undef, 此值未定义)。日志消息必须是 UTF8 字符串,其中 低频线分隔符。第三个参数是对数组的引用 svn_client_commit_item3_t对象,可以是完全的或仅 部分填充,具体取决于提交操作的类型。这 第 4 个也是最后一个参数将是池。

如果函数希望返回错误,则应返回 svn_error_t使用 SVN::Error::create 创建的对象。任何其他退货 值将被解释为SVN_NO_ERROR。

据此,可能最简单的方法是每次要提交时调用它,然后安装一条新消息。

$client->log_msg( sub { 
my ( $msg_ref, $path, $array_of_commit_obj, $pool ) = @_;
# set the message, beware the scalar reference
$$msg_ref = "Initial commitnnFollowed by a wall of text...";
return; # undef should be treated like SVN_NO_ERROR
});
$client->commit($targets, $nonrecursive, $pool);
# possibly call log_msg again to reset it. 

如果您希望这更容易,您可以安装一次相同的处理程序,但对消息使用(可能是全局或包)变量。

our $commit_message;
$client->log_msg( sub { 
my ( $msg_ref, $path, $array_of_commit_obj, $pool ) = @_;
# set the message, beware the scalar reference
$$msg_ref = $commit_message;
return; # undef should be treated like SVN_NO_ERROR
});
# ...
for my $targets ( @list_of_targets ) {
$commit_message = get_msg($targets); # or whatever
$client->commit($targets, $nonrecursive, $pool);
}

这样,您可以重用回调,但每次都更改消息。


请注意,我没有尝试过这个。我所做的只是阅读文档并进行一些疯狂的猜测。

最新更新