[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

RE: Making tags write-once with a pre-commit hook

From: Durden, Paul <Paul.Durden_at_avocent.com>
Date: 2006-03-31 16:24:23 CEST

Nico,
I found a Perl script that does this. However, I modified the script to
also check the log message for a minimum length, and to allow changes to
a tag if the author is a particular "super user." I did this, because I
found that we sometimes needed to go back and rename tags because the
developer who created the tag didn't follow the desired naming
convention.

Hope this helps.

Paul

--------------------- CUT HERE ---------------------
#!c:/perl/bin/Perl.exe
##
## $Id: prevent-tag-changes.pl 37 2006-03-06 15:55:47Z pdurden $
##

use strict;

my $svnlook = "C:/Program Files/Subversion/bin/svnlook.exe";
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 = "SVN-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 "Cannot modify a tag.\n";
      close INPUT;
      exit 1;
    }
  }
}

close INPUT;
exit 0;
--------------------- CUT HERE ---------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Fri Mar 31 16:29:32 2006

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.