[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Converting output of 'svnlook tree' to canonical format

From: Carl Spalletta <cspalletta_at_gmail.com>
Date: 2006-02-06 19:08:39 CET

Excuse me for reinventing the wheel, but I couldn't find an existing script to
convert output of 'svnlook tree' to the usual unix format.

Hope this is useful to somebody.

Please give credit if you use the logic or code somewhere.

#!/usr/bin/perl -n
#Copyright (c) 2006 by Carl Spalletta cspalletta@gmail.com under GPL, v2
#This file takes the output of unix or svnlook 'tree' command, eg:
#
# trunk/
# CVS-LEGACY/
# cvswrappers
# checkoutlist
# PROJ1/
# config
# branches/
# ...
#
# And turns it into this:
#
#trunk/
#trunk/CVS-LEGACY/
#trunk/CVS-LEGACY/cvswrappers
#trunk/CVS-LEGACY/checkoutlist
#trunk/PROJ1/config
#branches/
# ...

BEGIN
{
  $level=0;
  $olevel=-1;
}

#count number of leading spaces
sub countlevels
{
my $line = shift;
my @ltrs = split "",$line;
my $levels;

for($levels=0;$levels<=$#ltrs;$levels++)
  {
  last unless $ltrs[$levels] =~ /^ $/;
  }

return $levels;
}

#chomp,print,next if /^\S/;
if(/^\S/)
{
if(m{^/})
  {
  chomp;
  print "$_";
  }
else
  {
  die "Extraneous garbage: $_";
  }
next
}

$level = countlevels $_;
if($level<$olevel)
{
for($i=$level;$i<$olevel;$i++)
  {
  $l[$i]="";
  }
}

$l[$level-1]=$_;
print "$line\n";

$line = join "/",@l;

$line =~ s/\s//g;
$line =~ tr/\///s;

$olevel=$level;

END
{
print "$line\n";
}

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Mon Feb 6 20:10:39 2006

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.