#!/usr/local/bin/perl
use strict ;
use Getopt::Std ;
use SVN::Client;

sub process_dir 
{
  my ( $ctx, $url, $revision, $spaces, $level ) = @_ ;
  my $dirs = $ctx->ls ( $url , $revision, 0 ) ;

  $level++;
  #print "************ $level ************\n";
  foreach my $dir (sort keys (%$dirs)) {
	my $printed = 0;
	my $props = $ctx->propget("svn:externals", "$url/$dir", $revision, 0);
	if (%$props + 0) {	
		print " " x $spaces, $dir, "\n";
		$printed++;
		foreach my $prop (keys %$props) {
			#print " ** \"$props->{$prop}\"\n";
			my $y = $props->{$prop};
			#$y =~ tr/\n//d;
			$y =~ tr/\r//d;
			my @x = split /\s+/,$y;
			#print "** ", join(",", @x), "\n";
			for (my $i = 0; $i < $#x; $i+=2) {
			  print " " x $spaces, " ", $x[$i], " -> ", $x[$i+1], "\n";
			}
		}
	}
	if ($dirs->{$dir}->kind() == $SVN::Node::dir) {
		print " " x $spaces, $dir, "\n" if ($printed eq 0);
		process_dir($ctx, "$url/$dir", $revision, $spaces+1, $level);
		#sleep 1;
	}
	elsif ($dirs->{$dir}->kind() == $SVN::Node::file) {
		print  " " x $spaces, "$dir\n" if ($printed eq 0);
	} else {
		print $dir, "\n";
		exit 0;
	}
  }
}

my $url ;
my $ctx = new SVN::Client(
              auth => [SVN::Client::get_simple_provider(),
              SVN::Client::get_simple_prompt_provider(\&simple_prompt,2),
              SVN::Client::get_username_provider()]
              );
my $revision = 'HEAD' ;
my %options ;
getopts("u:",\%options);

if ( $options{'u'} ) { $url = $options{'u'}; }
if ( $options{'r'} ) { $revision = $options{'r'}; }
print "[$url]\n";
process_dir ( $ctx, $url, $revision, 0 , 1) 

