如何搜索简历评论历史

时间:2020-03-06 14:34:22  来源:igfitidea点击:

我知道此命令:
`cvs log -N -w <userid> -d" 1天前"

不幸的是,这会生成带有很多换行符的格式化报告,因此文件路径,文件版本和注释文本都位于单独的行中。因此,很难对其进行扫描以查找所有出现的注释文本(例如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.
=============================================================================

解决方案

这可能是过大的手段,但是我们可以使用git-cvsimport将CVS历史记录导入到Git存储库中,并使用Gi​​t的工具进行搜索。我们不仅可以在提交消息中搜索文本,还可以搜索已从存储库中的文件中添加或者删除的代码。

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

我最初的想法是使用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

-w选项似乎与-S选项更好地工作。否则,会有其他结果似乎与用户标识无关。也许有人可以解释。

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

这是我做的简单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

我们需要cvsps,它将从CVS历史记录生成补丁集。然后,我们应该在cvsps输出中仅包含一个注释实例,其下方整齐地列出了文件