#!/usr/bin/perl

use CM_util;

#########################################
# Hauptprogramm
#########################################

# open files
open (FIN, "$ARGV[0]") || die "file not found: $ARGV[0]\n";
open (FOUT, ">$ARGV[1]") || die "file not found: $ARGV[1]\n";

# define command tables
@UpdateDirs       = ();
@CheckinDirs      = ();
@DeleteFiles      = ();
@IgnoreFiles      = ();
@DeleteRepository = ();
@AddFiles         = ();
@BinFiles         = ();

analyseCmStatus();

# now build svn specific commands
foreach $Item ( @UpdateDirs )
{
    print FOUT "echo svn up $Item\n";
    print FOUT "svn up $Item\n\n";
}

foreach $Item ( @DeleteFiles )
{
    print FOUT "rm -r $Item\n\n";
}

foreach $Item ( @IgnoreFiles )
{
    print FOUT "echo \"$Item\" >> .cm.ignore\n\n";
}

foreach $Item ( @DeleteRepository )
{
    print FOUT "echo svn rm $Item\n";
    print FOUT "svn rm $Item\n\n";
}

foreach $Item ( @AddFiles )
{
    print FOUT "echo svn add -N $Item\n";
    print FOUT "svn add -N $Item\n\n";
}

foreach $Item ( @BinFiles )
{
    if ( $Item =~ /\// )
    {
        $Dir  = $Item;
        $Dir  =~ s/\/.*//;
        $Item =~ s/.*?\///;
        print FOUT "echo svn add $Item\n";
        print FOUT "cd $Dir; svn add $Item; cd ..\n\n";
    }
    else
    {
        print FOUT "echo svn add $Item\n";
        print FOUT "svn add $Item\n\n";
    }
}

$hostname = $ENV{'M_HOST'};

if (@CheckinDirs)
{
    print FOUT "echo Check in\n";
    print FOUT "svn ci -m $hostname\n\n";
}

print FOUT "svn up\n";

