#!/bin/sh
#	This file is part of the Concurrent Versions System CVS.
#	Written by Dick Grune, Vrije Universiteit, Amsterdam.
#	$Header: hist1,v 3.2 89/10/13 11:54:39 dick Exp $

#
#	Historian: ad-hoc configuration history reconstruction program, part 1
#
#		hist1 [ repository ]
#	writes on standard output phase 1 of the reconstruction of the
#	configuration history file of the repository, using reasonable(?)
#	heuristics. If no repository is given, the repository of the present
#	directory is used.
#
Name=hist1; export Name

# CVSBIN, CVSLIB and RCSBIN directories
CVSBIN=/home/top/dick/cvs
CVSLIB=/home/top/dick/cvs
RCSBIN=${RCSBIN-/usr/local/bin}
export CVSBIN CVSLIB RCSBIN

# avoid spurious identifications
PATH=${CVSPATH-/bin:/usr/bin}; export PATH

# determine the name of the repository
Repository=$1
. $CVSLIB/NR.aux

# get the whole rlog of all files
RCSFILES=`
	ls $Repository/*,v $Repository/.*,v \
		$Repository/Attic/*,v $Repository/Attic/.*,v 2>/dev/null |
	grep -v "\*"
`
for Rcs in $RCSFILES
do
	$RCSBIN/rlog $Rcs
done |

# remove all kinds of garbage
tr '\200-\377' '' |

# identify and combine revision and date lines
sed '
	/^--*$/{
		N
		s/\nrevision /\
<REV> /
		N
		s/\ndate: / /
		s/; *author:/ /
		s/;.*//
	}
	/^==*$/s/.*/----------------------------/
' |

# construct one line for each file modification
awk '
	$1 == "RCS" && running == 0 {
		# establish file name
		fname = $6;
	}
	$1 == "<REV>" {
		# print			date time fname rev author
		printf("%s %s %s %s %s ; ", $3, $4, fname, $2, $5);
		running = 1;
	}
	$1 ~ /^--*$/ && running != 0 {
		# revision description terminator
		printf("\n");
	}
	$1 != "<REV>" && $1 !~ /^--*$/ && running != 0 {
		# one line of revision description
		if (running > 1) {
			# multi-line revision message
			printf("\\n");
		}
		printf("%s", $0);
		running++;
	}
' |

# sort on date and time
sort -n |

# put a separator after each group of identical messages
awk -F\; '
	{	if (msg != "" && $2 != msg) {print ""; }
		msg = $2;
		print;
	}
	END	{
		if (msg != "") {print ""; }
	}
'

exit 0

