#!/usr/bin/perl -w # $FreeBSD: src/tools/tools/commitsdb/make_commit_db,v 1.1.2.1 2002/08/12 13:37:46 joe Exp $ # $DragonFly: src/tools/tools/commitsdb/make_commit_db,v 1.2 2003/06/17 04:29:11 dillon Exp $ # This script walks the tree from the current directory # and spits out a database generated by md5'ing the cvs log # messages of each revision of every file in the tree. use strict; use Digest::MD5 qw(md5_hex); my $dbname = "commitsdb"; open DB, "> $dbname" or die "$!\n"; # Extract all the logs for the current directory. my @dirs = "."; while (@dirs) { my $dir = shift @dirs; my %logs; opendir DIR, $dir or die $!; foreach (grep { /[^\.]/ } readdir DIR) { my $filename = "$dir/$_"; if (-f $filename) { my %loghash = parse_log_message($filename); next unless %loghash; $logs{$filename} = {%loghash}; } elsif (-d $_) { next if /^CVS$/; push @dirs, $_; } } close DIR; # Product a database of the commits foreach my $f (keys %logs) { my $file = $logs{$f}; foreach my $rev (keys %$file) { my $hash = $$file{$rev}; print DB "$f $rev $hash\n"; } } print "\r" . " " x 30 . "\r$dir"; } print "\n"; close DB; ################################################## # Run a cvs log on a file and return a parse entry. ################################################## sub parse_log_message { my $file = shift; # Get a log of the file. open LOG, "cvs -R log $file |" or die $!; my @log = ; my $log = join "", @log; close LOG; # Split the log into revisions. my @entries = split /----------------------------\n/, $log; # Throw away the first entry. shift @entries; # Record the hash of the message against the revision. my %loghash = (); foreach my $e (@entries) { # Get the revision number $e =~ s/^revision\s*(\S*)\n//s; my $rev = $1; # Strip off any other headers. while ($e =~ s/^(date|branches):[^\n]*\n//sg) { }; my $hash = string_to_hash($e); $loghash{$rev} = $hash; } return %loghash; } ################################################## # Convert a log message into an md5 checksum. ################################################## sub string_to_hash { my $logmsg = shift; return md5_hex($logmsg); } #end