mirror of
https://github.com/opnsense/src.git
synced 2026-07-02 05:49:46 -04:00
subdirectories, and ended up making us loop forever. Add the username to the md5 of the commit to make it slightly more unique. Make the 'cvs' run quietly.
105 lines
2.1 KiB
Perl
105 lines
2.1 KiB
Perl
#!/usr/bin/perl -w
|
|
|
|
# $FreeBSD$
|
|
|
|
# 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 my $f (grep { /[^\.]/ } readdir DIR) {
|
|
my $filename = "$dir/$f";
|
|
if (-f $filename) {
|
|
my %loghash = parse_log_message($filename);
|
|
next unless %loghash;
|
|
|
|
$logs{$filename} = {%loghash};
|
|
} elsif (-d $filename) {
|
|
next if $filename =~ /\/CVS$/;
|
|
push @dirs, $filename;
|
|
}
|
|
}
|
|
close DIR;
|
|
|
|
# Produce 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 2>/dev/null |" or die $!;
|
|
my @log = <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.
|
|
my $user;
|
|
while ($e =~ s/^(date|branches):([^\n]*)\n//sg) {
|
|
my $sub = $2;
|
|
$user = $1 if $sub =~ /author: (.*?);/;
|
|
};
|
|
|
|
my $hash = string_to_hash($e);
|
|
$loghash{$rev} = "$user:$hash";
|
|
}
|
|
|
|
return %loghash;
|
|
}
|
|
|
|
|
|
##################################################
|
|
# Convert a log message into an md5 checksum.
|
|
##################################################
|
|
sub string_to_hash {
|
|
my $logmsg = shift;
|
|
|
|
return md5_hex($logmsg);
|
|
}
|
|
|
|
|
|
|
|
#end
|