3 # $FreeBSD: src/tools/tools/commitsdb/query_commit_db,v 1.3.2.1 2002/08/12 13:37:46 joe Exp $
4 # $DragonFly: src/tools/tools/commitsdb/query_commit_db,v 1.2 2003/06/17 04:29:11 dillon Exp $
6 # This script takes a filename and revision number as arguments
7 # and spits out a list of other files and their revisions that share
8 # the same log message. This is done by referring to the database
9 # previously written by running make_commit_db.
12 use Digest::MD5 qw(md5_hex);
14 my $dbname = "commitsdb";
16 # Take the filename and revision number from the command line.
17 # Also take a flag to say whether to generate a patch or not.
18 my ($file, $revision, $genpatch) = (shift, shift, shift);
20 # Find the checksum of the named revision.
22 open DB, "< $dbname" or die "$!\n";
26 my ($name, $rev, $hash) = split;
29 $possible_files{$name} = 1 if $file !~ /\// && $name =~ /^.*\/$file/;
31 next unless $name eq $file and $rev eq $revision;
36 # Handle the fall-out if the file/revision wasn't matched.
38 if (%possible_files) {
39 print "Couldn't find the file. Maybe you meant:\n";
40 foreach (sort keys %possible_files) {
44 die "Can't find $file rev $revision in database\n";
48 # Look for similar revisions.
50 open DB, "< $dbname" or die "$!\n";
53 my ($name, $rev, $hash) = split;
55 next unless $hash eq $cksum;
57 push @results, "$name $rev";
61 # May as well show the log message if we're producing a patch
62 print `cvs log -r$revision $file` if $genpatch;
64 # Show the commits that match, and their patches if required.
65 foreach my $r (sort @results) {
67 next unless $genpatch;
69 my ($name, $rev) = split /\s/, $r, 2;
70 my $prevrev = previous_revision($rev);
71 print `cvs diff -u -r$prevrev -r$rev $name`;
76 # Return the previous revision number.
78 sub previous_revision {
81 $rev =~ /(?:(.*)\.)?([^\.]+)\.([^\.]+)$/;
82 my ($base, $r1, $r2) = ($1, $2, $3);
88 $prevrev = "$base." if $base;
89 $prevrev .= "$r1." . ($r2 - 1);