2017-06-19 60 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); 
} 

這樣您就可以重複使用回調,但每次都會更改消息。


請注意,我沒有試過這個。我所做的一切都是閱讀文檔並做出一些野蠻的猜測。