[Top][All Lists]

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

Re: log message verification

From: Dale Miller
Subject: Re: log message verification
Date: Tue, 05 Dec 2000 17:56:20 -0600

address@hidden wrote:

> Hi all,
> I am having a problem.I want to check that a log msg is entered
> before commit.For this I want to check that the log msg is not null.
> I have the following line in verifymsg
> src /usr/cvssupport/verify.log
> and in verify.log I have the following script
> _________________________________________________
> msg = `head -1`
> if [ "$msg" = '' ];
>  then
> echo "No log message was entered;enter a log message and try again"
> exit 1
> else
> echo "Commit Success"
> exit 0
> fi
> __________________________________________________
> But this is aborting the commit even when a msg is entered.Am I doing
> this correctly?will the firstline in the code above get the log msg
> into the variable msg?Else how do I get the log message into that
> variable?? Pls help.
> Thanks a lot,
> Paddy Thomas


Try adding
echo $msg | cat -tev
after your msg = `head -1` line to see what it actually contains.
The cat options will show you the end of line or any control
characters that might be present.

I use a perl program I enforce that a person starts the commit
message with a valid System Change Request (SCR) number.
I have a crontab that maintains a file of active SCRs and I
use it to verify the comment entry.

The perl program gets the comment from STDIN.
You cannot alter the comment that the commit will use but
you can verify the contents.

My program displays the SCR number and title to the screen
and then does a normal exit on a match.

I was asking the person to confirm that the SCR number was
valid, however, when I moved to using pserver I had to comment
out the call to the subroutine because you cannot get interaction
with pserver from STDIN.  I tried many things to see if I
could get interaction, but I finally forced it to quite looping
after 4 failures, and later just commented out the call.

You might get some ideas from it.

---------------- cut here ----------------------------
#!/usr/local/bin/perl -ws
#  verifymsg_SCR   Dale Miller   16-AUG-1999
#  $Id: verifymsg_SCR,v 1.2 2000/09/06 22:04:00 miller Exp $
#  This program is called by $CVSROOT/CVSROOT/verifymsg
#  and is used to verify that the log message starts with a
#  SCR number with the three letters SCR before the 8 digits.
#  If the SCRyyyydddd is not supplied the commit fails.

$scrfile = "/sdhs_code/SDHSU/cm/tools/open_SCRs.txt" unless defined

$reply = "xx";  #initialize
$counter = 0;   #initialize

chop($scr = <>);

if (-r "$scrfile") {
    if ($scr !~ /(^SCR\d{8})(\s+|$)/) {
        print "$scr\n";
        print "*******************************************    ERROR\n";
        print "*******************************************\n";
        print "Must start your comment with \"SCRyyyydddd \"\n";
        print "       The commit has been aborted!\n";
        print "*******************************************\n";
        print "*******************************************    ERROR\n";
        exit 1;
    } else {
        $scr = $scr;
        $scr =~ s/^SCR(\d{8}).*$/$1/;
        $match = `grep $scr $scrfile`;
        chomp $match;
        if ($match eq "") {
            print "*******************************************
            print "*******************************************\n";
            print "SCR$scr is not active or not a valid number\n";
            print "*******************************************\n";
            print "*******************************************
            exit 1;
        } else {
            $status = ""; #not used (-w)
            ($status, $number, $title) = split(/\s+/, $match, 3);
            print "SCR$number: $title\n";
            exit 0;
} else {
    print "$scrfile is not readable or does not exist.\n";
    print "Please notify CM staff\n";
    exit 1;

sub ask_if_correct {
    print "Is this the correct SCR? (y|n): ";

    chop($reply = <STDIN>);
    until ($reply =~ /^[yn]/i) {
        print "Please enter \"y\" or \"n\": ";
        chop($reply = <STDIN>);
        if ($counter > 4) {
            $reply = "n";

    if ($reply =~ /^n/i) {
        print "Please try again using the proper SCR number\n";
        print "********************************************\n";
        exit 1;

reply via email to

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