#!/usr/bin/perl -w
# $Id$
# Copyright (C) 2006 by Martin Scharrer <martin@scharrer-online.de>
# This is free software under the GPL.

use strict;
use File::Copy;

# Current working dir
use Cwd;
my $CWD = getcwd;

# Revision counter
my $rev = 0;

# Log entry
my $log = "";


# Create test repository and working directory
system ("svnadmin create testrepos");
system ("svn co file://$CWD/testrepos testwd");


### Generate test file ###
# The pseudo random function is used with a constant seed. The `random'
# numbers we get will look random but will be the same at every run on
# every host. There text contains of 600 sections a 100 lines with 5 rand's
# each. The sections a seperated by two newlines.
# Three almost identical files a generated. The second two misses a different 
# section.

srand(100);  # Init generator, do not change the number, please

my $tf1;
my $tf2;

open (TF1, '>', "testfile1");
open (TF2, '>', "testfile2");

for my $N (1..600) 
 { 
   my $text;
   for (1..100) 
   { for (1..5) 
     { $text .= rand() . " " }
     $text .= "\n";
   }

   print (TF1 $text, "\n\n"); 
   print (TF2 $text, "\n\n") unless ($N == 300); 
 }

close (TF1);
close (TF2);

# Create a other file in the wd, it's needed to generate some other revs
open (OTH, ">", "testwd/other");
print OTH " ";
close (OTH);
system ("svn add testwd/other");


# Now lets check-in the file
copy("testfile1", "testwd/testfile");
system ("svn add testwd/testfile");
system ("svn ci testwd/testfile -m 'First check-in'");
$rev++;

for (1..15)
 {
   copy("testfile2", "testwd/testfile");
   system ("svn ci testwd/testfile -m 'Deleted lines in file.'");
   $rev++;
   $log .= sprintf ("%3d: Deleted lines; Rev size %6d\n", $rev, -s "testrepos/db/revs/$rev");

   &other_revs();

   copy("testfile1", "testwd/testfile");
   system ("svn ci testwd/testfile -m 'Added lines in file.'");
   $rev++;
   $log .= sprintf ("%3d:   Added lines; Rev size %6d\n", $rev, -s "testrepos/db/revs/$rev");
   
   &other_revs();
 }

system ("svn up testwd/");

print "\nFinal log:\n";
print   "~~~~~~~~~~\n";
print $log;

exit(0);

my $num = 0;

sub other_revs
 {
   my $i = 0;

   unless ($num > 0)
    { $num = 5; }

   # Generate a couple of other revs
   while ( $i++ < $num )
    {
      open (OTH, ">", "testwd/other");
      print OTH "$i:", rand;
      close (OTH);

      system ("svn ci testwd/other -m 'Other check-in ($i).'");
      $rev++;
    }

    $num--;
 }

__END__


