Update of /cvsroot/lxr/lxr/lib/LXR/Files
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27031/lib/LXR/Files
Modified Files:
Tag: bk-dev-branch
BK.pm
Log Message:
BK::getdir starting to come together - code builds an in-memory hash of
the entire source tree per version, as there appears to be no good way
to get the directory structure at a release point otherwise.
Tests for building the tree from the output of bk -r prs -r$release
are passing - no tests yet for correctly interfacing with BK.
Index: BK.pm
===================================================================
RCS file: /cvsroot/lxr/lxr/lib/LXR/Files/Attic/BK.pm,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -d -r1.1.2.1 -r1.1.2.2
--- BK.pm 4 Dec 2004 23:31:15 -0000 1.1.2.1
+++ BK.pm 12 Dec 2004 02:41:39 -0000 1.1.2.2
@@ -21,22 +21,67 @@
$CVSID = '$Id$ ';
use strict;
-use FileHandle;
+use File::Spec;
use Time::Local;
use LXR::Common;
-use vars qw();
+use vars qw(%tree_cache);
sub new {
- my ($self, $rootpath) = @_;
+ my ( $self, $rootpath ) = @_;
- $self = bless({}, $self);
+ $self = bless( {}, $self );
$self->{'rootpath'} = $rootpath;
- $self->{'rootpath'} =~ s@/*$@/@;
+ $self->{'rootpath'} =~ s!/*$!!;
return $self;
}
-sub allreleases {
- my ($self, $filename) = @_;
+sub insert_entry {
+ my ( $newtree, $path, $entry ) = @_;
+ $$newtree{$path} = {} if !defined( $$newtree{$path} );
+ $newtree->{$path}{$entry} = 1;
+}
+
+sub getdir {
+ my ( $self, $pathname, $release ) = @_;
+
+ if ( !defined $tree_cache{$release} ) {
+
+ # Not in cache, so need to build
+ my @all_entries = $self->get_tree( $release, $pathname );
+ my %newtree = ();
+ my ( $entry, $path, $file, $vol, @dirs );
+
+ $newtree{ File::Spec->rootdir() } = {};
+
+ foreach $entry (@all_entries) {
+ ( $vol, $path, $file ) = File::Spec->splitpath( File::Spec->rootdir() . $entry );
+ insert_entry( \%newtree, $path, $file );
+ while($path ne File::Spec->rootdir()) {
+ # Insert any directories in path into hash
+ ($vol, $path, $file) = File::Spec->splitpath(
+ File::Spec->catdir(File::Spec->splitdir($path)));
+ insert_entry(\%newtree, $path, $file);
+ }
+ }
+ $tree_cache{$release} = \%newtree;
}
+ return keys %{$tree_cache{$release}->{$pathname}};
+}
+
+sub get_tree() {
+ my ( $self, $release ) = @_;
+
+ my $real = $self->{'rootpath'};
+
+ open( X, "bk -r prs -r$release $real|" ) or die "Can't exec bk prs";
+
+ my @files = <X>;
+ @files = grep /^P /, @files;
+ map( s/^P //, @files );
+ chomp @files;
+ close X;
+
+ return @files;
+}
|