> There's an example of this in the manual.  The gist is to use a loginfo script
> to do the checkout.  Be sure to do the checkout in the background so the script
> doesn't deadlock.

We use CVS to manage our website here. In addition to the automated checkouts,
we also do HTML validation on checkin, and use the CVS information to 
generate Dublin Core Metadata for the pages - we also use it to target a
search engine (if we know what pages have changed, we need only update them
in the database). We also have a interface to CVS from the "Publish" option
in several editors, and I'm looking at providing a DAV interface as well.

Anyway, getting back to the point, we use a variation of an auto-export
script that I found - it _only_ exports the files that have been committed,
and doesn't bother scanning the entire tree, making it much more responsive.
The script used to punt this into cvs export (requiring a sleep to prevent
deadlocks) - however I wasn't happy with this approach, as it seemed to
have lots of race potential, so I rewrote the script to use rcs to checkout
the files before CVS has released the globabl repository lock (which looked
safe when I looked through the code - no doubt someone will tell me now if
it isn't.)

I've included the script below. I'm hoping to package this, along with the
rest of the tools I use, up and make them available - let me know if 
anyone's interested in this. You'll need to change the cvsroot and docroot
variables.

Cheers,

Simon.

#!/usr/bin/perl
#
# auto-export.pl
#
# Invoke with the following line in the loginfo script
#
# ALL           $CVSROOT/CVSROOT/auto-export.pl %s

use File::Basename;

print "Automatically exporting files to the live tree\n";

$cvsroot="/disk/public/export/infweb/cvs";
$docroot="/disk/public/export/infweb/checkout";

my($fileCapture) = 0;
my($files)       = "";
my(@importFiles) = qw();
my(@files1) = qw();
my(@files2) = qw();
my($subDir)      = "";

while(<STDIN>) {
    chop;
    if ($_ =~ /^Log Message:/) {
        $fileCapture = 0;
    } elsif ($fileCapture) {
        $files .= $_;
    } elsif ($_ =~ /^Update of /) {
        $subDir = $_;
        $subDir =~ s/^Update of $cvsroot//;
    } elsif (($_ =~ /^Modified Files:/) ||
             ($_ =~ /^Added Files:/)) {
        $fileCapture = 1;
    } elsif ($_ =~ /^(U|N) (\S+)$/) {
        my $fname = $2;
        $fname =~ s|/+|/|g;
        push(@importFiles,$fname);
    }
}

$args=$ARGV[0];
$args=~s/\- New directory//;

# make argv[0] into a list of files
if ($args =~ /^(\S+?) (.+)$/) {
    my($dir) = $1;
    @files1 = split(' ',$2);
    @files1 = map { $dir.'/'.$_ } @files1;
}

# make the file capture files into a list of files
if ($files) {
    $files =~ s/\s+/ /g;
    $files =~ s/^\s+//g;
    @files2 = split(' ',$files);
    @files2 = map { $subDir.'/'.$_ } @files2;
}

# if imported list is there, use that
# otherwise, argv and capt list should be the same and we can use that

my($fileList,@fileList);
if ($#importFiles >= 0) {
    @fileList = @importFiles;
} else {
    @fileList = @files1;
}

#
# remove any existing versions of the files
#
unlink(map {$docroot.'/'.$_ } @fileList);

#
# export the files
#

foreach $file (@fileList) {
  my $dir=dirname($file);
  print `mkdir -p $docroot/$dir` if $dir;
  print `co -kv $cvsroot/${file},v $docroot/${file}`;
}








Reply via email to