3 # Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
4 # 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
6 # This file is part of GNU Emacs.
8 # GNU Emacs is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # GNU Emacs is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22 # Extract entries from ChangeLogs matching specified criteria.
23 # Optionally format the resulting output to a form suitable for RCS
24 # logs, like they are used in Emacs, for example. In this format,
25 # author lines, leading spaces, and file names are removed.
30 # Parse command line options.
32 use vars
qw($author $regexp $exclude $from_date $to_date
33 $rcs_log $with_date $version $help $reverse
42 # No arguments cannot possibly mean "show everything"!!
47 $result = GetOptions ("author=s" => \$author,
49 "exclude=s" => \$exclude,
50 "from-date=s" => \$from_date,
51 "to-date=s" => \$to_date,
52 "rcs-log" => \$rcs_log,
53 "with-date" => \$with_date,
54 "reverse!" => \$reverse,
55 "version" => \$version,
58 # If date options are specified, check that they have the format
61 $result = 0 if $from_date && $from_date !~ /^\d\d\d\d-\d\d-\d\d$/;
62 $result = 0 if $to_date && $to_date !~ /^\d\d\d\d-\d\d-\d\d$/;
65 # Print usage information and exit when necessary.
67 if ($result == 0 || $help) {
70 Usage: $0 [options] [CHANGELOG...]
72 Print entries in ChangeLogs matching various criteria.
75 --author=AUTHOR Match entries whose author line matches
76 regular expression AUTHOR
77 --text=TEXT Match entries whose text matches regular
79 --exclude=TEXT Exclude entries matching TEXT
80 --from-date=YYYY-MM-DD Match entries not older than given date
81 --to-date=YYYY-MM-DD Match entries not younger than given date
82 --rcs-log Format output suitable for RCS log entries
83 --with-date Print short date line in RCS log
84 --reverse Show entries in reverse (chronological) order
85 --version Print version info
86 --help Print this help
88 If no CHANGELOG is specified scan the files "ChangeLog" and
89 "ChangeLog.N+" in the current directory. Old-style dates in ChangeLogs
95 # Print version info and exit if `--version' was specified.
103 # Value is non-zero if HEADER matches according to command line
104 # options specified, i.e. it matches $author, and its date is in
105 # the range $from_date <= date <= $to_date.
110 return 0 unless $header;
112 # No match if AUTHOR-regexp specified and doesn't match.
113 return 0 if $author && $header !~ /$author/;
115 # Check that the date of the entry matches if date options
116 # `--from-date' and/or `--to-date' were specified . Old-style
117 # dates in ChangeLogs are not recognized, and never match.
118 if ($from_date || $to_date) {
119 if ($header =~ /^(\d\d\d\d-\d\d-\d\d)/) {
121 return 0 if $from_date && $date lt $from_date;
122 return 0 if $to_date && $date gt $to_date;
124 # Don't bother recognizing old-style dates.
133 # Value is non-zero if ENTRY matches the criteria specified on the
134 # command line, i.e. it matches $regexp, and it doesn't match
140 return 0 unless $entry;
143 return 1 if ($entry =~ /$regexp/
144 && (!$exclude || $entry !~ $exclude));
146 return 1 if !$exclude || $entry !~ $exclude;
153 # Print HEADER and/or ENTRY in a format suitable for what was
154 # specified on the command line. If $rcs_log is specified, author
155 # lines are not printed, and leading spaces and file names are removed
156 # from ChangeLog entries.
159 my ($header, $entry) = @_;
163 # Remove leading whitespace from entry.
164 $entry =~ s/^\s+//mg;
165 # Remove file name parts.
166 $entry =~ s/^\*.*\(/(/mg;
167 # Remove file name parts, 2.
168 $entry =~ s/^\*.*://mg;
170 $header =~ /(\d\d\d\d-\d\d-\d\d)/;
171 $output = "!changelog-date $1\n";
175 $output .= $header . $entry;
179 push @entries, $output;
185 # Scan LOG for matching entries, and print them to standard output.
187 sub parse_changelog
{
192 @entries = () if $reverse;
194 # Open the ChangeLog.
195 open (IN
, "< $log") || die "Cannot open $log: $!";
197 while (defined(my $line = <IN
>)) {
198 if ($line =~ /^\S/) {
199 # Line is an author-line. Print previous entry if
201 print_log
($header, $entry)
202 if header_match_p
($header) && entry_match_p
($entry);
207 # Add empty lines below the header.
208 while (defined($line = <IN
>) && $line =~ /^\s*$/) {
209 $header = "$header$line";
213 last unless defined $line;
215 if ($line =~ /^\s*\*/) {
216 # LINE is the first line of a ChangeLog entry. Print
217 # previous entry if it matches.
218 print_log
($header, $entry)
219 if header_match_p
($header) && entry_match_p
($entry);
222 # Add LINE to the current entry.
223 $entry = "$entry$line";
227 # Print last entry if it matches.
228 print_log
($header, $entry)
229 if header_match_p
($header) && entry_match_p
($entry);
234 for (my $entry = @entries; $entry; $entry--) {
235 print $entries[$entry-1];
241 # Main program. Process ChangeLogs.
243 # If files were specified on the command line, parse those files in the
244 # order supplied by the user; otherwise parse default files ChangeLog and
245 # ChangeLog.NNN according to $reverse.
247 @ARGV = ("ChangeLog");
255 grep /^ChangeLog\.\d+$/, readdir D
;
258 @ARGV = reverse @ARGV if $reverse;
261 while (defined (my $log = shift @ARGV)) {
262 parse_changelog
($log) if -f
$log;
266 # arch-tag: 9e4f6749-e053-4bb7-b3ad-11947318418e
267 # grep-changelog ends here.