2017-06-19 63 views
2

我试图自动化一些svn任务与perl SVN ::客户端模块。SVN ::客户端提交评论/消息选项

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

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

有谁知道如何添加评论/消息在svn提交与SVN ::客户端? 是否有任何替代选项与Perl来做到这一点?

在此先感谢。

回答

1

The documentation of SVN::Client说你需要使用log_msg回调。

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

Commit files or directories referenced by target. Will use the log_msg callback to obtain the log message for the commit.

以下是关于log_msg的文档说明。

$client->log_msg(\&log_msg)

Sets the log_msg callback for the client context to a code reference that you pass. It always returns the current codereference set.

The subroutine pointed to by this coderef will be called to get the log message for any operation that will commit a revision to the repo.

It receives 4 parameters. The first parameter is a reference to a scalar value in which the callback should place the log_msg. If you wish to cancel the commit you can set this scalar to undef. The 2nd value is a path to any temporary file which might be holding that log message, or undef if no such file exists (though, if log_msg is undef, this value is undefined). The log message MUST be a UTF8 string with LF line separators. The 3rd parameter is a reference to an array of svn_client_commit_item3_t objects, which may be fully or only partially filled-in, depending on the type of commit operation. The 4th and last parameter will be a pool.

If the function wishes to return an error it should return a svn_error_t object made with SVN::Error::create. Any other return value will be interpreted as 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); 
} 

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


请注意,我没有试过这个。我所做的一切都是阅读文档并做出一些野蛮的猜测。