123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- require 5;
- use strict;
- use vars qw($author $regexp $exclude $from_date $to_date
- $rcs_log $with_date $version $help $reverse
- @entries);
- use Getopt::Long;
- my $result;
- if (@ARGV == 0) {
-
- $result = 0;
- } else {
- $result = GetOptions ("author=s" => \$author,
- "text=s" => \$regexp,
- "exclude=s" => \$exclude,
- "from-date=s" => \$from_date,
- "to-date=s" => \$to_date,
- "rcs-log" => \$rcs_log,
- "with-date" => \$with_date,
- "reverse!" => \$reverse,
- "version" => \$version,
- "help" => \$help);
-
-
- $result = 0 if $from_date && $from_date !~ /^\d\d\d\d-\d\d-\d\d$/;
- $result = 0 if $to_date && $to_date !~ /^\d\d\d\d-\d\d-\d\d$/;
- }
- if ($result == 0 || $help) {
- print <<USAGE;
- Usage: $0 [options] [CHANGELOG...]
- Print entries in ChangeLogs matching various criteria.
- Valid options are:
- --author=AUTHOR Match entries whose author line matches
- regular expression AUTHOR
- --text=TEXT Match entries whose text matches regular
- expression TEXT
- --exclude=TEXT Exclude entries matching TEXT
- --from-date=YYYY-MM-DD Match entries not older than given date
- --to-date=YYYY-MM-DD Match entries not younger than given date
- --rcs-log Format output suitable for RCS log entries
- --with-date Print short date line in RCS log
- --reverse Show entries in reverse (chronological) order
- --version Print version info
- --help Print this help
- If no CHANGELOG is specified scan the files "ChangeLog" and
- "ChangeLog.N+" in the current directory. Old-style dates in ChangeLogs
- are not recognized.
- USAGE
- exit !$help;
- }
- if ($version) {
- print "0.3\n";
- exit 0;
- }
- sub header_match_p {
- my $header = shift;
- return 0 unless $header;
-
- return 0 if $author && $header !~ /$author/;
-
-
-
- if ($from_date || $to_date) {
- if ($header =~ /^(\d\d\d\d-\d\d-\d\d)/) {
- my $date = $1;
- return 0 if $from_date && $date lt $from_date;
- return 0 if $to_date && $date gt $to_date;
- } else {
-
- return 0;
- }
- }
- return 1;
- }
- sub entry_match_p {
- my $entry = shift;
- return 0 unless $entry;
- if ($regexp) {
- return 1 if ($entry =~ /$regexp/
- && (!$exclude || $entry !~ $exclude));
- } else {
- return 1 if !$exclude || $entry !~ $exclude;
- }
- return 0;
- }
- sub print_log {
- my ($header, $entry) = @_;
- my $output = '';
- if ($rcs_log) {
-
- $entry =~ s/^\s+//mg;
-
- $entry =~ s/^\*.*\(/(/mg;
-
- $entry =~ s/^\*.*://mg;
- if ($with_date) {
- $header =~ /(\d\d\d\d-\d\d-\d\d)/;
- $output = "!changelog-date $1\n";
- }
- $output .= $entry;
- } else {
- $output .= $header . $entry;
- }
- if ($reverse) {
- push @entries, $output;
- } else {
- print $output;
- }
- }
- sub parse_changelog {
- my $log = shift;
- my $entry = undef;
- my $header = undef;
- @entries = () if $reverse;
-
- open (IN, "< $log") || die "Cannot open $log: $!";
- while (defined(my $line = <IN>)) {
- if ($line =~ /^\S/) {
-
-
- print_log ($header, $entry)
- if header_match_p ($header) && entry_match_p ($entry);
- $entry = "";
- $header = $line;
-
- while (defined($line = <IN>) && $line =~ /^\s*$/) {
- $header = "$header$line";
- }
- }
- last unless defined $line;
- if ($line =~ /^\s*\*/) {
-
-
- print_log ($header, $entry)
- if header_match_p ($header) && entry_match_p ($entry);
- $entry = $line;
- } else {
-
- $entry = "$entry$line";
- }
- }
-
- print_log ($header, $entry)
- if header_match_p ($header) && entry_match_p ($entry);
- close IN;
- if ($reverse) {
- for (my $entry = @entries; $entry; $entry--) {
- print $entries[$entry-1];
- }
- }
- }
- unless (@ARGV > 0) {
- @ARGV = ("ChangeLog");
- push @ARGV,
- map {"ChangeLog.$_"}
- sort {$b <=> $a}
- map {/\.(\d+)$/; $1}
- do {
- opendir D, '.';
- grep /^ChangeLog\.\d+$/, readdir D;
- };
- @ARGV = reverse @ARGV if $reverse;
- }
- while (defined (my $log = shift @ARGV)) {
- parse_changelog ($log) if -f $log;
- }
|