[svk-commit] r2174 - in trunk: lib/SVK t
clkao at bestpractical.com
clkao at bestpractical.com
Sat Nov 18 15:52:42 EST 2006
Author: clkao
Date: Sat Nov 18 15:52:42 2006
New Revision: 2174
Modified:
trunk/lib/SVK/Command.pm
trunk/lib/SVK/Command/Info.pm
trunk/lib/SVK/Command/List.pm
trunk/lib/SVK/Command/Propget.pm
trunk/t/32list.t
Log:
Move error and pool handling into run_command_recursively
Modified: trunk/lib/SVK/Command.pm
==============================================================================
--- trunk/lib/SVK/Command.pm (original)
+++ trunk/lib/SVK/Command.pm Sat Nov 18 15:52:42 2006
@@ -1015,16 +1015,29 @@
=cut
+sub _run_code {
+ my ($self, $target, $code, $level, $errs, $kind) = @_;
+ eval { $code->( $target, $kind, $level ) };
+ if ($@) {
+ print $@;
+ push @$errs, "$@";
+ }
+}
+
sub run_command_recursively {
- my ($self, $target, $code, $level) = @_;
+ my ( $self, $target, $code, $errs, $newline, $level ) = @_;
my $root = $target->root;
- my $kind = $root->check_path($target->path_anchor);
- $code->($target, $kind, -1);
- $self->_descend_with($target, $code, 1) if $kind == $SVN::Node::dir && $self->{recursive} && (!$self->{depth} || 0 < $self->{depth});
+ my $kind = $root->check_path( $target->path_anchor );
+ $self->_run_code($target, $code, -1, $errs, $kind);
+ $self->_descend_with( $target, $code, $errs, 1 )
+ if $kind == $SVN::Node::dir
+ && $self->{recursive}
+ && ( !$self->{depth} || 0 < $self->{depth} );
+ print "\n" if $newline;
}
sub _descend_with {
- my ($self, $target, $code, $level) = @_;
+ my ($self, $target, $code, $errs, $level) = @_;
my $root = $target->root;
my $entries = $root->dir_entries ($target->path_anchor);
my $pool = SVN::Pool->new_default;
@@ -1033,11 +1046,11 @@
my $kind = $entries->{$_}->kind;
next if $kind == $SVN::Node::unknown;
my $child = $target->new->descend($_);
- $code->($child, $kind, $level);
+ $self->_run_code($child, $code, $level, $errs, $kind);
my $isdir = ($kind == $SVN::Node::dir);
- if ($isdir && $self->{recursive} && (!$self->{'depth'} || ( $level < $self->{'depth'}))) {
- $self->_descend_with($child, $code, $level+1);
+ if ($isdir && $self->{recursive} && (!$self->{'depth'} || ( $level < $self->{'depth'}))) {
+ $self->_descend_with($child, $code, $errs, $level+1);
}
}
}
Modified: trunk/lib/SVK/Command/Info.pm
==============================================================================
--- trunk/lib/SVK/Command/Info.pm (original)
+++ trunk/lib/SVK/Command/Info.pm Sat Nov 18 15:52:42 2006
@@ -20,22 +20,17 @@
}
sub run {
- my ($self, @arg) = @_;
- my $exception='';
- my $pool = SVN::Pool->new_default;
+ my ( $self, @arg ) = @_;
+ my $exception = '';
+ my $errs = [];
$self->run_command_recursively(
$_,
sub {
- $pool->clear;
- eval { $self->_do_info( $_[0] ) };
- if ($@) {
- $exception .= "$@";
- $exception .= "\n" unless $exception =~ m/\n$/;
- next;
- }
- }
+ $self->_do_info( $_[0] );
+ }, $errs, $#arg,
) for @arg;
- die($exception) if($exception);
+
+ return scalar @$errs;
}
sub _do_info {
Modified: trunk/lib/SVK/Command/List.pm
==============================================================================
--- trunk/lib/SVK/Command/List.pm (original)
+++ trunk/lib/SVK/Command/List.pm Sat Nov 18 15:52:42 2006
@@ -26,35 +26,27 @@
my $exception = '';
my $enc = get_encoder;
- if ($self->{recursive}) {
- $self->{depth}++ if $self->{depth};
- }
- else {
+ if ( $self->{recursive} ) {
+ $self->{depth}++ if $self->{depth};
+ } else {
$self->{recursive}++;
$self->{depth} = 1;
}
- while ( my $arg = shift @arg ) {
- $arg = $arg->as_depotpath;
- eval {
- $self->run_command_recursively(
- $self->apply_revision($arg),
- sub {
- my ( $target, $kind, $level ) = @_;
- if ( $level == -1 ) {
- return if $kind == $SVN::Node::dir;
- die loc( "Path %1 is not versioned.\n",
- $target->path_anchor )
- unless $kind == $SVN::Node::file;
- }
- $self->_print_item( $target, $kind, $level, $enc );
- }
- );
- print "\n" if @arg;
- };
- $exception .= "$@" if $@;
- }
+ my $errs = [];
+ $self->run_command_recursively(
+ $self->apply_revision($_),
+ sub {
+ my ( $target, $kind, $level ) = @_;
+ if ( $level == -1 ) {
+ return if $kind == $SVN::Node::dir;
+ die loc( "Path %1 is not versioned.\n", $target->path_anchor )
+ unless $kind == $SVN::Node::file;
+ }
+ $self->_print_item( $target, $kind, $level, $enc );
+ }, $errs, $#arg
+ ) for map { $_->as_depotpath } @arg;
- die($exception) if($exception);
+ return scalar @$errs;
}
sub _print_item {
Modified: trunk/lib/SVK/Command/Propget.pm
==============================================================================
--- trunk/lib/SVK/Command/Propget.pm (original)
+++ trunk/lib/SVK/Command/Propget.pm Sat Nov 18 15:52:42 2006
@@ -23,6 +23,7 @@
sub run {
my ( $self, $pname, @targets ) = @_;
+ my $errs = [];
$self->run_command_recursively(
$_,
sub {
@@ -34,10 +35,10 @@
if !$self->{strict} && ( $self->{recursive} || @targets > 1 );
print $proplist->{$pname};
print "\n" if !$self->{strict};
- }
+ }, $errs, 0,
) for @targets;
- return;
+ return scalar @$errs;
}
1;
Modified: trunk/t/32list.t
==============================================================================
--- trunk/t/32list.t (original)
+++ trunk/t/32list.t Sat Nov 18 15:52:42 2006
@@ -37,10 +37,10 @@
is_output ($svk, 'ls', ['-f',"/$depot/crap/"], ['Path /crap is not versioned.']);
ok ($svk->ls ('-f', "/$depot/crap/") == 1, "ls -f /$depot/crap/ [exit status]");
is_output ($svk, 'ls', ['-f',"/$depot/", "/$depot/A"],
- ["/$depot/A/", '', "/$depot/A/B/","/$depot/A/foo"]);
+ ["/$depot/A/", '', "/$depot/A/B/","/$depot/A/foo", '']);
ok ($svk->ls ('-f', "/$depot/", "/$depot/A") == 0, "ls -f /$depot/ /$depot/A [exit status]");
is_output ($svk, 'ls', ['-f',"/$depot/A", "/$depot/crap/"],
- ["/$depot/A/B/","/$depot/A/foo", '', 'Path /crap is not versioned.']);
+ ["/$depot/A/B/","/$depot/A/foo", '', 'Path /crap is not versioned.', '']);
ok ($svk->ls ('-f', "/$depot/A", "/$depot/crap/") == 1, "ls -f /$depot/A /$depot/crap/ [exit status]");
use POSIX qw( strftime );
@@ -85,13 +85,13 @@
[qr" 2 $re_user $re_date /$depot/A/",
'',
qr" 2 $re_user $re_date /$depot/A/B/",
- qr" 1 $re_user $size $re_date /$depot/A/foo"]);
+ qr" 1 $re_user $size $re_date /$depot/A/foo", '']);
ok ($svk->ls ('-v', '-f', "/$depot/", "/$depot/A") == 0, "ls -v -f /$depot/ /$depot/A [exit status]");
is_output ($svk, 'ls', ['-v', '-f', "/$depot/A/", "/$depot/crap/"],
[qr" 2 $re_user $re_date /$depot/A/B/",
qr" 1 $re_user $size $re_date /$depot/A/foo",
'',
- 'Path /crap is not versioned.']);
+ 'Path /crap is not versioned.', '']);
ok ($svk->ls ('-v', '-f', "/$depot/A", "/$depot/crap/") == 1, "ls -f /$depot/A /$depot/crap/ [exit status]");
chdir("..");
More information about the svk-commit
mailing list