Link to home
Start Free TrialLog in
Avatar of jwcorbett
jwcorbett

asked on

Parse revisions from log file

I need to verify file revisions in a log file that I'm writing out with a perl script.
The log file, has the following lines in it, among other things:

<===cut from log===>
File: Helpus/All/build.xml
before Release20060411_01:
   Sticky Tag:            Q20060330 (revision: 1.1)

after Release20060411_01
   Sticky Tag:            Release20060404_01 (revision: 1.2)
<===cut from log===>

I'd like to add a revision audit function to my current perl script.
I need to look for
1)revisions going backwards ("before" "revision: 1.1" and "after" "revision:1.0")...
...as well as
2)revision hopping (before 1.1, after 1.3).

I need to audit each file in the log file.
Each file has an entry similar to the build.xml <=cut=> from above.
If the file is indicated in the log as violating #1 or #2, I like to write the file name listed in the log after "File:" to an alert text file.

Thanks for any help!
I haven't had time to hack anything together and I like learn from the experts anyway.


Avatar of ozo
ozo
Flag of United States of America image

I'm not quite sure what it is you want to do.
Given the above cut from log as input, what would you want the output of the sctipt to be?
Avatar of jwcorbett
jwcorbett

ASKER

The output would depend on the revisions listed for the given filename.
So, in the cut, the filename (and path) is Helpus/All/build.xml
I would want "Helpus/All/build.xml" listed in a new text file if the revisions for it either go backward, or hop (skip) a revision.
So, given the above cut from log, you would not have any output?
Would (before 1.9, after 2.0) be a skip?
Correct, the cut from above would not have output...
No, before 1.9, after 2.0 would not be a skip, it would be valid.

So the two examples where I'd need an alert text file written to would be:
Skip (revision 1.2 is skipped):
<===cut from log===>
File: Helpus/All/build.xml
before Release20060411_01:
   Sticky Tag:          Q20060330 (revision: 1.1)

after Release20060411_01
   Sticky Tag:          Release20060404_01 (revision: 1.3)
<===cut from log===>

and backwards:
<===cut from log===>
File: Helpus/All/build.xml
before Release20060411_01:
   Sticky Tag:          Q20060330 (revision: 1.3)

after Release20060411_01
   Sticky Tag:          Release20060404_01 (revision: 1.2)
<===cut from log===>

Hope this helps and thanks for yours!
I'm still not quite sure how skip is defined.
would 1.85 to 2.01 be a skip?
would 1.9 to 1.10 be a skip?  Would it be backwards?
how about 1.2.1 to 1.3.1?
Basically, I think it comes down to evaluating the digits between the dots.

would 1.85 to 2.01 be a skip?
Yes, this is a skip.  
This scenario (1.X to 2.X), is somwhat hard to handle...for this one the "OK" scenario would be 1.85 to 1.86.

would 1.9 to 1.10 be a skip?  Would it be backwards?
This would be OK, not a skip or backwards.

how about 1.2.1 to 1.3.1
Yes, this would be a skip, 1.2.1 going to 1.2.2 would be OK.





So what is allowed to preceed 2.0?
1.9 is ok, 1.85 is not, what about 1.99 or 1.9.9?
For the purposes of this script, going to 2.0 from any 1.X would be a skip (1.9 to 2.0 is not OK, 1.9 to 1.10 would be OK).

In practice, if we go to 2.0 from 1.X, it's a new release and would be handled accordingly (baseline would start at 2.X).



#maybe you want something like this.  I'm not sure about the skip condition
#!/usr/bin/perl
$/="File: ";
while( <> ){
    next unless /^before.*revision:\s*([\d.]+).*after.*revision:\s*([\d.]+)/ms;
    $before=eval"v$1";    $after=eval"v$2";
    print /(\S.*)/," backwards \n" if $after lt $before;
    print /(\S.*)/," skip\n" if ord(substr$before,-1)+1 < ord(substr$after,-1)\
;
}
Initial test show that this will get me going...let me get it implemented into the script before I close out the question.

Thanks Ozo! Once again, it's Ozo nice to have you around!
Or maybe this is better
#!/usr/bin/perl
$/="File: ";
while( <> ){
    next unless /^before\s.*?revision:\s*([\d.]+).*?^after\s.*?revision:\s*([\d.]+)/ms;
    $after=eval"v$2";
    $next=eval"v$1";
    substr($next,-1)=chr(ord(substr$next,-1)+1);
    print /(\S.*)/," backwards\n" if $after lt $next;
    print /(\S.*)/," skip\n" if $next lt $after;
}
Not really better...it lists files whose revision did not change as going backwards...
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That's better...what do you see as the primary differences between your 1st script and the last one?
Ozo,

How can I get "print /(\S.*)/" into a variable?
If the revision does skip or goes backwards, I'd like to take some action on the filename, but I can't seem to get the filename into a variable...
($variable) = /(\S.*)/;
That's what I thought too, but when I do that, my variable is equal to 1...

I changed the syntax a bit from the original, this what I'm using:
        if ( "$next" lt "$after" ) {
            print /(\S.*)/," skipped revisions\n";
            $FILEDREV = /(\S.*)/;
            print "The file is $FILEDREV\n";
        }

When I use a log file that has a skipped revision, the output is:
MMS2/All/versions.properties skipped revisions
The file is 1

($FILEDREV) = /(\S.*)/;
the ( ) puts it in list context