質問
私はこのコマンドを知っています:cvs log -N -w<userid> -d"1 day ago"
残念ながら、これにより、ファイル パス、ファイル バージョン、およびコメント テキストがすべて別の行に表示されるような、多数の改行を含む書式設定されたレポートが生成されます。したがって、コメント テキスト (例: grep) のすべての出現をスキャンし、一致をファイル/バージョンに関連付けることは困難です。
(CVS のみがネイティブにフィルタリングを実行できる場合、ログ出力は完全に許容できることに注意してください。)
編集:サンプル出力。次のようなテキストのブロックがリポジトリ ファイルごとにレポートされます。
RCS file: /data/cvs/dps/build.xml,v Working file: build.xml head: 1.49 branch: locks: strict access list: keyword substitution: kv total revisions: 57; selected revisions: 1 description: ---------------------------- revision 1.48 date: 2008/07/09 17:17:32; author: noec; state: Exp; lines: +2 -2 Fixed src.jar references ---------------------------- revision 1.47 date: 2008/07/03 13:13:14; author: noec; state: Exp; lines: +1 -1 Fixed common-src.jar reference. =============================================================================
解決
の -w
オプションは、 -S
オプション。それ以外の場合は、ユーザー ID に関連していないと思われる追加の結果が存在します。おそらく誰かがそれを説明できるでしょう。
cvs log -N -S -w<userid> -d"1 day ago"
これにより、 grep にパイプすることでそれなりの成功を収めています。
cvs log -N -S -w<userid> -d"1 day ago" | grep -B14 "some text" > afile
CVS ログのノイズが多く、静かにする方法がわからないため、出力をファイルにリダイレクトしています。代替案は、stderrをにリダイレクトすることだと思います /dev/null
.
他のヒント
あなたが欲しいのは cvsps - CVS 履歴からパッチセットを生成します。そうすれば、cvsps 出力にはコメントのインスタンスが 1 つだけ表示され、その下にファイルがきちんとリストされます。
私が最初に考えたのは、egrep (または grep -E だったと思います) を使用して、次のような複数のパターンを検索することでした。
<Cmd> | egrep 'Filename:|Version:|Comment:'
しかしその後、あなたはもっとインテリジェントにフィルタリングしたいと考えていることに気づきました。
そのために、awk (または perl) を使用して出力を 1 行ずつ処理し、目的のセクションが見つかったら echo 変数を設定します。ここの疑似コード:
# Assume the sections are of the format:
# Filename: <filename>
# Version: <version>
# Comment: <comment>
# <more comment>
Set echo to false
While more lines left
Get line
If line starts with "Filename: " and <filename> is of interest
Set echo to true
If line starts with "Filename: " and <filename> is not of interest
Set echo to false
If echo is true
Output line
End while
私がやったことは次のとおりです - 単純な Java スクリプトです。
import java.io.IOException;
public class ParseCVSLog
{
public static final String CVS_LOG_FILE_SEPARATOR = "=============================================================================";
public static final String CVS_LOG_REVISION_SEPARATOR = "----------------------------";
public static final String CVS_LOG_HEADER_FILE_NAME = "Working file";
public static final String CVS_LOG_VERSION_PREFIX = "revision";
public static void main(String[] args) throws IOException
{
String searchString = args[0];
System.out.println( "SEARCHING FOR: " + searchString );
StringBuffer cvsLogOutputBuffer = new StringBuffer();
byte[] bytes = new byte[1024];
int numBytesRead = 0;
while( (numBytesRead = System.in.read( bytes )) > 0 )
{
String bytesString = new String(bytes, 0, numBytesRead);
cvsLogOutputBuffer.append( bytesString );
}
String cvsLogOutput = cvsLogOutputBuffer.toString();
String newLine = System.getProperty("line.separator");
String[] fileArray = cvsLogOutput.split( CVS_LOG_FILE_SEPARATOR );
for ( String fileRecord : fileArray )
{
if ( !fileRecord.contains( searchString ) )
{
continue;
}
String[] revisionArray = fileRecord.split( CVS_LOG_REVISION_SEPARATOR );
String[] fileHeaderLineArray = revisionArray[ 0 ].split( newLine );
String fileName = "";
for ( String fileHeadeLine : fileHeaderLineArray )
{
if ( fileHeadeLine.contains( CVS_LOG_HEADER_FILE_NAME ) )
{
fileName = fileHeadeLine.split( ": " )[ 1 ];
break;
}
}
System.out.print( fileName );
for ( int i = 1; i < revisionArray.length; i++ )
{
String versionRecord = revisionArray[ i ];
if ( !versionRecord.contains( searchString ) )
{
continue;
}
String[] versionLineArray = versionRecord.split( newLine );
for ( String versionLine : versionLineArray )
{
if ( versionLine.contains( CVS_LOG_VERSION_PREFIX ) )
{
System.out.print( " " + versionLine.split( " " )[ 1 ] );
}
}
}
System.out.println();
}
}
}
そして、私がそれを使用した方法は次のとおりです。
cvs log -N -S -washamsut | java ParseCVSLog GS-242
このコマンドと gawk スクリプトは、各ログ エントリのファイル名、日付、コメント行のみを見つけるのに役立ちます。
cvs log -N -S -b -w<userid> -d ">1 day ago" 2>/dev/null | gawk 'BEGIN{out=0;} /^Working file:/ { print $0; } /^date:/ { out=1; } /^===/ { print ""; out=0; } (out==1){print $0;}'
これはやりすぎかもしれませんが、次のようにすることもできます git-cvsimport CVS 履歴を Git リポジトリにインポートし、Git のツールを使用して検索します。コミットメッセージ内のテキストを検索できるだけでなく、これまでに追加されたコードも検索できます または削除されました リポジトリ内のファイルから。
CVSサーチ 役立つかもしれませんが、これは CGI アプリケーションです:'(