[Bps-public-commit] r9034 - in SVN-Hook/lib/SVN: Hook
clkao at bestpractical.com
clkao at bestpractical.com
Thu Sep 13 09:50:47 EDT 2007
Author: clkao
Date: Thu Sep 13 09:50:46 2007
New Revision: 9034
Modified:
SVN-Hook/lib/SVN/Hook.pm
SVN-Hook/lib/SVN/Hook/Redispatch.pm
Log:
Make the entry hook use redispatch as well.
Modified: SVN-Hook/lib/SVN/Hook.pm
==============================================================================
--- SVN-Hook/lib/SVN/Hook.pm (original)
+++ SVN-Hook/lib/SVN/Hook.pm Thu Sep 13 09:50:46 2007
@@ -62,7 +62,16 @@
die "There is already $hook file.\n" if -e $path;
$self->_install_perl_hook( $path, <<"EOF");
-# DO NOT EDIT. generated by svnhook version $VERSION.
+# Generated by svnhook version $VERSION.
+# This $hook hook is managed by svnook.
+
+use SVN::Hook::Redispatch {
+ '' => '',
+# Add other dispatch mapping here:
+# 'foo' => 'bar'
+# will run scripts under _$hook/bar/ when commit are solely within foo.
+}, \@ARGV;
+exit 0;
use SVN::Hook::CLI; SVN::Hook::CLI->_run("$hook", \@ARGV);
EOF
Modified: SVN-Hook/lib/SVN/Hook/Redispatch.pm
==============================================================================
--- SVN-Hook/lib/SVN/Hook/Redispatch.pm (original)
+++ SVN-Hook/lib/SVN/Hook/Redispatch.pm Thu Sep 13 09:50:46 2007
@@ -1,36 +1,55 @@
package SVN::Hook::Redispatch;
use strict;
-use Data::Dumper;
use Path::Class;
use SVN::Hook;
sub import {
my $class = shift;
my $spec = shift;
+ return unless $spec;
- my $hook_base = Path::Class::File->new($0)->parent;
+ my $hook_base = Path::Class::File->new($0);
my $type;
my $svnlook_arg;
- if ($hook_base =~ m/pre-commit$/) {
- $type = 'pre-commit';
+
+ if ($hook_base->parent =~ m'hooks$') { # the hook file itself
+ my $type = $hook_base->basename;
+ $hook_base = $hook_base->parent->subdir("_".$type);
+ }
+ else {
+ $hook_base = $hook_base->parent;
+ $type = $hook_base;
+ $type =~ s{^.*/_}{};
+ }
+
+ # if we are able to pull out the toplevel path
+ if ($type eq 'pre-commit') {
$svnlook_arg = "-t $_[1]";
}
- elsif ($hook_base =~ m/post-commit$/) {
- $type = 'post-commit';
+ elsif ($type eq 'post-commit') {
$svnlook_arg = "-r $_[1]";
}
else {
- die "not yet";
}
+ my $ignore_error = $type =~ m/^post-/? 1 : 0;
+
+ if (defined (my $dir = delete $spec->{''})) { # global ones
+ my @scripts = SVN::Hook::Script->load_from_dir
+ ( $hook_base.'/'.$dir );
+ SVN::Hook->run_scripts( \@scripts, $ignore_error, @_ );
+ }
+
+ return unless $svnlook_arg;
+
my $toplevel = $class->find_toplevel_change($_[0], $svnlook_arg);
for (map { Path::Class::Dir->new_foreign('Unix', $_) } sort keys %$spec) {
next unless $_ eq $toplevel || $_->subsumes($toplevel);
my @scripts = SVN::Hook::Script->load_from_dir
( $hook_base.'/'.$spec->{$_} );
- SVN::Hook->run_scripts( \@scripts, 0, @_ );
+ SVN::Hook->run_scripts( \@scripts, $ignore_error, @_ );
}
};
More information about the Bps-public-commit
mailing list