5 # This script takes a filename and revision number as arguments
6 # and spits out a list of other files and their revisions that share
7 # the same log message. This is done by referring to the database
8 # previously written by running make_commit_db.
11 use Digest::MD5 qw(md5_hex);
13 my $dbname = "commitsdb";
15 # Take the filename and revision number from the command line.
16 # Also take a flag to say whether to generate a patch or not.
17 my ($file, $revision, $genpatch) = (shift, shift, shift);
19 # Find the checksum of the named revision.
21 open DB, "< $dbname" or die "$!\n";
25 my ($name, $rev, $hash) = split;
28 $possible_files{$name} = 1 if $file !~ /\// && $name =~ /^.*\/$file/;
30 next unless $name eq $file and $rev eq $revision;
35 # Handle the fall-out if the file/revision wasn't matched.
37 if (%possible_files) {
38 print "Couldn't find the file. Maybe you meant:\n";
39 foreach (sort keys %possible_files) {
43 die "Can't find $file rev $revision in database\n";
47 # Look for similar revisions.
49 open DB, "< $dbname" or die "$!\n";
52 my ($name, $rev, $hash) = split;
54 next unless $hash eq $cksum;
56 push @results, "$name $rev";
60 # May as well show the log message if we're producing a patch
61 print `cvs log -r$revision $file` if $genpatch;
63 # Show the commits that match, and their patches if required.
64 foreach my $r (sort @results) {
66 next unless $genpatch;
68 my ($name, $rev) = split /\s/, $r, 2;
69 my $prevrev = previous_revision($rev);
70 print `cvs diff -u -r$prevrev -r$rev $name`;
75 # Return the previous revision number.
77 sub previous_revision {
80 $rev =~ /(?:(.*)\.)?([^\.]+)\.([^\.]+)$/;
81 my ($base, $r1, $r2) = ($1, $2, $3);
87 $prevrev = "$base." if $base;
88 $prevrev .= "$r1." . ($r2 - 1);