كيفية البحث في تاريخ التعليقات على السيرة الذاتية

StackOverflow https://stackoverflow.com/questions/118342

  •  02-07-2019
  •  | 
  •  

سؤال

أنا على علم بهذا الأمر: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 خيار.بخلاف ذلك، هناك نتائج إضافية لا تبدو ذات صلة بمعرف المستخدم.ربما شخص ما يمكن أن يفسر ذلك.

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

أقوم بإعادة توجيه الإخراج إلى ملف نظرًا لأن سجل السيرة الذاتية صاخب ولست متأكدًا من كيفية جعله هادئًا.أفترض أن البديل هو إعادة توجيه stderr إلى /dev/null.

نصائح أخرى

انت تريد cvsps - والتي سوف تولد مجموعات التصحيح من تاريخ CVS.بعد ذلك، يجب أن يكون لديك مثيل واحد فقط لتعليقك في مخرجات cvsps، مع إدراج الملفات بدقة أسفله

كانت أفكاري الأولى هي استخدام egrep (أو grep -E، على ما أعتقد) للبحث عن أنماط متعددة مثل:

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

ولكن بعد ذلك أدركت أنك تريد التصفية بشكل أكثر ذكاءً.

ولتحقيق هذه الغاية، سأستخدم awk (أو Perl) لمعالجة المخرجات سطرًا تلو الآخر، مع تعيين متغير الصدى عندما تجد قسمًا محل اهتمام؛الكود الزائف هنا:

# 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.لا يمكنك البحث عن نص ضمن رسائل الالتزام فحسب، بل يمكنك أيضًا البحث عن التعليمات البرمجية التي تمت إضافتها من قبل أو إزالتها من الملفات الموجودة في المستودع الخاص بك.

بحث CVSS قد يساعد، لكنه تطبيق CGI :'(

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top