#!/usr/bin/perl 
## 
## Check the log message length
##
## Only allow modification of TAGS by admin user
## 


use strict; 


my $svnlook = "/usr/bin/svnlook";
my $repo_path = $ARGV[ 0 ]; 
my $txn_name = $ARGV[ 1 ]; 


## Indicates the minimum log message length 
## If set to 0, message length will not be checked 
my $logMessageLengthMinimum = 10; 


## Indicates the username that can modify tags 
my $svnSuperUser = "Admin"; 


## Indicates if the user can modify tags 
my $allowTagModify = 0; 



## Misc. variables 
my $logMessageLength = 0; 
my $debugEnabled = 0; 
my $argNum = 0; 


## 
## Check to see if debug is enabled 
## 
foreach $argNum (0 .. $#ARGV) 
{ 
  if ( ($ARGV[$argNum] eq "-d") || ($ARGV[$argNum] eq "-D")) 
  { 
    $debugEnabled = 1; 
  } 
} 


if ($debugEnabled) 
{ 
  print "\n------ DEBUG IS ENABLED ------\n"; 
  ## Use revision numbers since there is not a transaction number 
  $txn_name = "-r $txn_name"; 
} 
else 
{ 
  ## Use transaction numbers 
  $txn_name = "-t $txn_name"; 
} 


## 
## Check to see if the log message is long enough 
## 
if ($logMessageLengthMinimum > 0) 
{ 
  open( INPUT, "\"$svnlook\" log $txn_name $repo_path|" ); 
  while( <INPUT> ) 
  { 
    $logMessageLength += length; 
  } 
  close INPUT; 
   
  if ($logMessageLength < $logMessageLengthMinimum) 
  { 
    printf STDERR "Log message length ($logMessageLength) does not meet 
minimum length requirements of $logMessageLengthMinimum.\n"; 
    exit 1; 
  } 
} 


## 
## Check to see if this is a super user that is allowed to change TAGS 
## 
open( INPUT, "\"$svnlook\" author $txn_name $repo_path|" ); 
while( <INPUT> ) 
{ 
  if( /^$svnSuperUser/i ) 
  { 
    if ($debugEnabled) 
    { 
      print "Author == \"$svnSuperUser\", will not check for tags 
modification\n" 
    } 
    $allowTagModify = 1; 
  } 
} 


close INPUT; 


## 
## Check to see if someone is modifying a TAGS directory 
## 
if (!$allowTagModify) 
{ 
  if ($debugEnabled) 
  { 
    print "Checking to see if TAGS directory is being modified\n"; 
  } 
   
  open( INPUT, "\"$svnlook\" changed $txn_name $repo_path|" ); 
  while( <INPUT> ) 
  { 
    if( /^[UD]\s*?.*?\/?tags\/.*/i ) 
    { 
      printf STDERR "Tags can only be modified by $svnSuperUser.\n"; 
      close INPUT; 
      exit 1; 
    } 
  } 
} 


close INPUT; 
exit 0; 


