info-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: tools for deleting the expanded $Log$ comments


From: Zieg, Mark
Subject: RE: tools for deleting the expanded $Log$ comments
Date: Wed, 06 Aug 2003 09:07:30 -0400

> I would like to know if there is a tools (in perl for example)
> that delete all the $Log$ expanded comments. Sometimes it is 
> useful because your classes have revisions for a given project,
> but if you decide to eliminate from all your code the inserted
> log comments for a given new revision, or because your are using
> your class on another project.

Yuck...but I've been there.  It's an ugly situation, but sometimes management 
comes up with pretty ugly mandates.

You may need to tweak this to work on your coding/comment conventions, but it 
worked on a bit of C code I ran it against:

#!/usr/bin/perl -w
################################################################################
#                                                                              #
#                               StripRcsLog.pl                                 #
#                                                                              #
################################################################################
#                                                                              #
#  Description:    Attempts to strip RCS/CVS-inserted "$Log$" comments from a  #
#                  text file.                                                  #
#                                                                              #
#  Author:         Mark Zieg <address@hidden>                                   
#
#                                                                              #
#  Usage:          StripRcsLog.pl < commented.c > stripped.c                   #
#                                                                              #
#  WARNING:        THIS IS DANGEROUS.  The algorithm is not foolproof.         #
#                  Manual verification of cleaned code is highly recommended!  #
#                  (Of course, you'd only be using this script if you kept     #
#                  all your code under revision-control...:-)                  #
#                                                                              #
################################################################################

MAIN:
{
    my $State = "BEFORE_LOG";
    my $Prefix;
    while( my $Line = <STDIN> )
    {
        if( $State eq "BEFORE_LOG" )
        {
            if( $Line =~ /^(.*)\$Log.*\$/ )
            {
                $State = "IN_LOG";
                $Prefix = $1;
                $Prefix =~ s/\*/\\*/g;  # If you understand the need for this,
            }                           # you get your Perl badge for the day!
            else
            {
                print $Line;
            }
        }
        elsif( $State eq "IN_LOG" )
        {
            if( $Line =~ /^$Prefix/ )
            {
                # looks like a follow-on log line;
                # do nothing, and thus delete line
            }
            else
            {
                # looks like the prefix has changed, so
                # assUme we've ended the log section
                print $Line;
                $State = "AFTER_LOG";
            }
        }
        elsif( $State eq "AFTER_LOG" )
        {
            print $Line;
        }
        else
        {
            die( "Invalid state: $State\n" );
        }
    }
    if( $State eq "BEFORE_LOG" )
    {
        warn( "No RCS-formatted logs were found!" );
    }
    elsif( $State eq "IN_LOG" )
    {
        warn( "The log parser consumed the entire file!  Probable script 
error!" );
    }
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]