8

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

不幸的是,这会生成一个带有许多换行符的格式化报告,这样文件路径、文件版本和注释文本都在不同的行上。因此很难扫描它以查找所有出现的注释文本(例如,grep),并将匹配项与文件/版本相关联。

(请注意,如果只有 cvs 可以本地执行过滤,日志输出将是完全可以接受的。)

编辑:示例输出。每个存储库文件都会报告这样的文本块:

RCS 文件:/data/cvs/dps/build.xml,v
工作文件:build.xml
头:1.49
分支:
锁:严格
访问列表:
关键字替换:kv
总修订:57;选定的修订:1
描述:
----------------------------
修订版 1.48
日期:2008/07/09 17:17:32;作者:noec;状态:经验​​;线路:+2 -2
修复了 src.jar 引用
----------------------------
修订版 1.47
日期:2008/07/03 13:13:14;作者:noec;状态:经验​​;线路:+1 -1
修复了 common-src.jar 引用。
==================================================== ============================
4

7 回答 7

9

这些-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.

于 2008-12-19T19:32:38.393 回答
4

您需要cvsps - 它将根据 CVS 历史生成补丁集。然后,您应该在 cvsps 输出中只有一个注释实例,文件整齐地列在其下方

于 2009-11-17T22:55:55.723 回答
2

我的第一个想法是使用 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
于 2008-09-23T00:25:10.267 回答
1

这是我所做的 - 一个简单的 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
于 2009-02-11T21:22:42.117 回答
1

这个命令和 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;}'
于 2015-12-17T16:05:51.293 回答
0

这可能有点矫枉过正,但您可以使用git-cvsimport将 CVS 历史导入 Git 存储库并使用 Git 的工具进行搜索。您不仅可以搜索提交消息中的文本,还可以搜索曾经在存储库中的文件中添加或删除的代码。

于 2008-09-23T00:17:51.377 回答
0

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

于 2008-09-23T00:19:15.447 回答