2008-09-23 97 views
8

我知道这个命令: cvs log -N -w<userid> -d"1 day ago"如何搜索CVS评论历史

不幸的是这会产生一个格式化的报告有很多新行的话,这样的文件路径,文件版本和注释文字都是分开的。因此,很难对所有出现的评论文本进行扫描(例如,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. 
============================================================================= 

回答

9

-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

+1

史蒂夫太棒了。我不知道-B grep选项:“打印NUM行前导上下文”。因此,使用cvs日志为每个文件生成的15行报告(注释是第15行),-B14会为每个匹配文件提供整个块。 – 2008-12-23 14:29:58

0

这可能是矫枉过正的方法,但你可以使用git-cvsimport导入CVS历史的Git仓库,并使用Gi​​t的工具搜索。您不仅可以搜索提交消息中的文本,还可以搜索已添加的代码或从存储库中的文件中删除

+2

这将做什么? – dokaspar 2012-07-27 14:32:11

0

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

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 
+0

后处理解决方案的棘手部分是感兴趣的内容位于文本块的后面部分。因此,有必要缓冲每个块,然后丢弃或输出它。我相信awk可以做到这一点,但它可能会涉及为期多天的项目。 – 2008-09-24 12:42:16

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 
4

你想cvsps - 这将产生从CVS历史补丁集。然后,你应该只在cvsps输出中有一个你的评论实例,其文件整齐地列在它下面

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;}'