我知道这个命令:cvs log -N -w<userid> -d"1 day ago"

不幸的是,这产生一种格式的报告有很多空行,这样,本文件的路径,该文件的版本,并评论文都是在单独行。因此,它是难以扫描出现的所有评论的文字,(例如,查询),以及相关的匹配的文件版本。

(注意,在记录输出将可以完全可接受的,如果只有简历可以执行的过滤本身。)

编辑:样品产出。方框中的案文一样,这是报告的每个储存库的文件:

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选项。否则,有其他结果似乎与userid无关。也许有人可以解释一下。

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输出中有一个你的评论实例,其中的文件整齐地列在它下面

我的第一个想法是使用egrep(或grep -E,我认为)来搜索多种模式,例如:

<Cmd> | egrep 'Filename:|Version:|Comment:'

然后我意识到你想要更智能地过滤。

为此,我会使用awk(或perl)逐行处理输出,当你找到感兴趣的部分时设置一个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;}'

这可能是方式矫枉过正,但是你能用 混帐cvsimport 进口的简历史个混库和搜索令的工具。你不仅可以搜索文本内提交信息,但也可以搜索的代码曾经加入 或删除 从文件的储存库。

CVSSearch 可能有所帮助,但这是一个CGI应用程序:'(

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top