2017-06-19 2 views
2

私はいくつかのsvnタスクをperlで自動化しようとしていますSVN :: Clientモジュール。コメント/メッセージオプション付きのSVN :: Clientコミット

残念ながら、私はコミットメッセージでファイルをコミットするオプションを見つけることができませんでした。 現状私は以下の方法を使用しています。

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

誰でも私はSVN :: Clientでsvn commitでコメント/メッセージを追加する方法を知っていますか? これを行うには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); 
} 

この方法では、コールバックを再利用しますが、毎回メッセージを変更します。


私はこれを試していないことに注意してください。私がやったことは、ドキュメンテーションを読み、いくつかの野生の推測をすることです。

関連する問題