[Lxr-commits] CVS: lxr/lib/LXR/Files BK.pm,1.1.2.3,1.1.2.4
Brought to you by:
ajlittoz
From: Malcolm B. <mb...@us...> - 2005-02-13 23:07:21
|
Update of /cvsroot/lxr/lxr/lib/LXR/Files In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10408/lib/LXR/Files Modified Files: Tag: bk-dev-branch BK.pm Log Message: genxref now works against the test BK repository. Index: BK.pm =================================================================== RCS file: /cvsroot/lxr/lxr/lib/LXR/Files/Attic/BK.pm,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -d -r1.1.2.3 -r1.1.2.4 --- BK.pm 13 Feb 2005 19:35:05 -0000 1.1.2.3 +++ BK.pm 13 Feb 2005 23:07:06 -0000 1.1.2.4 @@ -23,6 +23,7 @@ use strict; use File::Spec; use Cwd; +use Digest::SHA qw(sha1_hex); use Time::Local; use LXR::Common; @@ -40,20 +41,87 @@ return $self; } -sub insert_entry { - my ($newtree, $path, $entry, $curfile, $rev) = @_; - $$newtree{$path} = {} if !defined($$newtree{$path}); - $newtree->{$path}{$entry} = { 'curpath' => $curfile, 'revision' => $rev }; -} +# +# Public interface +# sub getdir { my ($self, $pathname, $release) = @_; $self->fill_cache($release); + $pathname = canonise($pathname); $pathname = File::Spec->rootdir() if $pathname eq ''; return keys %{ $tree_cache{$release}->{$pathname} }; } +sub getfile { + my ($self, $pathname, $release) = @_; + $pathname = canonise($pathname); + my $fileh = $self->getfilehandle($pathname, $release); + + return undef unless $fileh; + my $buffer = join('', $fileh->getlines); + close $fileh; + return $buffer; +} + +sub getfilehandle { + my ($self, $pathname, $release) = @_; + $pathname = canonise($pathname); + my $fileh = undef; + my $dir = getcwd(); + chdir($self->{'rootpath'}); + if ($self->file_exists($pathname, $release)) { + my $info = $self->getfileinfo($pathname, $release); + my $ver = $info->{'revision'}; + my $where = $info->{'curpath'}; + open($fileh, "bk get -p -r$ver $where 2>/dev/null |") + or die "Error executing bk get"; + } + chdir($dir); + return $fileh; +} + + + +sub filerev { + my ($self, $filename, $release) = @_; + + my $info = $self->getfileinfo($filename, $release); + return sha1_hex($info->{'curpath'}.'-'.$info->{'revision'}); +} + +sub tmpfile { + my ($self, $filename, $release) = @_; + my ($tmp, $buf); + + $buf = $self->getfile($filename, $release); + return undef unless defined($buf); + + $tmp = + $config->tmpdir + . '/bktmp.' + . time . '.' + . $$ . '.' + . &LXR::Common::tmpcounter; + open(TMP, "> $tmp") || return undef; + print(TMP $buf); + close(TMP); + + return $tmp; +} + + +# +# Private interface +# + +sub insert_entry { + my ($newtree, $path, $entry, $curfile, $rev) = @_; + $$newtree{$path} = {} if !defined($$newtree{$path}); + $newtree->{$path}{$entry} = { 'curpath' => $curfile, 'revision' => $rev }; +} + sub fill_cache { my ($self, $release) = @_; @@ -76,7 +144,7 @@ ($vol, $path, $file) = File::Spec->splitpath( File::Spec->catdir(File::Spec->splitdir($path))); - insert_entry(\%newtree, $path, $file); + insert_entry(\%newtree, $path, $file.'/'); } } @@ -108,23 +176,6 @@ return @files; } -sub getfilehandle { - my ($self, $pathname, $release) = @_; - $pathname = canonise($pathname); - my $fileh = undef; - my $dir = getcwd(); - chdir($self->{'rootpath'}); - if ($self->file_exists($pathname, $release)) { - my $info = $self->getfileinfo($pathname, $release); - my $ver = $info->{'revision'}; - my $where = $info->{'curpath'}; - open($fileh, "bk get -p -r$ver $where 2>/dev/null |") - or die "Error executing bk get"; - } - chdir($dir); - return $fileh; -} - sub canonise { my $path = shift; $path =~ s!^/!!; @@ -151,33 +202,3 @@ } -sub getfile { - my ($self, $pathname, $release) = @_; - $pathname = canonise($pathname); - my $fileh = $self->getfilehandle($pathname, $release); - - return undef unless $fileh; - my $buffer = join('', $fileh->getlines); - close $fileh; - return $buffer; -} - -sub tmpfile { - my ($self, $filename, $release) = @_; - my ($tmp, $buf); - - $buf = $self->getfile($filename, $release); - return undef unless defined($buf); - - $tmp = - $config->tmpdir - . '/bktmp.' - . time . '.' - . $$ . '.' - . &LXR::Common::tmpcounter; - open(TMP, "> $tmp") || return undef; - print(TMP $buf); - close(TMP); - - return $tmp; -} |