enhanced pre-revprop-change to:
* check the minimum log message length. * check if svn:author is empty * prevent deletion of svn:log, svn:date, svn:author revision properties
This commit is contained in:
		| @ -92,6 +92,44 @@ sub is_project_commitable | ||||
| 	return (((scalar(@row) > 0 && $row[0] eq 'Y')? 1: 0), undef); | ||||
| } | ||||
|  | ||||
| sub check_commit_message | ||||
| { | ||||
| 	my ($minlen) = @_; | ||||
|  | ||||
| 	my $pool = SVN::Pool->new(undef);  | ||||
| 	#my $config = SVN::Core::config_get_config(undef); | ||||
| 	#my $fs = eval { SVN::Fs::open ($REPOFS, $config, $pool) }; | ||||
| 	my $svn = eval { SVN::Repos::open ($REPOFS, $pool) }; | ||||
| 	if (!defined($svn)) | ||||
| 	{ | ||||
| 		print (STDERR "Cannot open svn - $REPOFS\n"); | ||||
| 		return -1; # error | ||||
| 	} | ||||
| 	 | ||||
| 	my $fs = $svn->fs (); | ||||
| 	if (!defined($fs)) | ||||
| 	{ | ||||
| 		print (STDERR "Cannot open fs - $REPOFS\n"); | ||||
| 		return -1; # error | ||||
| 	} | ||||
| 	 | ||||
| 	my $txn = eval { $fs->open_txn ($TRANSACTION) }; | ||||
| 	if (!defined($txn)) | ||||
| 	{ | ||||
| 		print (STDERR "Cannot open transaction - $TRANSACTION\n"); | ||||
| 		return -1; | ||||
| 	} | ||||
| 	 | ||||
| 	my $log = $txn->prop ('svn:log'); | ||||
| 	$log =~ s/^\s+|\s+$//g; # trim leading spaces and  trailing spaces | ||||
| 	if (length($log) < $minlen) { | ||||
| 		print (STDERR "Commit message too short. must be >= $minlen\n"); | ||||
| 		return 0; | ||||
| 	} | ||||
|  | ||||
| 	return 1; | ||||
| } | ||||
|  | ||||
| #------------------------------------------------------------ | ||||
| # MAIN | ||||
| #------------------------------------------------------------ | ||||
| @ -103,38 +141,11 @@ if (!defined($cfg)) | ||||
| 	exit (1); | ||||
| } | ||||
|  | ||||
| my $pool = SVN::Pool->new(undef);  | ||||
| #my $config = SVN::Core::config_get_config(undef); | ||||
| #my $fs = eval { SVN::Fs::open ($REPOFS, $config, $pool) }; | ||||
| my $svn = eval { SVN::Repos::open ($REPOFS, $pool) }; | ||||
| if (!defined($svn)) | ||||
| if (check_commit_message ($cfg->{svn_min_commit_message_length}) <= 0) | ||||
| { | ||||
| 	print (STDERR "Cannot open svn - $REPOFS\n"); | ||||
| 	exit (0); # just let go if the file system can't be opened | ||||
| 	exit (1); | ||||
| } | ||||
|  | ||||
| my $fs = $svn->fs (); | ||||
| if (!defined($fs)) | ||||
| { | ||||
| 	print (STDERR "Cannot open fs - $REPOFS\n"); | ||||
| 	exit (0); # just let go if the file system can't be opened | ||||
| } | ||||
|  | ||||
| my $txn = eval { $fs->open_txn ($TRANSACTION) }; | ||||
| if (!defined($txn)) | ||||
| { | ||||
| 	print (STDERR "Cannot open transaction - $TRANSACTION\n"); | ||||
| 	exit (0); # just let go if the transation can't be opened | ||||
| } | ||||
|  | ||||
| my $log = $txn->prop ('svn:log'); | ||||
| $log =~ s/^\s+|\s+$//g; # trim leading spaces and  trailing spaces | ||||
| if (length($log) < $cfg->{svn_min_commit_message_length}) { | ||||
| 	print (STDERR "Commit message too short. must be >= $cfg->{svn_min_commit_message_length}\n"); | ||||
| 	exit (1); # block  | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
| #my $dbh = open_database ($cfg); | ||||
| #if (!defined($dbh)) | ||||
|  | ||||
| @ -6,8 +6,13 @@ use Config::Simple; | ||||
| use DBI; | ||||
| use File::Basename; | ||||
|  | ||||
| #use SVN::Core; | ||||
| #use SVN::Repos; | ||||
| #use SVN::Fs; | ||||
|  | ||||
| my $CFG_FILE = '@CFGDIR@/codepot.ini'; | ||||
| my $REPOBASE = basename($ARGV[0]); | ||||
| my $REPOFS = $ARGV[0]; | ||||
| my $REPOBASE = basename($REPOFS); | ||||
| my $REVISION= $ARGV[1]; | ||||
| my $USER = $ARGV[2]; | ||||
| my $PROPNAME = $ARGV[3]; | ||||
| @ -28,7 +33,9 @@ sub get_config | ||||
| 		database_password => $cfg->param ("database_password"), | ||||
| 		database_name => $cfg->param ("database_name"), | ||||
| 		database_driver => $cfg->param ("database_driver"), | ||||
|                 database_prefix => $cfg->param ("database_prefix") | ||||
| 		database_prefix => $cfg->param ("database_prefix"), | ||||
|  | ||||
| 		svn_min_commit_message_length => $cfg->param ('svn_min_commit_message_length') | ||||
| 	}; | ||||
|  | ||||
| 	return $config; | ||||
| @ -73,10 +80,42 @@ sub is_project_member | ||||
| 	return (((scalar(@row) > 0)? 1: 0), undef); | ||||
| } | ||||
|  | ||||
| #sub check_commit_message | ||||
| #{ | ||||
| #	my ($minlen, $newmsg) = @_; | ||||
| # | ||||
| #	my $pool = SVN::Pool->new(undef);  | ||||
| #	my $svn = eval { SVN::Repos::open ($REPOFS, $pool) }; | ||||
| #	if (!defined($svn)) | ||||
| #	{ | ||||
| #		print (STDERR "Cannot open svn - $REPOFS\n"); | ||||
| #		return -1; # error | ||||
| #	} | ||||
| #	 | ||||
| #	my $fs = $svn->fs (); | ||||
| #	if (!defined($fs)) | ||||
| #	{ | ||||
| #		print (STDERR "Cannot open fs - $REPOFS\n"); | ||||
| #		return -1; # error | ||||
| #	} | ||||
| #	 | ||||
| #	my $log = $fs->revision_prop ($REVISION, 'svn:log'); | ||||
| #	$log =~ s/^\s+|\s+$//g; # trim leading spaces and  trailing spaces | ||||
| #	if (length($log) < $minlen)  | ||||
| #	{ | ||||
| #		print (STDERR "[$log] Commit message too short. must be >= $minlen\n"); | ||||
| #		return 0; | ||||
| #	} | ||||
| # | ||||
| #	return 1; | ||||
| #} | ||||
|  | ||||
| #------------------------------------------------------------ | ||||
| # MAIN | ||||
| #------------------------------------------------------------ | ||||
|  | ||||
| my $newauthor = undef; | ||||
|  | ||||
| my $cfg = get_config (); | ||||
| if (!defined($cfg)) | ||||
| { | ||||
| @ -84,6 +123,41 @@ if (!defined($cfg)) | ||||
| 	exit (1); | ||||
| } | ||||
|  | ||||
|  | ||||
| if ($ACTION eq 'D') | ||||
| { | ||||
| 	if ($PROPNAME eq 'svn:log' || $PROPNAME eq 'svn:author' || $PROPNAME eq 'svn:date') | ||||
| 	{ | ||||
| 		print (STDERR "Not allowed to delete $PROPNAME\n"); | ||||
| 		exit (1); | ||||
| 	} | ||||
| } | ||||
| elsif ($ACTION eq 'M' || $ACTION eq 'A') | ||||
| { | ||||
| 	if ($PROPNAME eq 'svn:author') | ||||
| 	{ | ||||
| 		$newauthor = do { local $/; <STDIN> }; # read <STDIN> as a whole | ||||
| 		$newauthor =~ s/^\s+|\s+$//g; # trim leading spaces and  trailing spaces | ||||
| 		if ($newauthor eq '')  | ||||
| 		{ | ||||
| 			print (STDERR "Not allowed to empty the author\n"); | ||||
| 			exit (1); | ||||
| 		} | ||||
| 	} | ||||
| 	elsif ($PROPNAME eq 'svn:log') | ||||
| 	{ | ||||
| 		my $minlen = $cfg->{svn_min_commit_message_length}; | ||||
| 		my $newmsg = do { local $/; <STDIN> }; # read <STDIN> as a whole | ||||
| 		$newmsg =~ s/^\s+|\s+$//g; # trim leading spaces and  trailing spaces | ||||
| 		if (length($newmsg) < $minlen)  | ||||
| 		{ | ||||
| 			print (STDERR "Commit message too short. must be >= $minlen\n"); | ||||
| 			exit (1); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
|  | ||||
| my $dbh = open_database ($cfg); | ||||
| if (!defined($dbh)) | ||||
| { | ||||
| @ -93,17 +167,38 @@ if (!defined($dbh)) | ||||
|  | ||||
| my ($member, $errstr) = is_project_member ($dbh, $cfg->{database_prefix}, $REPOBASE, $USER); | ||||
|  | ||||
| close_database ($dbh); | ||||
|  | ||||
| if ($member <= -1) | ||||
| { | ||||
| 	print (STDERR "Cannot check membership - $errstr\n"); | ||||
| 	close_database ($dbh); | ||||
| 	print (STDERR "Cannot check membership of [$USER] in the $REPOBASE project - $errstr\n"); | ||||
| 	exit (1); | ||||
| } | ||||
| elsif ($member == 0) | ||||
| { | ||||
| 	print (STDERR "$USER doesn't belong to the $REPOBASE project\n"); | ||||
| 	close_database ($dbh); | ||||
| 	print (STDERR "[$USER] doesn't belong to the $REPOBASE project\n"); | ||||
| 	exit (1); | ||||
| } | ||||
|  | ||||
| if (defined($newauthor)) | ||||
| { | ||||
| 	# the new author to set must be a member of the project. | ||||
|  | ||||
| 	my ($member, $errstr) = is_project_member ($dbh, $cfg->{database_prefix}, $REPOBASE, $newauthor); | ||||
| 	if ($member <= -1) | ||||
| 	{ | ||||
| 		close_database ($dbh); | ||||
| 		print (STDERR "Cannot check membership of [$newauthor] in the $REPOBASE project - $errstr\n"); | ||||
| 		exit (1); | ||||
| 	} | ||||
| 	elsif ($member == 0) | ||||
| 	{ | ||||
| 		close_database ($dbh); | ||||
| 		print (STDERR "[$newauthor] doesn't belong to the $REPOBASE project\n"); | ||||
| 		exit (1); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| close_database ($dbh); | ||||
| exit (0); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user