Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I am trying to write some code to handle CVS checkout.
Priliminary work, i created two folders (test1 and test2) and tested it.
Please go through the code which wrote: It's just like a comparision of files.

#!/usr/bin/perl $dir1 = "/root/test1"; # Checkout Dir $dir2 = "/root/test2"; # CVS opendir(BIN, $dir1) or die "Can't open $dir: $!"; while ( defined ($file = readdir BIN) ) { push(@fl,$file) unless $file =~ /^\.\.?$/; } closedir(BIN); foreach $key(@fl) { if(! -e "$dir2/$key") { system (`cp "$dir1/$key" "$dir2/$key"`); } else { $cvs_modi = (stat("$dir1/$key"))[9]; $client_modi = (stat("$dir2/$key"))[9]; if($cvs_modi > $client_modi) { system(`cp "$dir1/$key" "$dir2/$key"`); } else { print "No need to copy.\n"; } } }

Is any sample code available in net to do this work?
or can anyone help me to handle this problem.
Thanks & Regards
Maj

Replies are listed 'Best First'.
Re: cvs checkin sample code
by Mutant (Priest) on Oct 20, 2004 at 14:24 UTC
    I'm not quite sure what you're trying to do. If you're tring to emulate the funtionality of CVS, don't.

    Instead, have a look at one of the CVS related modules on CPAN, such as Cvs. This should do pretty much everything for you.

    (I haven't tried this module myself, but if it doesn't suit your purposes, try doing a CPAN search on CVS. There are plenty of CVS related modules available)
      Hi
      Thanks for your reply.
      I want to write some code to handle CVS Checkin/Checkout as a cron program.
      But i didn't get any proper direction to tackle this problem.
      I had gone through the internet for sample program, but i didn't get.
      I am expecting some help from perlmonks
      Thanks
        So you want to periodically check in and check out from CVS?

        Apart from the fact that it's possibly a bad idea (since the idea of CVS is usually that it's a manual thing, ie. you decide when you've made some changes to checkin, etc), can you just call the 'cvs' command line directly from cron?

        If you need something a bit more sophisticated, then I recommend looking into the modules I mentioned above.
Re: cvs checkin sample code
by tachyon (Chancellor) on Oct 21, 2004 at 08:48 UTC

    It sound like you just want to run a cvs command from cron nightly. You can just use a shell script:

    #!/bin/sh cd /home/you/cvs/stuff /usr/bin/cvs update /usr/bin/cvs diff

    You can do the same in perl if you want

    #!/usr/bin/perl my $CVS = '/usr/bin/cvs'; my $DIR = '/home/you/cvs/stuff'; chdir $DIR; print `$CVS update`; print `$CVS diff`;

    Make sure you run the job as you so you pick up your CVSROOT environment var OK. Backticks let you capture the command output, so with the print and cron will email you the output automagically.

    cheers

    tachyon

Re: cvs checkin sample code
by trammell (Priest) on Oct 20, 2004 at 14:56 UTC
      Hi
      Thanks for your reply
      Yes i will do that
      regards