[Bps-public-commit] r9030 - in SVN-Hook: . bin lib/SVN/Hook
clkao at bestpractical.com
clkao at bestpractical.com
Thu Sep 13 08:01:11 EDT 2007
Author: clkao
Date: Thu Sep 13 08:01:02 2007
New Revision: 9030
Removed:
SVN-Hook/Makefile.old
Modified:
SVN-Hook/bin/svnhook
SVN-Hook/lib/SVN/Hook.pm
SVN-Hook/lib/SVN/Hook/CLI.pm
SVN-Hook/lib/SVN/Hook/Script.pm
Log:
minor refactoring.
Modified: SVN-Hook/bin/svnhook
==============================================================================
--- SVN-Hook/bin/svnhook (original)
+++ SVN-Hook/bin/svnhook Thu Sep 13 08:01:02 2007
@@ -1,3 +1,8 @@
#!/usr/bin/perl
use strict;
use warnings;
+use SVN::Hook::CLI;
+
+SVN::Hook::CLI->dispatch(@ARGV);
+
+1;
Modified: SVN-Hook/lib/SVN/Hook.pm
==============================================================================
--- SVN-Hook/lib/SVN/Hook.pm (original)
+++ SVN-Hook/lib/SVN/Hook.pm Thu Sep 13 08:01:02 2007
@@ -48,6 +48,14 @@
return Path::Class::Dir->new($self->repospath)->subdir('hooks')->file($hook);
}
+sub new {
+ my $class = shift;
+ my $self = $class->SUPER::new(@_);
+ die $self->repospath." is not a svn repository.\n"
+ unless -e catfile($self->repospath, 'format');
+ return $self;
+}
+
sub init {
my ($self, $hook) = @_;
my $path = $self->hook_path($hook);
@@ -56,7 +64,7 @@
my $perl = _this_perl();
print $fh <<"EOF";
#!$perl
-# DO NOT EDIT. generated by svnhook
+# DO NOT EDIT. generated by svnhook version $VERSION.
use SVN::Hook::CLI; SVN::Hook::CLI->_run("$hook", \@ARGV);
EOF
@@ -67,13 +75,35 @@
sub scripts {
my ( $self, $hook ) = @_;
- return map {
- SVN::Hook::Script->new(
- { hook => $self,
- path => Path::Class::File->new($_),
- enabled => (!m/-$/ && -x $_ )
- })
- } glob( $self->hook_path("_$hook/*") );
+ SVN::Hook::Script->load_from_dir($self->hook_path("_$hook"));
+}
+
+sub run_hook {
+ my $self = shift;
+ my $hook = shift;
+ my $ignore_error = $hook =~ m/^post-/? 1 : 0;
+
+ $self->run_scripts( [grep { $_->enabled } $self->scripts($hook)],
+ $ignore_error, @_ );
+}
+
+sub run_scripts {
+ my $self = shift;
+ my $scripts = shift;
+
+ my $ignore_error = shift;
+
+ for my $script (@$scripts) {
+ system($script->path, @_);
+
+ if ($? == -1) {
+ die "Failed to execute $_: $!.\n";
+ }
+ elsif ($?) {
+ exit ($? >> 8) unless $ignore_error;
+ }
+ }
+ return 0;
}
sub status {
Modified: SVN-Hook/lib/SVN/Hook/CLI.pm
==============================================================================
--- SVN-Hook/lib/SVN/Hook/CLI.pm (original)
+++ SVN-Hook/lib/SVN/Hook/CLI.pm Thu Sep 13 08:01:02 2007
@@ -25,19 +25,19 @@
my ($repospath) = @_;
my $h = SVN::Hook->new({repospath => $repospath});
- my $ignore_error = $hook =~ m/^post-/? 1 : 0;
- for my $script (grep { $_->enabled } $h->scripts($hook)) {
- system($script->path, @_);
+ $h->run_hook( $hook, @_ );
+}
- if ($? == -1) {
- die "Failed to execute $_: $!.\n";
- }
- elsif ($?) {
- exit ($? >> 8) unless $ignore_error;
- }
- }
- return 0;
+sub init {
+ my $class = shift;
+ my ($repospath, @hooks) = @_;
+
+ @hooks = SVN::Hook->ALL_HOOKS unless @hooks;
+
+ my $h = SVN::Hook->new({repospath => $repospath});
+ $h->init($_) for @hooks;
+ print "initialized.\n";
}
sub list {
Modified: SVN-Hook/lib/SVN/Hook/Script.pm
==============================================================================
--- SVN-Hook/lib/SVN/Hook/Script.pm (original)
+++ SVN-Hook/lib/SVN/Hook/Script.pm Thu Sep 13 08:01:02 2007
@@ -3,4 +3,21 @@
use base 'Class::Accessor::Fast';
__PACKAGE__->mk_accessors(qw(hook enabled path));
+use Path::Class;
+
+# returns an array of SVN::Hook::Script objects
+sub load_from_dir {
+ my $class = shift;
+ my $dir = shift;
+ my $hook = shift;
+
+ return map {
+ SVN::Hook::Script->new(
+ { hook => $hook,
+ path => Path::Class::File->new($_),
+ enabled => (!m/-$/ && -x $_ )
+ })
+ } grep { -f $_ } glob( "$dir/*" );
+}
+
1;
More information about the Bps-public-commit
mailing list