#! /tools/bin/perl -w

my $branch_tag=shift;
my $tag_release=shift;
my $tag_short=shift;
my $src_dir="/usr/www/push/temp2";
my $modules="webdev dal data_push";

my $tag_base=$tag_short . "_base";

my $base_log="/usr/www/push/var/merges/" . $tag_short;
my $conflict_log=$base_log . "_conflict.1";
my $merge_log=$base_log . "_merge.1";
my $commit_log=$base_log . "_commit.1";

if (! $branch_tag) {
	print "Please enter the branch tag name for the release: (release_20010520_version_2_2_9_full_branch)\n";
	exit 1;
} # End of if

if (! $tag_release) {
	print "Please enter the tag name for the release: (release_20010520_version_2_2_9_full_final_20010522)\n";
	exit 1;
} # End of if

if (! $tag_short) {
	print "Please enter the tag name for the release tag: (release_20010520_version_2_2_9_full)\n";
	exit 1;
} # End of if

print "BRANCH-$branch_tag\n";
print "BASE-$tag_base\n";
print "RELEASE-$tag_release\n";
print "CONFLICT-$conflict_log\n";
print "MERGE-$merge_log\n";

my $cmd1="cd $src_dir; cvs get $modules";
print "Executing: $cmd1\n";
system($cmd1);
my $cmd2="cd $src_dir; cvs up -j$tag_base -j$tag_release";
print "Executing: $cmd2\n";
system($cmd2);
my $cmd3="cd $src_dir; cvs -n up | grep ^[C] >& $conflict_log";
print "Executing: $cmd3\n";
system($cmd3);
my $cmd4="cd $src_dir; cvs -n up | grep ^[RAM] >& $merge_log";
print "Executing: $cmd4\n";
system($cmd4);

&mailit($branch_tag);
&commit_it($branch_tag,$src_dir,$commit_log);

sub mailit
{
my $branch=shift;
my $people='walt@epinions-inc,wmiller@epinions-inc.com';
#my $people="eng\@epinions-inc.com";
my $cc='Cc: wmiller@epinions-inc.com';
my $sendmailexec="/usr/lib/sendmail -t";

open (M, "| $sendmailexec ") || die ("sendmail failed to launch correctly aborting restart of");
print "Found some conflicts......\n";
print M "To: $people\n${cc}\nSubject: Conflicts found......\n\n";
print M "Warning!!!!!! Warning !!!!!!!\n\n";
print M "There were conflicts found when auto-merging from the branch\n\n$branch\n\nback to the trunk.\n";
print M "Click below for the diff.\n";
close (M);
} # End of mailit

sub commit_it
{
my $branch=shift;
my $dir=shift;
my $log=shift;

my $cmd="cd $dir; cvs commit -m\"Auto-merge for the $branch branch...\" >& $log ";
print "Executing: $cmd\n";
system($cmd);
} # End of commit_it

