3 # $FreeBSD: src/tools/tools/commitsdb/make_commit_db,v 1.1.2.1 2002/08/12 13:37:46 joe Exp $
4 # $DragonFly: src/tools/tools/commitsdb/make_commit_db,v 1.2 2003/06/17 04:29:11 dillon Exp $
6 # This script walks the tree from the current directory
7 # and spits out a database generated by md5'ing the cvs log
8 # messages of each revision of every file in the tree.
11 use Digest::MD5 qw(md5_hex);
13 my $dbname = "commitsdb";
14 open DB, "> $dbname" or die "$!\n";
16 # Extract all the logs for the current directory.
19 my $dir = shift @dirs;
22 opendir DIR, $dir or die $!;
23 foreach (grep { /[^\.]/ } readdir DIR) {
24 my $filename = "$dir/$_";
26 my %loghash = parse_log_message($filename);
29 $logs{$filename} = {%loghash};
37 # Product a database of the commits
38 foreach my $f (keys %logs) {
40 foreach my $rev (keys %$file) {
41 my $hash = $$file{$rev};
43 print DB "$f $rev $hash\n";
47 print "\r" . " " x 30 . "\r$dir";
55 ##################################################
56 # Run a cvs log on a file and return a parse entry.
57 ##################################################
58 sub parse_log_message {
61 # Get a log of the file.
62 open LOG, "cvs -R log $file |" or die $!;
64 my $log = join "", @log;
67 # Split the log into revisions.
68 my @entries = split /----------------------------\n/, $log;
70 # Throw away the first entry.
73 # Record the hash of the message against the revision.
75 foreach my $e (@entries) {
76 # Get the revision number
77 $e =~ s/^revision\s*(\S*)\n//s;
80 # Strip off any other headers.
81 while ($e =~ s/^(date|branches):[^\n]*\n//sg) {
84 my $hash = string_to_hash($e);
85 $loghash{$rev} = $hash;
92 ##################################################
93 # Convert a log message into an md5 checksum.
94 ##################################################
98 return md5_hex($logmsg);