Converting output of 'svnlook tree' to canonical format
Carl Spalletta <[email protected]> Mon, 6 Feb 2006 13:08:39 -0500
| Newsgroups | gmane.comp.version-control.subversion.devel,gmane.mail.eyebrowse.user |
|---|---|
| Message-ID | <69a7202e0602061008n293f334cu617676a484272c14__12443.6644059189$1139253021$gmane$org@mail.gmail.com> |
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 [email protected] 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=3D0; $olevel=3D-1; } #count number of leading spaces sub countlevels { my $line =3D shift; my @ltrs =3D split "",$line; my $levels; for($levels=3D0;$levels<=3D$#ltrs;$levels++) { last unless $ltrs[$levels] =3D~ /^ $/; } return $levels; } #chomp,print,next if /^\S/; if(/^\S/) { if(m{^/}) { chomp; print "$_"; } else { die "Extraneous garbage: $_"; } next } $level =3D countlevels $_; if($level<$olevel) { for($i=3D$level;$i<$olevel;$i++) { $l[$i]=3D""; } } $l[$level-1]=3D$_; print "$line\n"; $line =3D join "/",@l; $line =3D~ s/\s//g; $line =3D~ tr/\///s; $olevel=3D$level; END { print "$line\n"; }