我正在尝试使用perl SVN :: Client 模块自动执行某些svn任务。
不幸的是我找不到提交带有提交消息的文件的选项。 我当前正在使用以下方法。
$client->commit($targets, $nonrecursive, $pool);
有谁知道如何在SVN :: Client的svn提交中添加评论/消息? 是否有perl的替代选项可以做到这一点?
提前致谢。
答案 0 :(得分:1)
The documentation of SVN::Client表示您需要使用log_msg
回调。
$ client-> commit($ targets,$ nonrecursive,$ pool);
提交目标引用的文件或目录。将使用log_msg回调来获取提交的日志消息。
以下是该文档对log_msg
所说的内容。
$客户端 - > log_msg(\&安培; log_msg)
设置客户端的log_msg回调 您传递的代码引用的上下文。它总是返回 当前代码参考集。
将调用此coderef指向的子例程来获取 对将提交修订版本的任何操作的日志消息。
它接收4个参数。第一个参数是对a的引用 标量值,其中回调应放置log_msg。如果你 希望取消提交,您可以将此标量设置为undef。第二个 value是可能持有该日志的任何临时文件的路径 消息,如果没有这样的文件,则为undef(但是,如果log_msg为undef, 这个值是未定义的)。日志消息必须是带有的UTF8字符串 LF线分离器。第3个参数是对数组的引用 svn_client_commit_item3_t对象,可以是完全的,也可以是唯一的 部分填写,具体取决于提交操作的类型。该 第4个和最后一个参数将是一个池。
如果函数希望返回错误,则应返回a 使用SVN :: Error :: create制作的svn_error_t对象。任何其他回报 值将被解释为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 commit\n\nFollowed 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);
}
这样您就可以重复使用回调,但每次都要更改消息。
请注意,我没试过这个。我所做的就是阅读文档并做出一些猜测。