#!/usr/bin/perl -w #------------------------------------------------------------------------------ # $Id: cvshist,v 1.10 2003/05/20 11:08:18 peters Exp $ # # SCRIPT: cvshist # # AUTHOR: Peter Sundstrom (peter@ginini.com) # # FUNCTION: Converts the output of 'cvs history' into a more readable # HTML form. # # By default, reports on modification and additions. # The -c flag will report on checkouts and releases. # # NOTES: http://www.ginini.com/software/cvshist/ # # Copyright (c)2001-2002 Peter Sundstrom # #============================================================================== use strict; use User::pwent qw(:FIELDS); use Getopt::Std; use vars qw($opt_c $opt_d $path $version); $version='1.1.1'; #--------------------------------------------------------------------- # CONFIGURATION SECTION # # Default location of CVSROOT, if the $CVSROOT environment variable # is not set. # my $CVSROOT='/var/cvs'; # # Location of CVS binary # my $cvscmd='/usr/bin/cvs'; # # Default number of days to show history for # my $days=20; # # Timezone offset from GMT. If you are ahead of GMT it will be a # positive number, behind GMT, it will be a negative number. # GMT +1200 is Eastern Australian Time (during daylight savings) my $TZoffset='+1200'; # # Table colours # my $color_modified='#CCFFCC'; my $color_added='yellow'; my $color_removed='#DDBBEEFF'; my $color_released='#CCFFCC'; my $color_checked='yellow'; # # Define the URL to cvsweb if you have it installed on your system # and you want cvshist to link to it, otherwise set it to blank. # my $cvsweb='/cgi-bin/cvsweb.cgi'; # END OF CONFIGURATION SECTION #--------------------------------------------------------------------- # # If the CVSROOT environment variable is set, use it. # $ENV{CVSROOT}=$CVSROOT unless $ENV{CVSROOT}; # # Sanity checks # die "$cvscmd not found\n" unless -x $cvscmd; # # If CVSROOT is local, check the directory exists if ($ENV{CVSROOT} !~ /:/) { die "CVSROOT: $ENV{CVSROOT} does not exist\n" unless -d $ENV{CVSROOT}; } # # Process options # getopts('cd:') or die <] -c Show checkout history -d Show history for past x days (Default: $days days) Version: $version EOF $days=$opt_d if $opt_d; # # The flags to the history command are: # # -a Report on all users # -e Show all record types # -D Date flag. Show the specifed number of days of history entries # -z Timezone field. Unfortunately offsets in hours to GMT need to be used. open(HISTORY,"$cvscmd history -a -e -D \"$days days ago\" -z $TZoffset |/bin/sort -r +1 |") or die "Can not run $cvscmd, $!\n"; Header(); # # The first field of the cvs history output indicates the action type: # # O Check out # F Release # M Modified # A Added # R Removed while () { chomp; if ($opt_c) { if (/^[O,F]/) { my @field=split; if ($field[0] eq 'O') { print qq(\n); TD("Checked out"); } elsif ($field[0] eq 'F') { print qq(\n); TD("Released"); } TD($field[1]); TD($field[2]); my $username=Username($field[4]); $username .= " (remote)" if (/remote/); TD($username); if ($field[0] eq 'O') { if ($field[5] =~ /\[/) { $path=$field[6]; } else { $path=$field[5]; } if ($cvsweb) { TD(qq[$path]); } else { TD($path); } } else { $field[5] =~ s/=//g; TD($field[5]); } print "\n"; } } else { if (/^[M,A,R]/) { my ($action,$date,$time,$user,$version,$file,$dir) = /(\w) ([\d-]+) (\d+:\d+)\s+\S+\s+(\w+)\s+([\d\.]+)\s+(\S+)\s+(\S+|\s+)\s*==/; $dir =~ s/^ //g; if ($action eq 'M') { print qq(\n); TD("Modified"); } elsif ($action eq 'A') { print qq(\n); TD("Added"); } elsif ($action eq 'R') { print qq(\n); TD("Removed"); } TD($date); TD($time); my $username=Username($user); TD($username); TD($version) unless $opt_c; if ($cvsweb) { TD(qq[$dir/$file]); } else { TD("$dir/$file"); } print "\n"; } } } close(HISTORY); Footer(); #------------------------------------------------------------------------------ sub TD { my $field=shift; print qq($field); } #------------------------------------------------------------------------------ sub Username { my $user=shift; getpwnam($user) or return ("$user"); return $pw_gecos; } #------------------------------------------------------------------------------ sub Header { my $date=localtime(); print < CVS History

CVS History

for the last $days days

Last updated: $date

TEXT print qq(\n) unless $opt_c; print qq(\n); print qq(\n); } #------------------------------------------------------------------------------ sub Footer { print <

Version: $version

TEXT }
Action Date Time UserVersionDir/File