#! /tools/bin/perl  -w

use DBI;
use strict;
use vars qw ($dbh $sth);
require '/usr/www/push/sqlcommon20.pl';
require '/usr/www/push/common20.pl';
require '/usr/www/push/getrev20.pl';
my $dbh=&ConnectToDatabase("push20");
my $root="/usr/www/push/temp/";
my $dirlist="/usr/www/push/scripts/dirlist30";
my $dir;

open(FILE,$dirlist);
my @dirs=<FILE>;
close(FILE);
foreach $dir (@dirs){
	chomp $dir;
	print "$dir\n";
	&get_all_versions($dir);
} # End of foreach

sub ConnectToDatabase {
    my $database = shift ;
    my ($dsn)="DBI:mysql:$database:keefer.epinions.com";
 DBI->trace(1, "/usr/www/push/var/load20.out");
        $dbh = DBI->connect($dsn, "root", "push")
            || die "$DBI::errstr - Can't connect to database server: .";
} # End of ConnectToDatabase

sub get_all_versions
{
my $path=shift ;
my $m;
my @buf;
my $full_path = $root . $path . "/CVS/Entries";
$full_path =~  s/\/\//\//g; # get rid of // from path
#return if !(-e $full_path);
open(STAT,"$full_path");
@buf=<STAT>;
close(STAT);

foreach $m (@buf) {
        next if ($m =~ m/^D/);
        chomp ($m);
        my ($g,$filename,$version,$rest)=split (/\//,$m,4);
	my $filepath=$path."/$filename";
	print "$filepath\n";
	print "$version\n";
	print "FILE-$filename DIR-$path\n";
	my $insert="insert into filepaths values (NULL,'$filepath','$version',NULL,NULL,NULL,NULL)";
	$sth= $dbh->prepare(qq{ $insert } ) || &choke($sth->errstr);
	$sth->execute() || &choke ($sth->errstr);
	$sth->finish(); #cleanup
#	&getrev($filename,$path,$dbh);
} # End of foreach
} # End of get_all_versions

sub choke
{
my $reason=shift;
print "Failing because: $reason !!!!\n";
exit 1;
} # End of choke
