3 # $FreeBSD: src/tools/tools/commitsdb/make_commit_db,v 1.1.2.1 2002/08/12 13:37:46 joe Exp $
5 # This script walks the tree from the current directory
6 # and spits out a database generated by md5'ing the cvs log
7 # messages of each revision of every file in the tree.
10 use Digest::MD5 qw(md5_hex);
12 my $dbname = "commitsdb";
13 open DB, "> $dbname" or die "$!\n";
15 # Extract all the logs for the current directory.
18 my $dir = shift @dirs;
21 opendir DIR, $dir or die $!;
22 foreach (grep { /[^\.]/ } readdir DIR) {
23 my $filename = "$dir/$_";
25 my %loghash = parse_log_message($filename);
28 $logs{$filename} = {%loghash};
36 # Product a database of the commits
37 foreach my $f (keys %logs) {
39 foreach my $rev (keys %$file) {
40 my $hash = $$file{$rev};
42 print DB "$f $rev $hash\n";
46 print "\r" . " " x 30 . "\r$dir";
54 ##################################################
55 # Run a cvs log on a file and return a parse entry.
56 ##################################################
57 sub parse_log_message {
60 # Get a log of the file.
61 open LOG, "cvs -R log $file |" or die $!;
63 my $log = join "", @log;
66 # Split the log into revisions.
67 my @entries = split /----------------------------\n/, $log;
69 # Throw away the first entry.
72 # Record the hash of the message against the revision.
74 foreach my $e (@entries) {
75 # Get the revision number
76 $e =~ s/^revision\s*(\S*)\n//s;
79 # Strip off any other headers.
80 while ($e =~ s/^(date|branches):[^\n]*\n//sg) {
83 my $hash = string_to_hash($e);
84 $loghash{$rev} = $hash;
91 ##################################################
92 # Convert a log message into an md5 checksum.
93 ##################################################
97 return md5_hex($logmsg);