+
Index: tools/hook-scripts/commit-html.pl.in
===================================================================
--- tools/hook-scripts/commit-html.pl.in (Revision 0)
+++ tools/hook-scripts/commit-html.pl.in (Revision 0)
@@ -0,0 +1,745 @@
+#!/usr/bin/env perl
+
+# ====================================================================
+# commit-html.pl: Create html pages that describe commits. (windows
version)
+#
+# For usage, see the usage subroutine or run the script with no
+# command line arguments.
+#
+# This file can be called using a post-commit.bat file like the following
in the
+# hooks directory of any repository:
+
+# d:
+# cd "\Programme\Repositories\golgotha\hooks"
+# set... (here, paste the output of set of a dos shell and prepend every
line with "set".
+# This causes the environment to be restored to normal, and maybe a little
less trouble executing
+# the following script (environment is empty at this point as described in
the documentation)
+# c:\cygwin\bin\perl
/cygdrive/d/Programme/Repositories/golgotha/hooks/commit-html.pl
"D:\Programme\Repositories\golgotha" %2 2>>commits.log
+# echo Repository %1 revision %2 documented>>commits.log
+
+
+#
+# $HeadURL:
http://svn.collab.net/repos/svn/trunk/tools/hook-scripts/commit-email.pl.in
$
+# $LastChangedDate: 2005-02-22 10:24:08 +0100 (Di, 22 Feb 2005) $
+# $LastChangedBy: maxb $
+# $LastChangedRevision: 13107 $
+#
+# ====================================================================
+# Copyright (c) 2000-2004 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/.
+# ====================================================================
+
+# Turn on warnings the best way depending on the Perl version.
+BEGIN {
+ if ( $] >= 5.006_000)
+ { require warnings; import warnings; }
+ else
+ { $^W = 1; }
+}
+
+use strict;
+use Carp;
+
+######################################################################
+# Configuration section.
+# Hint: Altough this script is primarly designed to run under windows,
+# I run it using cygwin perl, therefore all paths look unix-like.
+# To get even more confused, svnlook is a windows binary, so the Revision
argument
+# passed to this script should be a windows pathname (starting with C:\ or
so)
+
+# Sendmail path.
+my $sendmail = "/usr/sbin/sendmail";
+
+#unix2dos, perhaps required to clean up the output html
+my $unix2dos = "/usr/bin/unix2dos.exe";
+
+# Svnlook path.
+my $svnlook = "/cygdrive/d/Programme/Subversion/bin/svnlook.exe";
+
+# The output path. To be most usefull, this should point somewhere within
reach of the webserver,
+# for instance a subdirectory of the Apache2/htdocs folder. The folder must
exist.
+my $outputdir = "/cygdrive/d/Programme/Apache
Group/Apache2/htdocs/commits/";
+
+# If a diff gives more lines than this, we don't print added or removed
file's contents.
+# (Implicit $no_diff_deleted and $no_diff_added from bellow, because files
would be to large)
+my $maxlines=10000;
+
+# These two documents are used as the head and the tail of the resulting
html.
+# Any occurences of REPOSITORY or REVISION (all caps) will be replaced by
the repository name
+# or the revision number. Since the document body won't be formated on it's
own, the head should
+# end with and the tail should start with
or you'll notice
that the output html won't
+# be very readable.
+my $htmltemplatehead = "head.html.tmpl";
+my $htmltemplatetail = "tail.html.tmpl";
+my $htmltemplateindexhead = "indexhead.html.tmpl";
+my $htmltemplateindextail = "tail.html.tmpl"; #in my case, same as above
+# Name of the index document to be created.
+my $indexname = "index.html";
+
+# 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 = 1;
+# By default, when a file is added to 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_added to 1.
+my $no_diff_added = 0;
+
+# End of Configuration section.
+######################################################################
+
+# 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 ($unix2dos, $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;
+ }
+ }
+ #don't really test this, for some strange reason, the test won't work on
windows when executed
+ #by apache (as LocalSystem user), but the execution itself works
flawlessly.
+ #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];
+
+my $startrev;
+
+
+# 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 = ('-h' => 'hostname',
+ '-m' => '',
+ '-s' => 'subject_prefix',
+ '-startrev' => '');
+
+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;
+ }
+ elsif ($arg eq '-startrev')
+ {
+ $startrev=$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.");
+ }
+
+if (! defined $startrev)
+{
+ $startrev=$rev;
+}
+unless ($startrev =~ /^\d+/ and $rev > 0)
+ {
+ &usage("$0: revision number `$startrev' must be an integer > 0.");
+ }
+
+# 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 suitable directory so that svnlook diff can create its
.svnlook
+# directory. This could be removed - it's only for compatibility with
+# 1.0.x svnlook - from 1.1.0, svnlook will be sensible about choosing a
+# temporary directory all by itself.
+# my $tmp_dir = ( -d $ENV{'TEMP'} ? $ENV{'TEMP'} : '/tmp' );
+# chdir($tmp_dir)
+# or die "$0: cannot chdir `$tmp_dir': $!\n";
+
+my $repository_name=$repos;
+$repository_name=~ s/\\.*\\//g;
+$repository_name=~ s/.://;
+
+
+my $rev_inuse;
+
+for ($rev_inuse=$startrev; $rev_inuse<=$rev;$rev_inuse++)
+{
+
+ my @htmlhead;
+ my @htmltail;
+ open (HTMLHEADFILE,"<$htmltemplatehead") or die("$0: cannot open
$htmltemplatehead. $!\n");
+ @htmlhead = ;
+ close HTMLHEADFILE;
+
+
+ foreach my $htmlline( @htmlhead)
+ {
+ $htmlline =~s/REVISION/$rev_inuse/g;
+ $htmlline =~s/REPOSITORY/$repository_name/g;
+ }
+
+
+ open (HTMLTAILFILE,"<$htmltemplatetail") or die("$0: cannot open
$htmltemplatetail. $!\n");
+ @htmltail=;
+ close HTMLTAILFILE;
+
+ foreach my $htmltailline( @htmltail)
+ {
+ $htmltailline =~s/REVISION/$rev_inuse/g;
+ $htmltailline =~s/REPOSITORY/$repository_name/g;
+ }
+
+
+# Get the author, date, and log from svnlook.
+my @svnlooklines = &read_from_process($svnlook, 'info', $repos, '-r',
$rev_inuse);
+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_inuse);
+
+# 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_inuse);
+
+# 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 @no_diff_added = $no_diff_added ? ('--no-diff-added') : ();
+my @difflines = &read_from_process($svnlook, 'diff', $repos,
+ '-r', $rev_inuse, @no_diff_deleted,
+ @no_diff_added);
+
+if (scalar(@difflines)>$maxlines)
+{
+ @difflines = &read_from_process($svnlook, 'diff', $repos,
+ '-r', $rev_inuse,"--no-diff-deleted",
+ "--no-diff-added");
+}
+
+######################################################################
+# 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 = '';
+my @dirschanged_orig = @dirschanged;
+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#^\Q$commondir/\E##;
+ }
+ 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;
+my $outputfile;
+$outputfile=join("",("$outputdir","rev","$rev_inuse",".html"));
+push(@body, "Author: $author\n");
+push(@body, "Date: $date\n");
+push(@body, "New Revision: $rev_inuse\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_orig, @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 $to = 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 = "r$rev_inuse - in $commondir: $dirlist";
+ }
+ else
+ {
+ $subject = "r$rev_inuse - $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, "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
+ # 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 -f$mail_from $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";
+ # }
+ # }
+
+
+
+ warn "Writing $outputfile \n";
+ if (open(OUTPUTFILE, "> $outputfile"))
+ {
+ print OUTPUTFILE @htmlhead, @head, @body, @htmltail;
+ close OUTPUTFILE
+ or warn "$0: error in closing `$outputfile' for writting: $!\n";
+ #exec "$unix2dos \"$outputfile\"" or die ("$0: cannot execute
$unix2dos");
+ }
+ else
+ {
+ warn "$0: cannot open `$outputfile' for writing: $!\n";
+ }
+ }
+} #end of for each revision
+
+#now create the index document.
+my @htmlindexhead;
+my @htmlindextail;
+open (HTMLHEADFILE,"<$htmltemplateindexhead") or die("$0: cannot open
$htmltemplateindexhead. $!\n");
+@htmlindexhead = ;
+close HTMLHEADFILE;
+
+foreach my $htmlline( @htmlindexhead)
+{
+ $htmlline =~s/REVISION/$rev/g;
+ $htmlline =~s/REPOSITORY/$repository_name/g;
+}
+
+
+open (HTMLTAILFILE,"<$htmltemplateindextail") or die("$0: cannot open
$htmltemplateindextail. $!\n");
+@htmlindextail=;
+close HTMLTAILFILE;
+
+foreach my $htmltailline( @htmlindextail)
+{
+ $htmltailline =~s/REVISION/$rev/g;
+ $htmltailline =~s/REPOSITORY/$repository_name/g;
+}
+my $indexfile;
+$indexfile=join("",($outputdir,$indexname));
+my @indexdata;
+# Print out information about each revision in reverse order, such
+# that the youngest revision is on top of the page
+for (my $j=$rev;$j>=1 ;$j--)
+{
+ push(@indexdata,"");
+ my @svnlooklines = &read_from_process($svnlook, 'info', $repos, '-r', $j);
+ my $author = shift @svnlooklines;
+ my $date = shift @svnlooklines;
+ shift @svnlooklines;
+ my @log = map { "$_\n" } @svnlooklines;
+ push(@indexdata,join("",("","Revision ",$j," by $author on
$date
")));
+ push(@indexdata, @log);
+ push(@indexdata,"
\n");
+}
+unlink($indexfile)
+ or warn("$0: Could not delete $indexfile: $!\n");
+warn "Writing Index to $indexfile \n";
+ if (open(OUTPUTFILE, "> $indexfile"))
+ {
+ print OUTPUTFILE @htmlindexhead, @indexdata, @htmlindextail;
+ close OUTPUTFILE
+ or warn "$0: error in closing `$indexfile' for writting: $!\n";
+ #exec "$unix2dos \"$outputfile\"" or die ("$0: cannot execute
$unix2dos");
+ }
+ else
+ {
+ warn "$0: cannot open `$indexfile' for writing: $!\n";
+ }
+
+exit 0;
+
+sub usage
+{
+ warn "@_\n" if @_;
+ die "usage: $0 REPOS REVNUM [[-m regex] [options]]\n",
+ "options are\n",
+ " -h hostname Hostname to append to author for 'From:'\n",
+ " -m regex Regular expression to match committed
path\n",
+ " -s subject_prefix Subject line prefix\n",
+ " -startrev revision Create all html pages from revision rev to
REVNUM\n",
+ "\n",
+ "This script creates a list of html files that describe the changes
\n",
+ "in the repository in each revision. If -startrev is not passed, it
defaults \n",
+ "to REVNUM, which means that only the latest revision is checked. \n",
+ "This is usefull if the script runs within a post-commit hook.\n",
+ "The script also creates an index file which contains the logs \n",
+ "of each revision for quick lookup.\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 ()
+ {
+ 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;
+ }
+}