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

clkao at bestpractical.com clkao at bestpractical.com
Sat Nov 18 01:31:35 EST 2006


Author: clkao
Date: Sat Nov 18 01:31:35 2006
New Revision: 2166

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

Log:
Refactor svk list and make it display single file when ls is
given a single file.

Modified: trunk/lib/SVK/Command/List.pm
==============================================================================
--- trunk/lib/SVK/Command/List.pm	(original)
+++ trunk/lib/SVK/Command/List.pm	Sat Nov 18 01:31:35 2006
@@ -37,55 +37,64 @@
 
 sub _do_list {
     my ($self, $level, $target) = @_;
-    my $pool = SVN::Pool->new_default;
     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);
-
-        if ($self->{verbose}) {
-	    my $rev = $root->node_created_rev ($target->path."/$_");
-            my $fs = $target->repos->fs;
-
-            my $svn_date =
-                $fs->revision_prop ($rev, 'svn:date');
-
-	    # The author name may be undef
-            no warnings 'uninitialized';
-
-	    # Additional fields for verbose: revision author size datetime
-            printf "%7ld %-8.8s %10s %12s ", $rev,
-                $fs->revision_prop ($rev, 'svn:author'),
-                ($isdir) ? "" : $root->file_length ($target->path."/$_"),
-                reformat_svn_date("%b %d %H:%M", $svn_date);
-        }
-
-        if ($self->{'fullpath'}) {
-	    my $dpath = $target->path_anchor;
-	    to_native ($dpath, 'path', $enc);
-	    $dpath .= '/' unless $dpath eq '/';
-            print '/'.$target->depotname.$dpath;
-        } else {
-            print " " x ($level);
-        }
-	my $path = $_;
-	to_native ($path, 'path', $enc);
-        print $path.($isdir ? '/' : '')."\n";
+	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, $target->new->descend($_));
+	    _do_list($self, $level+1, $child);
 	}
     }
 }
 
+sub _print_item {
+    my ( $self, $target, $kind, $level, $enc ) = @_;
+    my $root = $target->root;
+    if ( $self->{verbose} ) {
+        my $rev = $root->node_created_rev( $target->path );
+        my $fs  = $target->repos->fs;
+
+        my $svn_date = $fs->revision_prop( $rev, 'svn:date' );
+
+        # The author name may be undef
+        no warnings 'uninitialized';
+
+        # Additional fields for verbose: revision author size datetime
+        printf "%7ld %-8.8s %10s %12s ", $rev,
+            $fs->revision_prop( $rev, 'svn:author' ),
+            ($kind == $SVN::Node::dir) ? "" : $root->file_length( $target->path ),
+            reformat_svn_date( "%b %d %H:%M", $svn_date );
+    }
+
+    my $output_path;
+    if ( $self->{'fullpath'} ) {
+        $output_path = $target->report;
+    }
+    else {
+        print " " x ($level);
+        $output_path = Path::Class::File->new_foreign( 'Unix', $target->path )
+            ->basename;
+    }
+    to_native( $output_path, 'path', $enc );
+    print $output_path;
+    print( ( $kind == $SVN::Node::dir ? '/' : '' ) . "\n" );
+
+}
+
 1;
 
 __DATA__

Modified: trunk/lib/SVK/Path.pm
==============================================================================
--- trunk/lib/SVK/Path.pm	(original)
+++ trunk/lib/SVK/Path.pm	Sat Nov 18 01:31:35 2006
@@ -320,7 +320,7 @@
 
 sub descend {
     my ($self, $entry) = @_;
-    $self->{path} .= "/$entry";
+    $self->{path} .= $self->{path} eq '/' ? $entry : "/$entry";
     return $self;
 }
 

Modified: trunk/t/32list.t
==============================================================================
--- trunk/t/32list.t	(original)
+++ trunk/t/32list.t	Sat Nov 18 01:31:35 2006
@@ -24,10 +24,10 @@
 
     is_output ($svk, 'ls', [], ['A/']);
     is_output ($svk, 'ls', ['-r1', 'A'], ['foo']);
-    is_output ($svk, 'ls', ['A/foo'], []);
+    is_output ($svk, 'ls', ['A/foo'], ['foo']);
     is_output ($svk, 'ls', ['-R', 'A'], ['B/', ' foo', 'foo']);
     is_output ($svk, 'ls', ['-R', '-d1'], ['A/', ' B/', ' foo']);
-    is_output ($svk, 'ls', ['-f','A/foo'], []);
+    is_output ($svk, 'ls', ['-f','A/foo'], ["/$depot/A/foo"]);
     is_output ($svk, 'ls', ["/$depot/"], ['A/']);
     is_output ($svk, 'ls', ['-f',"/$depot/"], ["/$depot/A/"]);
     is_output ($svk, 'ls', ['-f',"/$depot/A"],  ["/$depot/A/B/", "/$depot/A/foo"]);
@@ -51,7 +51,8 @@
                [qr"      2 $re_user          $re_date A/"]);
     is_output ($svk, 'ls', ['-v', '-r1'],
                [qr"      1 $re_user          $re_date A/"]);
-    is_output ($svk, 'ls', ['-v', 'A/foo'], []);
+    is_output ($svk, 'ls', ['-v', 'A/foo'],
+               [qr"      1 $re_user        $size $re_date foo"]);
     is_output ($svk, 'ls', ['-v', '-r1', '-R'],
                [qr"      1 $re_user          $re_date A/",
                 qr"      1 $re_user        $size $re_date  foo"]);
@@ -66,7 +67,8 @@
                 qr"      1 $re_user        $size $re_date  foo"]);
     is_output ($svk, 'ls', ['-v', '-f'],
                [qr"      2 $re_user          $re_date /$depot/A/"]);
-    is_output ($svk, 'ls', ['-v', '-f', 'A/foo'], []);
+    is_output ($svk, 'ls', ['-v', '-f', 'A/foo'],
+               [qr"      1 $re_user        $size $re_date /$depot/A/foo"]);
     is_output ($svk, 'ls', ['-v', '-f', "/$depot/"],
                [qr"      2 $re_user          $re_date /$depot/A/"]);
     is_output ($svk, 'ls', ['-v', '-f', "/$depot/A/"],


More information about the svk-commit mailing list