#!/usr/bin/perl

@log = ();

while( <> ) {
    chomp;
    if( /^Working file: (.*)$/ ) {
	$file = $1;
    }
    elsif( /^date: (.*?);/ ) {
	$date = $1;
	if( /author: (.*?);/ ) {
	    $author = $1;
	}
	$text = "";
	$init = 1;
	while( <> ) {
	    if( $init ) {
	        /^branches:.*;/ && next;
	    }
	    $init = 0;
	    last if( /^(---|===)/ );
	    $text .= $_;
	}
	chomp $text;
	push( @log, [ $date, $file, $text, $author ] ) unless( $file =~ /Attic/ );
	($date,$text,$author) = ("","","");
    }
}

@log = sort { $b->[0].$b->[2].$b->[1] cmp $a->[0].$a->[2].$a->[1] } @log;

for( $i=0; $i <= $#log; $i++ ) {
    $files = $log[$i]->[1];
    $date = $log[$i]->[0];
    $text = $log[$i]->[2];
    %authors = ($log[$i]->[3] => 1);
    while( ($i<$#log) && datecomp($log[$i+1]->[0], $date) && ($log[$i+1]->[2] eq $text) ) {
	$i++;
	$files .= ", ".$log[$i]->[1];
	$authors{$log[$i]->[3]} = 1;
    }
    $text =~ s/\n/\n\t/sg;
    print $date." (".join(",",keys %authors).")"."\t".$files.":"."\n\t".$text."\n\n";
}


sub datecomp {
   my( $a, $b ) = @_;
   $a =~ s/:\d\d$//;
   $b =~ s/:\d\d$//;
   return( $a eq $b );
}
