#!/usr/bin/perl -w
###########################################
# cvs2github - Turn cvs repos to github
# Mike Schilli, 2005 (m@perlmeister.com)
###########################################
use strict;
use Getopt::Std;
use Pod::Usage;
use File::Temp qw(tempdir tempfile);
use Sysadm::Install qw(:all);

my($proj) = @ARGV;
my($temp_dir) = tempdir(CLEANUP => 1);
my($fh, $author_conv_file) = 
                     tempfile(UNLINK => 1);
my($home) = glob "~";
my $git_dir  = "$home/DEV";

my $email   = 'githubemail@mydomain.com';
my $cvs_loc = 
    'mikeschilli@some.cvs.server:cvs';
my $github_loc = 'git@github.com:mschilli';

blurt(<<EOT, $author_conv_file);
mschilli=mschilli <$email>
perlmeis=mschilli <$email>
mikeschilli=mschilli <$email>
EOT

pod2usage("No project given") unless 
    defined $proj;

my $git_proj_name = lc($proj) . "-perl";
my $git_path = "$git_dir/$git_proj_name";

if(-e $git_path) {
    die "Path $git_path already exists";
}

mkd $git_path;

for my $cvs_dir ($proj, "CVSROOT")) {
  sysrun(
  "RSYNC_RSH=/usr/bin/ssh $rsync -avz " . 
  "$cvs_loc:cvs/$proj $temp_dir/");
}

cd $git_path;

sysrun("git-cvsimport -A " .
  "$author_conv_file -d $temp_dir $proj");

sysrun("git remote add origin " .
       "$github_loc/$git_proj_name.git");

print "Done: $git_proj_name\n";

__END__

=head1 NAME

    cvs2github - Convert cvs projects to git

=head1 SYNOPSIS

    cvs2github My-Project-Name

=head1 DESCRIPTION

cvs2github takes a project checked into cvs 
and converts it into a git repo ready for
github.

=head1 EXAMPLES

  $ cvs2github JavaScript-SpiderMonkey
