pkg-kde: commit - rev 207 - scripts/svn-hooks
Author: dato-guest
Date: 2004-11-07 14:22:50 -0700 (Sun, 07 Nov 2004)
New Revision: 207
Added:
scripts/svn-hooks/commit-access-control.pl
scripts/svn-hooks/commit-email.pl
scripts/svn-hooks/post-commit
scripts/svn-hooks/post-revprop-change
scripts/svn-hooks/pre-commit
scripts/svn-hooks/pre-revprop-change
scripts/svn-hooks/propchange-email.pl
scripts/svn-hooks/start-commit
Log:
Commited current versions of svn hooks.
Added: scripts/svn-hooks/commit-access-control.pl
===================================================================
--- scripts/svn-hooks/commit-access-control.pl 2004-11-07 21:19:52 UTC (rev 206)
+++ scripts/svn-hooks/commit-access-control.pl 2004-11-07 21:22:50 UTC (rev 207)
@@ -0,0 +1,398 @@
+#!/usr/bin/perl -w
+
+# ====================================================================
+# commit-access-control.pl: check if the user that submitted the
+# transaction TXN-NAME has the appropriate rights to perform the
+# commit in repository REPOS using the permissions listed in the
+# configuration file CONF_FILE.
+#
+# $HeadURL: http://svn.collab.net/repos/svn/branches/release-0.31.0/tools/hook-scripts/commit-access-control.pl.in $
+# $LastChangedDate: 2003-08-01 13:25:14 -0400 (Fri, 01 Aug 2003) $
+# $LastChangedBy: kfogel $
+# $LastChangedRevision: 6626 $
+#
+# Usage: commit-access-control.pl REPOS TXN-NAME CONF_FILE
+#
+# ====================================================================
+# Copyright (c) 2000-2003 CollabNet. All rights reserved.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at http://subversion.tigris.org/license-1.html.
+# If newer versions of this license are posted there, you may use a
+# newer version instead, at your option.
+#
+# This software consists of voluntary contributions made by many
+# individuals. For exact contribution history, see the revision
+# history and logs, available at http://subversion.tigris.org/.
+# ====================================================================
+
+use strict;
+use Carp;
+use Config::IniFiles 2.27;
+
+######################################################################
+# Configuration section.
+
+# Svnlook path.
+my $svnlook = "/usr/bin/svnlook";
+
+# Since the path to svnlook depends upon the local installation
+# preferences, check that the required program exists to insure that
+# the administrator has set up the script properly.
+{
+ my $ok = 1;
+ foreach my $program ($svnlook)
+ {
+ if (-e $program)
+ {
+ unless (-x $program)
+ {
+ warn "$0: required program `$program' is not executable, ",
+ "edit $0.\n";
+ $ok = 0;
+ }
+ }
+ else
+ {
+ warn "$0: required program `$program' does not exist, edit $0.\n";
+ $ok = 0;
+ }
+ }
+ exit 1 unless $ok;
+}
+
+######################################################################
+# Initial setup/command-line handling.
+
+&usage unless @ARGV == 3;
+
+my $repos = shift;
+my $txn = shift;
+my $cfg_filename = shift;
+
+unless (-e $repos)
+ {
+ &usage("$0: repository directory `$repos' does not exist.");
+ }
+unless (-d $repos)
+ {
+ &usage("$0: repository directory `$repos' is not a directory.");
+ }
+unless (-e $cfg_filename)
+ {
+ &usage("$0: configuration file `$cfg_filename' does not exist.");
+ }
+unless (-r $cfg_filename)
+ {
+ &usage("$0: configuration file `$cfg_filename' is not readable.");
+ }
+
+# Define two constant subroutines to stand for read-only or read-write
+# access to the repository.
+sub ACCESS_READ_ONLY () { 'read-only' }
+sub ACCESS_READ_WRITE () { 'read-write' }
+
+######################################################################
+# Load the configuration file and validate it.
+my $cfg = Config::IniFiles->new(-file => $cfg_filename);
+unless ($cfg)
+ {
+ die "$0: error in loading configuration file `$cfg_filename'",
+ @Config::IniFiles::errors ? ":\n@Config::IniFiles::errors\n"
+ : ".\n";
+ }
+
+# Go through each section of the configuration file, validate that
+# each section has the required parameters and complain about unknown
+# parameters. Compile any regular expressions.
+my @sections = $cfg->Sections;
+{
+ my $ok = 1;
+ foreach my $section (@sections)
+ {
+ # First check for any unknown parameters.
+ foreach my $param ($cfg->Parameters($section))
+ {
+ next if $param eq 'match';
+ next if $param eq 'users';
+ next if $param eq 'access';
+ warn "$0: config file `$cfg_filename' section `$section' parameter ",
+ "`$param' is being ignored.\n";
+ $cfg->delval($section, $param);
+ }
+
+ my $access = $cfg->val($section, 'access');
+ if (defined $access)
+ {
+ unless ($access eq ACCESS_READ_ONLY or $access eq ACCESS_READ_WRITE)
+ {
+ warn "$0: config file `$cfg_filename' section `$section' sets ",
+ "`access' to illegal value `$access'.\n";
+ $ok = 0;
+ }
+ }
+ else
+ {
+ warn "$0: config file `$cfg_filename' section `$section' does ",
+ "not set `access' parameter.\n";
+ $ok = 0;
+ }
+
+ my $match_regex = $cfg->val($section, 'match');
+ if (defined $match_regex)
+ {
+ # To help users that automatically write regular expressions
+ # that match the beginning of absolute paths using ^/,
+ # remove the / character because subversion paths, while
+ # they start at the root level, do not begin with a /.
+ $match_regex =~ s#^\^/#^#;
+
+ my $match_re;
+ eval { $match_re = qr/$match_regex/ };
+ if ($@)
+ {
+ warn "$0: config file `$cfg_filename' section `$section' ",
+ "`match' regex `$match_regex' does not compile:\n$@\n";
+ $ok = 0;
+ }
+ else
+ {
+ $cfg->newval($section, 'match_re', $match_re);
+ }
+ }
+ else
+ {
+ warn "$0: config file `$cfg_filename' section `$section' does ",
+ "not set `match' parameter.\n";
+ $ok = 0;
+ }
+ }
+ exit 1 unless $ok;
+}
+
+######################################################################
+# Harvest data using svnlook.
+
+# Change into /tmp so that svnlook diff can create its .svnlook
+# directory.
+my $tmp_dir = '/tmp';
+chdir($tmp_dir)
+ or die "$0: cannot chdir `$tmp_dir': $!\n";
+
+# Get the author from svnlook.
+my @svnlooklines = &read_from_process($svnlook, 'author', $repos, '-t', $txn);
+my $author = shift @svnlooklines;
+unless (length $author)
+ {
+ die "$0: txn `$txn' has no author.\n";
+ }
+
+# Figure out what directories have changed using svnlook..
+my @dirs_changed = &read_from_process($svnlook, 'dirs-changed', $repos,
+ '-t', $txn);
+
+# Lose the trailing slash in the directory names if one exists, except
+# in the case of '/'.
+my $rootchanged = 0;
+for (my $i=0; $i<@dirs_changed; ++$i)
+ {
+ if ($dirs_changed[$i] eq '/')
+ {
+ $rootchanged = 1;
+ }
+ else
+ {
+ $dirs_changed[$i] =~ s#^(.+)[/\\]$#$1#;
+ }
+ }
+
+# Figure out what files have changed using svnlook.
+my @files_changed;
+foreach my $line (&read_from_process($svnlook, 'changed', $repos, '-t', $txn))
+ {
+ # Split the line up into the modification code and path, ignoring
+ # property modifications.
+ if ($line =~ /^.. (.*)$/)
+ {
+ push(@files_changed, $1);
+ }
+ }
+
+# Create the list of all modified paths.
+my @changed = (@dirs_changed, @files_changed);
+
+# There should always be at least one changed path. If there are
+# none, then there maybe something fishy going on, so just exit now
+# indicating that the commit should not proceed.
+unless (@changed)
+ {
+ die "$0: no changed paths found in txn `$txn'.\n";
+ }
+
+######################################################################
+# Populate the permissions table.
+
+# Set a hash keeping track of the access rights to each path. Because
+# this is an access control script, set the default permissions to
+# read-only.
+my %permissions;
+foreach my $path (@changed)
+ {
+ $permissions{$path} = ACCESS_READ_ONLY;
+ }
+
+foreach my $section (@sections)
+ {
+ # Decide if this section should be used. It should be used if
+ # there are no users listed at all for this section, or if there
+ # are users listed and the author is one of them.
+ my $use_this_section;
+
+ # If there are any users listed, then check if the author of this
+ # commit is listed in the list. If not, then delete the section,
+ # because it won't apply.
+ #
+ # The configuration file can list users like this on multiple
+ # lines:
+ # users = joe@mysite.com betty@mysite.com
+ # users = bob@yoursite.com
+
+ # Because of the way Config::IniFiles works, check if there are
+ # any users at all with the scalar return from val() and if there,
+ # then get the array value to get all users.
+ my $users = $cfg->val($section, 'users');
+ if (defined $users and length $users)
+ {
+ my $match_user = 0;
+ foreach my $entry ($cfg->val($section, 'users'))
+ {
+ unless ($match_user)
+ {
+ foreach my $user (split(' ', $entry))
+ {
+ if ($author eq $user)
+ {
+ $match_user = 1;
+ last;
+ }
+ }
+ }
+ }
+
+ $use_this_section = $match_user;
+ }
+ else
+ {
+ $use_this_section = 1;
+ }
+
+ next unless $use_this_section;
+
+ # Go through each modified path and match it to the regular
+ # expression and set the access right if the regular expression
+ # matches.
+ my $access = $cfg->val($section, 'access');
+ my $match_re = $cfg->val($section, 'match_re');
+ foreach my $path (@changed)
+ {
+ $permissions{$path} = $access if $path =~ $match_re;
+ }
+ }
+
+# Go through all the modified paths and see if any permissions are
+# read-only. If so, then fail the commit.
+my @failed_paths;
+foreach my $path (@changed)
+ {
+ if ($permissions{$path} ne ACCESS_READ_WRITE)
+ {
+ push(@failed_paths, $path);
+ }
+ }
+
+if (@failed_paths)
+ {
+ warn "$0: user `$author' does not have permission to commit to ",
+ @failed_paths > 1 ? "these paths:\n " : "this path:\n ",
+ join("\n ", @failed_paths), "\n";
+ exit 1;
+ }
+else
+ {
+ exit 0;
+ }
+
+sub usage
+{
+ warn "@_\n" if @_;
+ die "usage: $0 REPOS TXN-NAME CONF_FILE\n";
+}
+
+sub safe_read_from_pipe
+{
+ unless (@_)
+ {
+ croak "$0: safe_read_from_pipe passed no arguments.\n";
+ }
+ print "Running @_\n";
+ my $pid = open(SAFE_READ, '-|');
+ unless (defined $pid)
+ {
+ die "$0: cannot fork: $!\n";
+ }
+ unless ($pid)
+ {
+ open(STDERR, ">&STDOUT")
+ or die "$0: cannot dup STDOUT: $!\n";
+ exec(@_)
+ or die "$0: cannot exec `@_': $!\n";
+ }
+ my @output;
+ while (<SAFE_READ>)
+ {
+ chomp;
+ push(@output, $_);
+ }
+ close(SAFE_READ);
+ my $result = $?;
+ my $exit = $result >> 8;
+ my $signal = $result & 127;
+ my $cd = $result & 128 ? "with core dump" : "";
+ if ($signal or $cd)
+ {
+ warn "$0: pipe from `@_' failed $cd: exit=$exit signal=$signal\n";
+ }
+ if (wantarray)
+ {
+ return ($result, @output);
+ }
+ else
+ {
+ return $result;
+ }
+}
+
+sub read_from_process
+ {
+ unless (@_)
+ {
+ croak "$0: read_from_process passed no arguments.\n";
+ }
+ my ($status, @output) = &safe_read_from_pipe(@_);
+ if ($status)
+ {
+ if (@output)
+ {
+ die "$0: `@_' failed with this output:\n", join("\n", @output), "\n";
+ }
+ else
+ {
+ die "$0: `@_' failed with no output.\n";
+ }
+ }
+ else
+ {
+ return @output;
+ }
+}
Property changes on: scripts/svn-hooks/commit-access-control.pl
___________________________________________________________________
Name: svn:executable
+ *
Added: scripts/svn-hooks/commit-email.pl
===================================================================
--- scripts/svn-hooks/commit-email.pl 2004-11-07 21:19:52 UTC (rev 206)
+++ scripts/svn-hooks/commit-email.pl 2004-11-07 21:22:50 UTC (rev 207)
@@ -0,0 +1,583 @@
+#!/usr/bin/perl -w
+
+# ====================================================================
+# commit-email.pl: send a commit email for commit REVISION in
+# repository REPOS to some email addresses.
+#
+# For usage, see the usage subroutine or run the script with no
+# command line arguments.
+#
+# $HeadURL: http://svn.collab.net/repos/svn/branches/release-0.31.0/tools/hook-scripts/commit-email.pl.in $
+# $LastChangedDate: 2003-08-01 13:25:14 -0400 (Fri, 01 Aug 2003) $
+# $LastChangedBy: kfogel $
+# $LastChangedRevision: 6626 $
+#
+# ====================================================================
+# Copyright (c) 2000-2003 CollabNet. All rights reserved.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at http://subversion.tigris.org/license-1.html.
+# If newer versions of this license are posted there, you may use a
+# newer version instead, at your option.
+#
+# This software consists of voluntary contributions made by many
+# individuals. For exact contribution history, see the revision
+# history and logs, available at http://subversion.tigris.org/.
+# ====================================================================
+
+use strict;
+use Carp;
+
+######################################################################
+# Configuration section.
+
+# Sendmail path.
+my $sendmail = "/usr/sbin/sendmail";
+
+# Svnlook path.
+my $svnlook = "/usr/bin/svnlook";
+
+# By default, when a file is deleted from the repository, svnlook diff
+# prints the entire contents of the file. If you want to save space
+# in the log and email messages by not printing the file, then set
+# $no_diff_deleted to 1.
+my $no_diff_deleted = 0;
+
+# Since the path to svnlook depends upon the local installation
+# preferences, check that the required programs exist to insure that
+# the administrator has set up the script properly.
+{
+ my $ok = 1;
+ foreach my $program ($sendmail, $svnlook)
+ {
+ if (-e $program)
+ {
+ unless (-x $program)
+ {
+ warn "$0: required program `$program' is not executable, ",
+ "edit $0.\n";
+ $ok = 0;
+ }
+ }
+ else
+ {
+ warn "$0: required program `$program' does not exist, edit $0.\n";
+ $ok = 0;
+ }
+ }
+ exit 1 unless $ok;
+}
+
+
+######################################################################
+# Initial setup/command-line handling.
+
+# Each value in this array holds a hash reference which contains the
+# associated email information for one project. Start with an
+# implicit rule that matches all paths.
+my @project_settings_list = (&new_project);
+
+# Process the command line arguments till there are none left. The
+# first two arguments that are not used by a command line option are
+# the repository path and the revision number.
+my $repos;
+my $rev;
+
+# Use the reference to the first project to populate.
+my $current_project = $project_settings_list[0];
+
+# This hash matches the command line option to the hash key in the
+# project. If a key exists but has a false value (''), then the
+# command line option is allowed but requires special handling.
+my %opt_to_hash_key = ('--from' => 'from_address',
+ '-h' => 'hostname',
+ '-l' => 'log_file',
+ '-m' => '',
+ '-r' => 'reply_to',
+ '-s' => 'subject_prefix');
+
+while (@ARGV)
+ {
+ my $arg = shift @ARGV;
+ if ($arg =~ /^-/)
+ {
+ my $hash_key = $opt_to_hash_key{$arg};
+ unless (defined $hash_key)
+ {
+ die "$0: command line option `$arg' is not recognized.\n";
+ }
+
+ unless (@ARGV)
+ {
+ die "$0: command line option `$arg' is missing a value.\n";
+ }
+ my $value = shift @ARGV;
+
+ if ($hash_key)
+ {
+ $current_project->{$hash_key} = $value;
+ }
+ else
+ {
+ # Here handle -m.
+ unless ($arg eq '-m')
+ {
+ die "$0: internal error: should only handle -m here.\n";
+ }
+ $current_project = &new_project;
+ $current_project->{match_regex} = $value;
+ push(@project_settings_list, $current_project);
+ }
+ }
+ elsif ($arg =~ /^-/)
+ {
+ die "$0: command line option `$arg' is not recognized.\n";
+ }
+ else
+ {
+ if (! defined $repos)
+ {
+ $repos = $arg;
+ }
+ elsif (! defined $rev)
+ {
+ $rev = $arg;
+ }
+ else
+ {
+ push(@{$current_project->{email_addresses}}, $arg);
+ }
+ }
+ }
+
+# If the revision number is undefined, then there were not enough
+# command line arguments.
+&usage("$0: too few arguments.") unless defined $rev;
+
+# Check the validity of the command line arguments. Check that the
+# revision is an integer greater than 0 and that the repository
+# directory exists.
+unless ($rev =~ /^\d+/ and $rev > 0)
+ {
+ &usage("$0: revision number `$rev' must be an integer > 0.");
+ }
+unless (-e $repos)
+ {
+ &usage("$0: repos directory `$repos' does not exist.");
+ }
+unless (-d _)
+ {
+ &usage("$0: repos directory `$repos' is not a directory.");
+ }
+
+# Check that all of the regular expressions can be compiled and
+# compile them.
+{
+ my $ok = 1;
+ for (my $i=0; $i<@project_settings_list; ++$i)
+ {
+ my $match_regex = $project_settings_list[$i]->{match_regex};
+
+ # To help users that automatically write regular expressions
+ # that match the root directory using ^/, remove the / character
+ # because subversion paths, while they start at the root level,
+ # do not begin with a /.
+ $match_regex =~ s#^\^/#^#;
+
+ my $match_re;
+ eval { $match_re = qr/$match_regex/ };
+ if ($@)
+ {
+ warn "$0: -m regex #$i `$match_regex' does not compile:\n$@\n";
+ $ok = 0;
+ next;
+ }
+ $project_settings_list[$i]->{match_re} = $match_re;
+ }
+ exit 1 unless $ok;
+}
+
+######################################################################
+# Harvest data using svnlook.
+
+# Change into /tmp so that svnlook diff can create its .svnlook
+# directory.
+my $tmp_dir = '/tmp';
+chdir($tmp_dir)
+ or die "$0: cannot chdir `$tmp_dir': $!\n";
+
+# Get the author, date, and log from svnlook.
+my @svnlooklines = &read_from_process($svnlook, 'info', $repos, '-r', $rev);
+my $author = shift @svnlooklines;
+my $date = shift @svnlooklines;
+shift @svnlooklines;
+my @log = map { "$_\n" } @svnlooklines;
+
+# Figure out what directories have changed using svnlook.
+my @dirschanged = &read_from_process($svnlook, 'dirs-changed', $repos,
+ '-r', $rev);
+
+# Lose the trailing slash in the directory names if one exists, except
+# in the case of '/'.
+my $rootchanged = 0;
+for (my $i=0; $i<@dirschanged; ++$i)
+ {
+ if ($dirschanged[$i] eq '/')
+ {
+ $rootchanged = 1;
+ }
+ else
+ {
+ $dirschanged[$i] =~ s#^(.+)[/\\]$#$1#;
+ }
+ }
+
+# Figure out what files have changed using svnlook.
+@svnlooklines = &read_from_process($svnlook, 'changed', $repos, '-r', $rev);
+
+# Parse the changed nodes.
+my @adds;
+my @dels;
+my @mods;
+foreach my $line (@svnlooklines)
+ {
+ my $path = '';
+ my $code = '';
+
+ # Split the line up into the modification code and path, ignoring
+ # property modifications.
+ if ($line =~ /^(.). (.*)$/)
+ {
+ $code = $1;
+ $path = $2;
+ }
+
+ if ($code eq 'A')
+ {
+ push(@adds, $path);
+ }
+ elsif ($code eq 'D')
+ {
+ push(@dels, $path);
+ }
+ else
+ {
+ push(@mods, $path);
+ }
+ }
+
+# Get the diff from svnlook.
+my @no_diff_deleted = $no_diff_deleted ? ('--no-diff-deleted') : ();
+my @difflines = &read_from_process($svnlook, 'diff', $repos,
+ '-r', $rev, @no_diff_deleted);
+
+######################################################################
+# Modified directory name collapsing.
+
+# Collapse the list of changed directories only if the root directory
+# was not modified, because otherwise everything is under root and
+# there's no point in collapsing the directories, and only if more
+# than one directory was modified.
+my $commondir = '';
+if (!$rootchanged and @dirschanged > 1)
+ {
+ my $firstline = shift @dirschanged;
+ my @commonpieces = split('/', $firstline);
+ foreach my $line (@dirschanged)
+ {
+ my @pieces = split('/', $line);
+ my $i = 0;
+ while ($i < @pieces and $i < @commonpieces)
+ {
+ if ($pieces[$i] ne $commonpieces[$i])
+ {
+ splice(@commonpieces, $i, @commonpieces - $i);
+ last;
+ }
+ $i++;
+ }
+ }
+ unshift(@dirschanged, $firstline);
+
+ if (@commonpieces)
+ {
+ $commondir = join('/', @commonpieces);
+ my @new_dirschanged;
+ foreach my $dir (@dirschanged)
+ {
+ if ($dir eq $commondir)
+ {
+ $dir = '.';
+ }
+ else
+ {
+ $dir =~ s#^$commondir/##;
+ }
+ push(@new_dirschanged, $dir);
+ }
+ @dirschanged = @new_dirschanged;
+ }
+ }
+my $dirlist = join(' ', @dirschanged);
+
+######################################################################
+# Assembly of log message.
+
+# Put together the body of the log message.
+my @body;
+push(@body, "Author: $author\n");
+push(@body, "Date: $date\n");
+push(@body, "New Revision: $rev\n");
+push(@body, "\n");
+if (@adds)
+ {
+ @adds = sort @adds;
+ push(@body, "Added:\n");
+ push(@body, map { " $_\n" } @adds);
+ }
+if (@dels)
+ {
+ @dels = sort @dels;
+ push(@body, "Removed:\n");
+ push(@body, map { " $_\n" } @dels);
+ }
+if (@mods)
+ {
+ @mods = sort @mods;
+ push(@body, "Modified:\n");
+ push(@body, map { " $_\n" } @mods);
+ }
+push(@body, "Log:\n");
+push(@body, @log);
+push(@body, "\n");
+push(@body, map { /[\r\n]+$/ ? $_ : "$_\n" } @difflines);
+
+# Go through each project and see if there are any matches for this
+# project. If so, send the log out.
+foreach my $project (@project_settings_list)
+ {
+ my $match_re = $project->{match_re};
+ my $match = 0;
+ foreach my $path (@dirschanged, @adds, @dels, @mods)
+ {
+ if ($path =~ $match_re)
+ {
+ $match = 1;
+ last;
+ }
+ }
+
+ next unless $match;
+
+ my @email_addresses = @{$project->{email_addresses}};
+ my $userlist = join(' ', @email_addresses);
+ my $from_address = $project->{from_address};
+ my $hostname = $project->{hostname};
+ my $log_file = $project->{log_file};
+ my $reply_to = $project->{reply_to};
+ my $subject_prefix = $project->{subject_prefix};
+ my $subject;
+
+ if ($commondir ne '')
+ {
+ $subject = "rev $rev - in $commondir: $dirlist";
+ }
+ else
+ {
+ $subject = "rev $rev - $dirlist";
+ }
+ if ($subject_prefix =~ /\w/)
+ {
+ $subject = "$subject_prefix $subject";
+ }
+ my $mail_from = $author;
+
+ if ($from_address =~ /\w/)
+ {
+ $mail_from = $from_address;
+ }
+ elsif ($hostname =~ /\w/)
+ {
+ $mail_from = "$mail_from\@$hostname";
+ }
+
+ my @head;
+ push(@head, "To: $userlist\n");
+ push(@head, "From: $mail_from\n");
+ push(@head, "Subject: $subject\n");
+ push(@head, "Reply-to: $reply_to\n") if $reply_to;
+
+ ### Below, we set the content-type etc, but see these comments
+ ### from Greg Stein on why this is not a full solution.
+ #
+ # From: Greg Stein <gstein@lyra.org>
+ # Subject: Re: svn commit: rev 2599 - trunk/tools/cgi
+ # To: dev@subversion.tigris.org
+ # Date: Fri, 19 Jul 2002 23:42:32 -0700
+ #
+ # Well... that isn't strictly true. The contents of the files
+ # might not be UTF-8, so the "diff" portion will be hosed.
+ #
+ # If you want a truly "proper" commit message, then you'd use
+ # multipart MIME messages, with each file going into its own part,
+ # and labeled with an appropriate MIME type and charset. Of
+ # course, we haven't defined a charset property yet, but no biggy.
+ #
+ # Going with multipart will surely throw out the notion of "cut
+ # out the patch from the email and apply." But then again: the
+ # commit emailer could see that all portions are in the same
+ # charset and skip the multipart thang.
+ #
+ # etc etc
+ #
+ # Basically: adding/tweaking the content-type is nice, but don't
+ # think that is the proper solution.
+ push(@head, "Content-Type: text/plain; charset=UTF-8\n");
+ push(@head, "Content-Transfer-Encoding: 8bit\n");
+
+ push(@head, "\n");
+
+ if ($sendmail =~ /\w/ and @email_addresses)
+ {
+ # Open a pipe to sendmail.
+ my $command = "$sendmail $userlist";
+ if (open(SENDMAIL, "| $command"))
+ {
+ print SENDMAIL @head, @body;
+ close SENDMAIL
+ or warn "$0: error in closing `$command' for writing: $!\n";
+ }
+ else
+ {
+ warn "$0: cannot open `| $command' for writing: $!\n";
+ }
+ }
+
+ # Dump the output to logfile (if its name is not empty).
+ if ($log_file =~ /\w/)
+ {
+ if (open(LOGFILE, ">> $log_file"))
+ {
+ print LOGFILE @head, @body;
+ close LOGFILE
+ or warn "$0: error in closing `$log_file' for appending: $!\n";
+ }
+ else
+ {
+ warn "$0: cannot open `$log_file' for appending: $!\n";
+ }
+ }
+ }
+
+exit 0;
+
+sub usage
+{
+ warn "@_\n" if @_;
+ die "usage: $0 REPOS REVNUM [[-m regex] [options] [email_addr ...]] ...\n",
+ "options are\n",
+ " --from email_address Email address for 'From:' (overrides -h)\n",
+ " -h hostname Hostname to append to author for 'From:'\n",
+ " -l logfile Append mail contents to this log file\n",
+ " -m regex Regular expression to match committed path\n",
+ " -r email_address Email address for 'Reply-To:'\n",
+ " -s subject_prefix Subject line prefix\n",
+ "\n",
+ "This script supports a single repository with multiple projects,\n",
+ "where each project receives email only for commits that modify that\n",
+ "project. A project is identified by using the -m command line\n",
+ "with a regular expression argument. If a commit has a path that\n",
+ "matches the regular expression, then the entire commit matches.\n",
+ "Any of the following -h, -l, -r and -s command line options and\n",
+ "following email addresses are associated with this project. The\n",
+ "next -m resets the -h, -l, -r and -s command line options and the\n",
+ "list of email addresses.\n",
+ "\n",
+ "To support a single project conveniently, the script initializes\n",
+ "itself with an implicit -m . rule that matches any modifications\n",
+ "to the repository. Therefore, to use the script for a single\n",
+ "project repository, just use the other comand line options and\n",
+ "a list of email addresses on the command line. If you do not want\n",
+ "a project that matches the entire repository, then use a -m with a\n",
+ "regular expression before any other command line options or email\n",
+ "addresses.\n";
+}
+
+# Return a new hash data structure for a new empty project that
+# matches any modifications to the repository.
+sub new_project
+{
+ return {email_addresses => [],
+ from_address => '',
+ hostname => '',
+ log_file => '',
+ match_regex => '.',
+ reply_to => '',
+ subject_prefix => ''};
+}
+
+# Start a child process safely without using /bin/sh.
+sub safe_read_from_pipe
+{
+ unless (@_)
+ {
+ croak "$0: safe_read_from_pipe passed no arguments.\n";
+ }
+
+ my $pid = open(SAFE_READ, '-|');
+ unless (defined $pid)
+ {
+ die "$0: cannot fork: $!\n";
+ }
+ unless ($pid)
+ {
+ open(STDERR, ">&STDOUT")
+ or die "$0: cannot dup STDOUT: $!\n";
+ exec(@_)
+ or die "$0: cannot exec `@_': $!\n";
+ }
+ my @output;
+ while (<SAFE_READ>)
+ {
+ s/[\r\n]+$//;
+ push(@output, $_);
+ }
+ close(SAFE_READ);
+ my $result = $?;
+ my $exit = $result >> 8;
+ my $signal = $result & 127;
+ my $cd = $result & 128 ? "with core dump" : "";
+ if ($signal or $cd)
+ {
+ warn "$0: pipe from `@_' failed $cd: exit=$exit signal=$signal\n";
+ }
+ if (wantarray)
+ {
+ return ($result, @output);
+ }
+ else
+ {
+ return $result;
+ }
+}
+
+# Use safe_read_from_pipe to start a child process safely and return
+# the output if it succeeded or an error message followed by the output
+# if it failed.
+sub read_from_process
+{
+ unless (@_)
+ {
+ croak "$0: read_from_process passed no arguments.\n";
+ }
+ my ($status, @output) = &safe_read_from_pipe(@_);
+ if ($status)
+ {
+ return ("$0: `@_' failed with this output:", @output);
+ }
+ else
+ {
+ return @output;
+ }
+}
Property changes on: scripts/svn-hooks/commit-email.pl
___________________________________________________________________
Name: svn:executable
+ *
Added: scripts/svn-hooks/post-commit
===================================================================
--- scripts/svn-hooks/post-commit 2004-11-07 21:19:52 UTC (rev 206)
+++ scripts/svn-hooks/post-commit 2004-11-07 21:22:50 UTC (rev 207)
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+# POST-COMMIT HOOK
+#
+# The post-commit hook is invoked after a commit. Subversion runs
+# this hook by invoking a program (script, executable, binary,
+# etc.) named 'post-commit' (for which
+# this file is a template) with the following ordered arguments:
+#
+# [1] REPOS-PATH (the path to this repository)
+# [2] REV (the number of the revision just committed)
+#
+# Because the commit has already completed and cannot be undone,
+# the exit code of the hook program is ignored. The hook program
+# can use the 'svnlook' utility to help it examine the
+# newly-committed tree.
+#
+# On a Unix system, the normal procedure is to have 'post-commit'
+# invoke other programs to do the real work, though it may do the
+# work itself too.
+#
+# Note that 'post-commit' must be executable by the user(s) who will
+# invoke it (typically the user httpd runs as), and that user must
+# have filesystem-level permission to access the repository.
+#
+# On a Windows system, you should name the hook program
+# 'post-commit.bat' or 'post-commit.exe',
+# but the basic idea is the same.
+#
+# Here is an example hook script, for a Unix /bin/sh interpreter:
+
+REPOS="$1"
+REV="$2"
+
+#/svn/pkg-kde/hooks/commit-email.pl "$REPOS" "$REV" debian-qt-kde@lists.debian.org
+/svn/pkg-kde/hooks/commit-email.pl "$REPOS" "$REV" -s "pkg-kde: commit -" debian-qt-kde@lists.debian.org
+# CHRIS CHENEY - NONEXISTANT SCRIPT
+#log-commit.py --repository "$REPOS" --revision "$REV"
Property changes on: scripts/svn-hooks/post-commit
___________________________________________________________________
Name: svn:executable
+ *
Added: scripts/svn-hooks/post-revprop-change
===================================================================
--- scripts/svn-hooks/post-revprop-change 2004-11-07 21:19:52 UTC (rev 206)
+++ scripts/svn-hooks/post-revprop-change 2004-11-07 21:22:50 UTC (rev 207)
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+# POST-REVPROP-CHANGE HOOK
+#
+# The post-revprop-change hook is invoked after a revision property
+# has been changed. Subversion runs this hook by invoking a program
+# (script, executable, binary, etc.) named 'post-revprop-change'
+# (for which this file is a template), with the following ordered
+# arguments:
+#
+# [1] REPOS-PATH (the path to this repository)
+# [2] REV (the revision that was tweaked)
+# [3] USER (the username of the person tweaking the property)
+# [4] PROPNAME (the property that was changed)
+#
+# Because the propchange has already completed and cannot be undone,
+# the exit code of the hook program is ignored. The hook program
+# can use the 'svnlook' utility to help it examine the
+# new property value.
+#
+# On a Unix system, the normal procedure is to have 'post-revprop-change'
+# invoke other programs to do the real work, though it may do the
+# work itself too.
+#
+# Note that 'post-revprop-change' must be executable by the user(s) who will
+# invoke it (typically the user httpd runs as), and that user must
+# have filesystem-level permission to access the repository.
+#
+# On a Windows system, you should name the hook program
+# 'post-revprop-change.bat' or 'post-revprop-change.exe',
+# but the basic idea is the same.
+#
+# Here is an example hook script, for a Unix /bin/sh interpreter:
+
+REPOS="$1"
+REV="$2"
+USER="$3"
+PROPNAME="$4"
+
+#/svn/pkg-kde/hooks/propchange-email.pl "$REPOS" "$REV" "$USER" "$PROPNAME" debian-qt-kde@lists.debian.org
+/svn/pkg-kde/hooks/propchange-email.pl "$REPOS" "$REV" "$USER" "$PROPNAME" -s "pkg-kde:" debian-qt-kde@lists.debian.org
Property changes on: scripts/svn-hooks/post-revprop-change
___________________________________________________________________
Name: svn:executable
+ *
Added: scripts/svn-hooks/pre-commit
===================================================================
--- scripts/svn-hooks/pre-commit 2004-11-07 21:19:52 UTC (rev 206)
+++ scripts/svn-hooks/pre-commit 2004-11-07 21:22:50 UTC (rev 207)
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+# PRE-COMMIT HOOK
+#
+# The pre-commit hook is invoked before a Subversion txn is
+# committed. Subversion runs this hook by invoking a program
+# (script, executable, binary, etc.) named 'pre-commit' (for which
+# this file is a template), with the following ordered arguments:
+#
+# [1] REPOS-PATH (the path to this repository)
+# [2] TXN-NAME (the name of the txn about to be committed)
+#
+# If the hook program exits with success, the txn is committed; but
+# if it exits with failure (non-zero), the txn is aborted and no
+# commit takes place. The hook program can use the 'svnlook'
+# utility to help it examine the txn.
+#
+# On a Unix system, the normal procedure is to have 'pre-commit'
+# invoke other programs to do the real work, though it may do the
+# work itself too.
+#
+# *** NOTE: THE HOOK PROGRAM MUST NOT MODIFY THE TXN. ***
+# This is why we recommend using the read-only 'svnlook' utility.
+# In the future, Subversion may enforce the rule that pre-commit
+# hooks should not modify txns, or else come up with a mechanism
+# to make it safe to do so (by informing the committing client of
+# the changes). However, right now neither mechanism is
+# implemented, so hook writers just have to be careful.
+#
+# Note that 'pre-commit' must be executable by the user(s) who will
+# invoke it (typically the user httpd runs as), and that user must
+# have filesystem-level permission to access the repository.
+#
+# On a Windows system, you should name the hook program
+# 'pre-commit.bat' or 'pre-commit.exe',
+# but the basic idea is the same.
+#
+# Here is an example hook script, for a Unix /bin/sh interpreter:
+
+REPOS="$1"
+TXN="$2"
+
+# Make sure that the log message contains some text.
+SVNLOOK=/usr/bin/svnlook
+LOG=`$SVNLOOK log -t "$TXN" "$REPOS"`
+echo "$LOG" | grep "[a-zA-Z0-9]" > /dev/null || exit 1
+
+# Check that the author of this commit has the rights to perform
+# the commit on the files and directories being modified.
+/svn/pkg-kde/hooks/commit-access-control.pl "$REPOS" "$TXN" /svn/pkg-kde/hooks/commit-access-control.cfg || exit 1
+
+# All checks passed, so allow the commit.
+exit 0
Property changes on: scripts/svn-hooks/pre-commit
___________________________________________________________________
Name: svn:executable
+ *
Added: scripts/svn-hooks/pre-revprop-change
===================================================================
--- scripts/svn-hooks/pre-revprop-change 2004-11-07 21:19:52 UTC (rev 206)
+++ scripts/svn-hooks/pre-revprop-change 2004-11-07 21:22:50 UTC (rev 207)
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+# PRE-REVPROP-CHANGE HOOK
+#
+# The pre-revprop-change hook is invoked before a revision property
+# is modified. Subversion runs this hook by invoking a program
+# (script, executable, binary, etc.) named 'pre-revprop-change' (for which
+# this file is a template), with the following ordered arguments:
+#
+# [1] REPOS-PATH (the path to this repository)
+# [2] REVISION (the revision being tweaked)
+# [3] USER (the username of the person tweaking the property)
+# [4] PROPNAME (the property being set on the revision)
+#
+# [STDIN] PROPVAL ** the property value is passed via STDIN.
+#
+# If the hook program exits with success, the propchange happens; but
+# if it exits with failure (non-zero), the propchange doesn't happen.
+# The hook program can use the 'svnlook' utility to examine the
+# existing value of the revision property.
+#
+# WARNING: unlike other hooks, this hook MUST exist for revision
+# properties to be changed. If the hook does not exist, Subversion
+# will behave as if the hook were present, but failed. The reason
+# for this is that revision properties are UNVERSIONED, meaning that
+# a successful propchange is destructive; the old value is gone
+# forever. We recommend the hook back up the old value somewhere.
+#
+# On a Unix system, the normal procedure is to have 'pre-revprop-change'
+# invoke other programs to do the real work, though it may do the
+# work itself too.
+#
+# Note that 'pre-revprop-change' must be executable by the user(s) who will
+# invoke it (typically the user httpd runs as), and that user must
+# have filesystem-level permission to access the repository.
+#
+# On a Windows system, you should name the hook program
+# 'pre-revprop-change.bat' or 'pre-revprop-change.exe',
+# but the basic idea is the same.
+#
+# Here is an example hook script, for a Unix /bin/sh interpreter:
+
+REPOS="$1"
+REV="$2"
+USER="$3"
+PROPNAME="$4"
+
+if [ "$PROPNAME" = "svn:log" ]; then exit 0; fi
+exit 1
Property changes on: scripts/svn-hooks/pre-revprop-change
___________________________________________________________________
Name: svn:executable
+ *
Added: scripts/svn-hooks/propchange-email.pl
===================================================================
--- scripts/svn-hooks/propchange-email.pl 2004-11-07 21:19:52 UTC (rev 206)
+++ scripts/svn-hooks/propchange-email.pl 2004-11-07 21:22:50 UTC (rev 207)
@@ -0,0 +1,458 @@
+#!/usr/bin/perl -w
+
+# ====================================================================
+# propchange-email.pl: send a commit email containing the new value of
+# revision property PROPNAME in revision REV of repository REPOS to
+# some email addresses.
+#
+# For usage, see the usage subroutine or run the script with no
+# command line arguments.
+#
+# $HeadURL: http://svn.collab.net/repos/svn/branches/release-0.31.0/tools/hook-scripts/propchange-email.pl.in $
+# $LastChangedDate: 2003-08-01 13:25:14 -0400 (Fri, 01 Aug 2003) $
+# $LastChangedBy: kfogel $
+# $LastChangedRevision: 6626 $
+#
+# ====================================================================
+# Copyright (c) 2000-2003 CollabNet. All rights reserved.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at http://subversion.tigris.org/license-1.html.
+# If newer versions of this license are posted there, you may use a
+# newer version instead, at your option.
+#
+# This software consists of voluntary contributions made by many
+# individuals. For exact contribution history, see the revision
+# history and logs, available at http://subversion.tigris.org/.
+# ====================================================================
+
+use strict;
+use Carp;
+use Cwd 'abs_path';
+
+######################################################################
+# Configuration section.
+
+# Sendmail path.
+my $sendmail = "/usr/sbin/sendmail";
+
+# Svnlook path.
+my $svnlook = "/usr/bin/svnlook";
+
+# Svn path.
+my $svn = "/usr/bin/svn";
+
+# Since the path to svn depends upon the local installation
+# preferences, check that the required programs exist to insure that
+# the administrator has set up the script properly.
+{
+ my $ok = 1;
+ foreach my $program ($sendmail, $svnlook, $svn)
+ {
+ if (-e $program)
+ {
+ unless (-x $program)
+ {
+ warn "$0: required program `$program' is not executable, ",
+ "edit $0.\n";
+ $ok = 0;
+ }
+ }
+ else
+ {
+ warn "$0: required program `$program' does not exist, edit $0.\n";
+ $ok = 0;
+ }
+ }
+ exit 1 unless $ok;
+}
+
+
+######################################################################
+# Initial setup/command-line handling.
+
+# Each value in this array holds a hash reference which contains the
+# associated email information for one project. Start with an
+# implicit rule that matches all paths.
+my @project_settings_list = (&new_project);
+
+# Process the command line arguments till there are none left. The
+# first three arguments that are not used by a command line option are
+# the repository path, the revision number, and the property name.
+my $repos;
+my $rev;
+my $author;
+my $propname;
+
+# Use the reference to the first project to populate.
+my $current_project = $project_settings_list[0];
+
+# This hash matches the command line option to the hash key in the
+# project. If a key exists but has a false value (''), then the
+# command line option is allowed but requires special handling.
+my %opt_to_hash_key = ('--from' => 'from_address',
+ '-h' => 'hostname',
+ '-l' => 'log_file',
+ '-m' => '',
+ '-r' => 'reply_to',
+ '-s' => 'subject_prefix');
+
+while (@ARGV)
+ {
+ my $arg = shift @ARGV;
+ if ($arg =~ /^-/)
+ {
+ my $hash_key = $opt_to_hash_key{$arg};
+ unless (defined $hash_key)
+ {
+ die "$0: command line option `$arg' is not recognized.\n";
+ }
+
+ unless (@ARGV)
+ {
+ die "$0: command line option `$arg' is missing a value.\n";
+ }
+ my $value = shift @ARGV;
+
+ if ($hash_key)
+ {
+ $current_project->{$hash_key} = $value;
+ }
+ else
+ {
+ # Here handle -m.
+ unless ($arg eq '-m')
+ {
+ die "$0: internal error: should only handle -m here.\n";
+ }
+ $current_project = &new_project;
+ $current_project->{match_regex} = $value;
+ push(@project_settings_list, $current_project);
+ }
+ }
+ elsif ($arg =~ /^-/)
+ {
+ die "$0: command line option `$arg' is not recognized.\n";
+ }
+ else
+ {
+ if (! defined $repos)
+ {
+ $repos = $arg;
+ }
+ elsif (! defined $rev)
+ {
+ $rev = $arg;
+ }
+ elsif (! defined $author)
+ {
+ $author = $arg;
+ }
+ elsif (! defined $propname)
+ {
+ $propname = $arg;
+ }
+ else
+ {
+ push(@{$current_project->{email_addresses}}, $arg);
+ }
+ }
+ }
+
+# If the property name is undefined, then there were not enough
+# command line arguments.
+&usage("$0: too few arguments.") unless defined $propname;
+
+# Check the validity of the command line arguments. Check that the
+# revision is an integer greater than 0 and that the repository
+# directory exists.
+unless ($rev =~ /^\d+/ and $rev > 0)
+ {
+ &usage("$0: revision number `$rev' must be an integer > 0.");
+ }
+unless (-e $repos)
+ {
+ &usage("$0: repos directory `$repos' does not exist.");
+ }
+unless (-d _)
+ {
+ &usage("$0: repos directory `$repos' is not a directory.");
+ }
+
+# Check that all of the regular expressions can be compiled and
+# compile them.
+{
+ my $ok = 1;
+ for (my $i=0; $i<@project_settings_list; ++$i)
+ {
+ my $match_regex = $project_settings_list[$i]->{match_regex};
+
+ # To help users that automatically write regular expressions
+ # that match the root directory using ^/, remove the / character
+ # because subversion paths, while they start at the root level,
+ # do not begin with a /.
+ $match_regex =~ s#^\^/#^#;
+
+ my $match_re;
+ eval { $match_re = qr/$match_regex/ };
+ if ($@)
+ {
+ warn "$0: -m regex #$i `$match_regex' does not compile:\n$@\n";
+ $ok = 0;
+ next;
+ }
+ $project_settings_list[$i]->{match_re} = $match_re;
+ }
+ exit 1 unless $ok;
+}
+
+######################################################################
+# Harvest data using svn.
+
+# Get the new property value svn.
+my $repos_url = 'file://' . &abs_path($repos);
+my @svnlines = &read_from_process($svn, 'propget', '--revprop', '-r', $rev,
+ $propname, $repos_url);
+
+# Figure out what directories have changed using svnlook. This is
+# merely so we can determine what project might care about receiving
+# this log.
+my @dirschanged = &read_from_process($svnlook, 'dirs-changed', $repos,
+ '-r', $rev);
+
+######################################################################
+# Assembly of log message.
+
+# Put together the body of the log message.
+my @body;
+push(@body, "Author: $author\n");
+push(@body, "Revision: $rev\n");
+push(@body, "Property Name: $propname\n");
+push(@body, "\n");
+push(@body, "New Property Value:\n");
+push(@body, map { /[\r\n]+$/ ? $_ : "$_\n" } @svnlines);
+push(@body, "\n");
+
+# Go through each project and see if there are any matches for this
+# project. If so, send the log out.
+foreach my $project (@project_settings_list)
+ {
+ my $match_re = $project->{match_re};
+ my $match = 0;
+ foreach my $path (@dirschanged)
+ {
+ if ($path =~ $match_re)
+ {
+ $match = 1;
+ last;
+ }
+ }
+
+ next unless $match;
+
+ my @email_addresses = @{$project->{email_addresses}};
+ my $userlist = join(' ', @email_addresses);
+ my $from_address = $project->{from_address};
+ my $hostname = $project->{hostname};
+ my $log_file = $project->{log_file};
+ my $reply_to = $project->{reply_to};
+ my $subject_prefix = $project->{subject_prefix};
+ my $subject;
+
+ $subject = "propchange - rev $rev - $propname";
+ if ($subject_prefix =~ /\w/)
+ {
+ $subject = "$subject_prefix $subject";
+ }
+ my $mail_from = $author;
+
+ if ($from_address =~ /\w/)
+ {
+ $mail_from = $from_address;
+ }
+ elsif ($hostname =~ /\w/)
+ {
+ $mail_from = "$mail_from\@$hostname";
+ }
+
+ my @head;
+ push(@head, "To: $userlist\n");
+ push(@head, "From: $mail_from\n");
+ push(@head, "Subject: $subject\n");
+ push(@head, "Reply-to: $reply_to\n") if $reply_to;
+
+ ### Below, we set the content-type etc, but see these comments
+ ### from Greg Stein on why this is not a full solution.
+ #
+ # From: Greg Stein <gstein@lyra.org>
+ # Subject: Re: svn commit: rev 2599 - trunk/tools/cgi
+ # To: dev@subversion.tigris.org
+ # Date: Fri, 19 Jul 2002 23:42:32 -0700
+ #
+ # Well... that isn't strictly true. The contents of the files
+ # might not be UTF-8, so the "diff" portion will be hosed.
+ #
+ # If you want a truly "proper" commit message, then you'd use
+ # multipart MIME messages, with each file going into its own part,
+ # and labeled with an appropriate MIME type and charset. Of
+ # course, we haven't defined a charset property yet, but no biggy.
+ #
+ # Going with multipart will surely throw out the notion of "cut
+ # out the patch from the email and apply." But then again: the
+ # commit emailer could see that all portions are in the same
+ # charset and skip the multipart thang.
+ #
+ # etc etc
+ #
+ # Basically: adding/tweaking the content-type is nice, but don't
+ # think that is the proper solution.
+ push(@head, "Content-Type: text/plain; charset=UTF-8\n");
+ push(@head, "Content-Transfer-Encoding: 8bit\n");
+
+ push(@head, "\n");
+
+ if ($sendmail =~ /\w/ and @email_addresses)
+ {
+ # Open a pipe to sendmail.
+ my $command = "$sendmail $userlist";
+ if (open(SENDMAIL, "| $command"))
+ {
+ print SENDMAIL @head, @body;
+ close SENDMAIL
+ or warn "$0: error in closing `$command' for writing: $!\n";
+ }
+ else
+ {
+ warn "$0: cannot open `| $command' for writing: $!\n";
+ }
+ }
+
+ # Dump the output to logfile (if its name is not empty).
+ if ($log_file =~ /\w/)
+ {
+ if (open(LOGFILE, ">> $log_file"))
+ {
+ print LOGFILE @head, @body;
+ close LOGFILE
+ or warn "$0: error in closing `$log_file' for appending: $!\n";
+ }
+ else
+ {
+ warn "$0: cannot open `$log_file' for appending: $!\n";
+ }
+ }
+ }
+
+exit 0;
+
+sub usage
+{
+ warn "@_\n" if @_;
+ die "usage: $0 REPOS REVNUM USER PROPNAME [[-m regex] [options] [email_addr ...]] ...\n",
+ "options are\n",
+ " --from email_address Email address for 'From:' (overrides -h)\n",
+ " -h hostname Hostname to append to author for 'From:'\n",
+ " -l logfile Append mail contents to this log file\n",
+ " -m regex Regular expression to match committed path\n",
+ " -r email_address Email address for 'Reply-To:'\n",
+ " -s subject_prefix Subject line prefix\n",
+ "\n",
+ "This script supports a single repository with multiple projects,\n",
+ "where each project receives email only for changes to properties\n",
+ "in revisions which otherwise modified that project. A project is\n",
+ "identified by using the -m command line with a regular expression\n",
+ "argument. If the given revision contained modifications to a path that\n",
+ "matches the regular expression, then the entire revision matches.\n",
+ "Any of the following -h, -l, -r and -s command line options and\n",
+ "following email addresses are associated with this project. The\n",
+ "next -m resets the -h, -l, -r and -s command line options and the\n",
+ "list of email addresses.\n",
+ "\n",
+ "To support a single project conveniently, the script initializes\n",
+ "itself with an implicit -m . rule that matches any modifications\n",
+ "to the repository. Therefore, to use the script for a single\n",
+ "project repository, just use the other comand line options and\n",
+ "a list of email addresses on the command line. If you do not want\n",
+ "a project that matches the entire repository, then use a -m with a\n",
+ "regular expression before any other command line options or email\n",
+ "addresses.\n";
+}
+
+# Return a new hash data structure for a new empty project that
+# matches any modifications to the repository.
+sub new_project
+{
+ return {email_addresses => [],
+ from_address => '',
+ hostname => '',
+ log_file => '',
+ match_regex => '.',
+ reply_to => '',
+ subject_prefix => ''};
+}
+
+# Start a child process safely without using /bin/sh.
+sub safe_read_from_pipe
+{
+ unless (@_)
+ {
+ croak "$0: safe_read_from_pipe passed no arguments.\n";
+ }
+
+ my $pid = open(SAFE_READ, '-|');
+ unless (defined $pid)
+ {
+ die "$0: cannot fork: $!\n";
+ }
+ unless ($pid)
+ {
+ open(STDERR, ">&STDOUT")
+ or die "$0: cannot dup STDOUT: $!\n";
+ exec(@_)
+ or die "$0: cannot exec `@_': $!\n";
+ }
+ my @output;
+ while (<SAFE_READ>)
+ {
+ s/[\r\n]+$//;
+ push(@output, $_);
+ }
+ close(SAFE_READ);
+ my $result = $?;
+ my $exit = $result >> 8;
+ my $signal = $result & 127;
+ my $cd = $result & 128 ? "with core dump" : "";
+ if ($signal or $cd)
+ {
+ warn "$0: pipe from `@_' failed $cd: exit=$exit signal=$signal\n";
+ }
+ if (wantarray)
+ {
+ return ($result, @output);
+ }
+ else
+ {
+ return $result;
+ }
+}
+
+# Use safe_read_from_pipe to start a child process safely and return
+# the output if it succeeded or an error message followed by the output
+# if it failed.
+sub read_from_process
+{
+ unless (@_)
+ {
+ croak "$0: read_from_process passed no arguments.\n";
+ }
+ my ($status, @output) = &safe_read_from_pipe(@_);
+ if ($status)
+ {
+ return ("$0: `@_' failed with this output:", @output);
+ }
+ else
+ {
+ return @output;
+ }
+}
Property changes on: scripts/svn-hooks/propchange-email.pl
___________________________________________________________________
Name: svn:executable
+ *
Added: scripts/svn-hooks/start-commit
===================================================================
--- scripts/svn-hooks/start-commit 2004-11-07 21:19:52 UTC (rev 206)
+++ scripts/svn-hooks/start-commit 2004-11-07 21:22:50 UTC (rev 207)
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+# START-COMMIT HOOK
+#
+# The start-commit hook is invoked before a Subversion txn is created
+# in the process of doing a commit. Subversion runs this hook
+# by invoking a program (script, executable, binary, etc.) named
+# 'start-commit' (for which this file is a template)
+# with the following ordered arguments:
+#
+# [1] REPOS-PATH (the path to this repository)
+# [2] USER (the authenticated user attempting to commit)
+#
+# If the hook program exits with success, the commit continues; but
+# if it exits with failure (non-zero), the commit is stopped before
+# even a Subversion txn is created.
+#
+# On a Unix system, the normal procedure is to have 'start-commit'
+# invoke other programs to do the real work, though it may do the
+# work itself too.
+#
+# Note that 'start-commit' must be executable by the user(s) who will
+# invoke it (typically the user httpd runs as), and that user must
+# have filesystem-level permission to access the repository.
+#
+# On a Windows system, you should name the hook program
+# 'start-commit.bat' or 'start-commit.exe',
+# but the basic idea is the same.
+#
+# Here is an example hook script, for a Unix /bin/sh interpreter:
+
+REPOS="$1"
+USER="$2"
+
+# CHRIS CHENEY - NONEXISTANT SCRIPT
+#commit-allower.pl --repository "$REPOS" --user "$USER" || exit 1
+#special-auth-check.py --user "$USER" --auth-level 3 || exit 1
+
+# All checks passed, so allow the commit.
+exit 0
Property changes on: scripts/svn-hooks/start-commit
___________________________________________________________________
Name: svn:executable
+ *
Reply to: