[svk-commit] r2167 - in trunk: lib/SVK t

clkao at bestpractical.com clkao at bestpractical.com
Sat Nov 18 01:54:37 EST 2006


Author: clkao
Date: Sat Nov 18 01:54:36 2006
New Revision: 2167

Modified:
   trunk/lib/SVK/Command.pm
   trunk/lib/SVK/Command/List.pm
   trunk/t/32list.t

Log:
Move run_command_recursively into SVK::Command.

Modified: trunk/lib/SVK/Command.pm
==============================================================================
--- trunk/lib/SVK/Command.pm	(original)
+++ trunk/lib/SVK/Command.pm	Sat Nov 18 01:54:36 2006
@@ -1008,6 +1008,40 @@
     return $path;
 }
 
+
+=head3 run_command_recursively($target, $code, [$level])
+
+Traverse C<$target> and and invoke C<$code> with each node.
+
+=cut
+
+sub run_command_recursively {
+    my ($self, $target, $code, $level) = @_;
+    $level ||= 0;
+    my $root = $target->root;
+
+    unless ((my $kind = $root->check_path ($target->path_anchor)) == $SVN::Node::dir) {
+       die loc("Path %1 is not versioned.\n", $target->path_anchor)
+           unless $kind == $SVN::Node::file;
+       $code->($target, $SVN::Node::file, 0);
+       return;
+    }
+
+    my $entries = $root->dir_entries ($target->path_anchor);
+    my $pool = SVN::Pool->new_default;
+    for (sort keys %$entries) {
+	$pool->clear;
+	my $child = $target->new->descend($_);
+	$code->($child, $entries->{$_}->kind, $level);
+
+	my $isdir = ($entries->{$_}->kind == $SVN::Node::dir);
+	if ($isdir && $self->{recursive} && (!$self->{'depth'} || ( $level < $self->{'depth'}))) {
+	    $self->run_command_recursively($child, $code, $level+1);
+	}
+    }
+}
+
+
 ## Resolve the correct revision numbers given by "-c"
 sub resolve_chgspec {
     my ($self,$target) = @_;

Modified: trunk/lib/SVK/Command/List.pm
==============================================================================
--- trunk/lib/SVK/Command/List.pm	(original)
+++ trunk/lib/SVK/Command/List.pm	Sat Nov 18 01:54:36 2006
@@ -25,42 +25,25 @@
     my ($self, @arg) = @_;
     my $exception = '';
 
-    while (my $arg = shift @arg) {
-	$arg = $arg->as_depotpath;
-        eval { _do_list($self, 0, $self->apply_revision($arg));
-	       print "\n" if @arg };
+    my $enc = get_encoder;
+    while ( my $arg = shift @arg ) {
+        $arg = $arg->as_depotpath;
+        eval {
+            $self->run_command_recursively(
+                $self->apply_revision($arg),
+                sub {
+                    my ( $target, $kind, $level ) = @_;
+                    $self->_print_item( $target, $kind, $level, $enc );
+                }
+            );
+            print "\n" if @arg;
+        };
         $exception .= "$@" if $@;
     }
 
     die($exception) if($exception);
 }
 
-sub _do_list {
-    my ($self, $level, $target) = @_;
-    my $root = $target->root;
-    unless ((my $kind = $root->check_path ($target->path_anchor)) == $SVN::Node::dir) {
-       die loc("Path %1 is not a versioned directory\n", $target->path_anchor)
-           unless $kind == $SVN::Node::file;
-       $self->_print_item( $target, $SVN::Node::file, 0, get_encoder);
-       return;
-    }
-
-    my $entries = $root->dir_entries ($target->path_anchor);
-    my $enc = get_encoder;
-    my $pool = SVN::Pool->new_default;
-    for (sort keys %$entries) {
-	$pool->clear;
-	my $isdir = ($entries->{$_}->kind == $SVN::Node::dir);
-	my $child = $target->new->descend($_);
-	$self->_print_item($child, $entries->{$_}->kind, $level, $enc);
-
-	if ($isdir && ($self->{recursive}) &&
-	    (!$self->{'depth'} ||( $level < $self->{'depth'} ))) {
-	    _do_list($self, $level+1, $child);
-	}
-    }
-}
-
 sub _print_item {
     my ( $self, $target, $kind, $level, $enc ) = @_;
     my $root = $target->root;

Modified: trunk/t/32list.t
==============================================================================
--- trunk/t/32list.t	(original)
+++ trunk/t/32list.t	Sat Nov 18 01:54:36 2006
@@ -34,13 +34,13 @@
     is_output ($svk, 'ls', ['-f',"/$depot/A/"],
 	       ["/$depot/A/B/","/$depot/A/foo"]);
     is_output ($svk, 'ls', ['-f','-R',"/$depot/A/"], ["/$depot/A/B/","/$depot/A/B/foo", "/$depot/A/foo"]);
-    is_output ($svk, 'ls', ['-f',"/$depot/crap/"], ['Path /crap is not a versioned directory']);
+    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"]);
     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 a versioned directory']);
+               ["/$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 );
@@ -79,7 +79,7 @@
                 qr"      2 $re_user        $size $re_date /$depot/A/B/foo",
                 qr"      1 $re_user        $size $re_date /$depot/A/foo"]);
     is_output ($svk, 'ls', ['-v', '-f',"/$depot/crap/"],
-               ['Path /crap is not a versioned directory']);
+               ['Path /crap is not versioned.']);
     ok ($svk->ls ('-v', '-f', "/$depot/crap/") == 1, "ls -v -f /$depot/crap/ [exit status]");
     is_output ($svk, 'ls', ['-v', '-f', "/$depot/", "/$depot/A/"],
                [qr"      2 $re_user          $re_date /$depot/A/",
@@ -91,7 +91,7 @@
                [qr"      2 $re_user          $re_date /$depot/A/B/",
                 qr"      1 $re_user        $size $re_date /$depot/A/foo",
                   '',
-                  'Path /crap is not a versioned directory']);
+                  '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