Mercurial > emacs
comparison lib-src/grep-changelog @ 38551:6bd3c93022e7
(parse_changelog): Remove unused local variable.
(main): Add new option --reverse.
(print_log): Use it.
(parse_changelog): Use it.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Wed, 25 Jul 2001 13:00:30 +0000 |
parents | 951057587d19 |
children | 695cf19ef79e d7ddb3e565de |
comparison
equal
deleted
inserted
replaced
38550:f909f7fe9a65 | 38551:6bd3c93022e7 |
---|---|
21 | 21 |
22 | 22 |
23 # Extract entries from ChangeLogs matching specified criteria. | 23 # Extract entries from ChangeLogs matching specified criteria. |
24 # Optionally format the resulting output to a form suitable for RCS | 24 # Optionally format the resulting output to a form suitable for RCS |
25 # logs, like they are used in Emacs, for example. In this format, | 25 # logs, like they are used in Emacs, for example. In this format, |
26 # author lines leading spaces, and file names are removed. | 26 # author lines, leading spaces, and file names are removed. |
27 | 27 |
28 require 5; | 28 require 5; |
29 use strict; | 29 use strict; |
30 | 30 |
31 # Parse command line options. | 31 # Parse command line options. |
32 | 32 |
33 use vars qw($author $regexp $exclude $from_date $to_date | 33 use vars qw($author $regexp $exclude $from_date $to_date |
34 $rcs_log $with_date $version $help); | 34 $rcs_log $with_date $version $help $reverse |
35 @entries); | |
35 | 36 |
36 use Getopt::Long; | 37 use Getopt::Long; |
37 my $result = GetOptions ("author=s" => \$author, | 38 my $result = GetOptions ("author=s" => \$author, |
38 "text=s" => \$regexp, | 39 "text=s" => \$regexp, |
39 "exclude=s" => \$exclude, | 40 "exclude=s" => \$exclude, |
40 "from-date=s" => \$from_date, | 41 "from-date=s" => \$from_date, |
41 "to-date=s" => \$to_date, | 42 "to-date=s" => \$to_date, |
42 "rcs-log" => \$rcs_log, | 43 "rcs-log" => \$rcs_log, |
43 "with-date" => \$with_date, | 44 "with-date" => \$with_date, |
45 "reverse!" => \$reverse, | |
44 "version" => \$version, | 46 "version" => \$version, |
45 "help" => \$help); | 47 "help" => \$help); |
46 | 48 |
47 # If date options are specified, check that they have the format | 49 # If date options are specified, check that they have the format |
48 # YYYY-MM-DD. | 50 # YYYY-MM-DD. |
65 --exclude=TEXT exclude entries matching TEXT. | 67 --exclude=TEXT exclude entries matching TEXT. |
66 --from-date=YYYY-MM-DD match entries not older than given date | 68 --from-date=YYYY-MM-DD match entries not older than given date |
67 --to-date=YYYY-MM-DD match entries not younger than given date | 69 --to-date=YYYY-MM-DD match entries not younger than given date |
68 --rcs-log format output suitable for RCS log entries. | 70 --rcs-log format output suitable for RCS log entries. |
69 --with-date print short date line in RCS log | 71 --with-date print short date line in RCS log |
72 --reverse show entries in reverse (chronological) order | |
70 --version print version info | 73 --version print version info |
71 --help print this help | 74 --help print this help |
72 | 75 |
73 If no CHANGELOG is specified scan the files "ChangeLog" and | 76 If no CHANGELOG is specified scan the files "ChangeLog" and |
74 "ChangeLog.[9-1]" in the current directory. Old-style dates in ChangeLogs | 77 "ChangeLog.[9-1]" in the current directory. Old-style dates in ChangeLogs |
140 # lines are not printed, and leading spaces and file names are removed | 143 # lines are not printed, and leading spaces and file names are removed |
141 # from ChangeLog entries. | 144 # from ChangeLog entries. |
142 | 145 |
143 sub print_log ($$) { | 146 sub print_log ($$) { |
144 my ($header, $entry) = @_; | 147 my ($header, $entry) = @_; |
148 my $output = ''; | |
145 | 149 |
146 if ($rcs_log) { | 150 if ($rcs_log) { |
147 # Remove leading whitespace from entry. | 151 # Remove leading whitespace from entry. |
148 $entry =~ s/^\s+//mg; | 152 $entry =~ s/^\s+//mg; |
149 # Remove file name parts. | 153 # Remove file name parts. |
150 $entry =~ s/^\*.*\(/(/mg; | 154 $entry =~ s/^\*.*\(/(/mg; |
151 # Remove file name parts, 2. | 155 # Remove file name parts, 2. |
152 $entry =~ s/^\*.*://mg; | 156 $entry =~ s/^\*.*://mg; |
153 if ($with_date) { | 157 if ($with_date) { |
154 $header =~ /(\d\d\d\d-\d\d-\d\d)/; | 158 $header =~ /(\d\d\d\d-\d\d-\d\d)/; |
155 print "!changelog-date $1\n"; | 159 $output = "!changelog-date $1\n"; |
156 } | 160 } |
157 print $entry; | 161 $output .= $entry; |
158 } else { | 162 } else { |
159 print $header, $entry; | 163 $output .= $header . $entry; |
164 } | |
165 | |
166 if ($reverse) { | |
167 push @entries, $output; | |
168 } else { | |
169 print $output; | |
160 } | 170 } |
161 } | 171 } |
162 | 172 |
163 # Scan LOG for matching entries, and print them to standard output. | 173 # Scan LOG for matching entries, and print them to standard output. |
164 | 174 |
165 sub parse_changelog ($) { | 175 sub parse_changelog ($) { |
166 my $log = shift; | 176 my $log = shift; |
167 my $entry = undef; | 177 my $entry = undef; |
168 my $header = undef; | 178 my $header = undef; |
169 my $match; | 179 |
180 @entries = () if $reverse; | |
170 | 181 |
171 # Open the ChangeLog. | 182 # Open the ChangeLog. |
172 open (IN, "< $log") || die "Cannot open $log: $!"; | 183 open (IN, "< $log") || die "Cannot open $log: $!"; |
173 | 184 |
174 while (defined(my $line = <IN>)) { | 185 while (defined(my $line = <IN>)) { |
204 # Print last entry if it matches. | 215 # Print last entry if it matches. |
205 print_log ($header, $entry) | 216 print_log ($header, $entry) |
206 if header_match_p ($header) && entry_match_p ($entry); | 217 if header_match_p ($header) && entry_match_p ($entry); |
207 | 218 |
208 close IN; | 219 close IN; |
220 | |
221 if ($reverse) { | |
222 while (defined (my $entry = pop @entries)) { | |
223 print $entry; | |
224 } | |
225 } | |
209 } | 226 } |
210 | 227 |
211 | 228 |
212 # Main program. Process ChangeLogs. | 229 # Main program. Process ChangeLogs. |
213 | 230 |
214 if (@ARGV > 0) { | 231 # If files were specified on the command line, parse those files in the |
215 # If files were specified on the command line, parse those files. | 232 # order supplied by the user; otherwise parse default files ChangeLog and |
216 while (defined(my $log = shift @ARGV)) { | 233 # ChangeLog.9...ChangeLog.1 according to $reverse. |
217 parse_changelog ($log); | 234 unless (@ARGV > 0) { |
218 } | 235 @ARGV = ("ChangeLog", map {"ChangeLog.$_"} reverse 1..9); |
219 } else { | 236 @ARGV = reverse @ARGV if $reverse; |
220 # Parse default files ChangeLog and ChangeLog.9...ChangeLog.1 in | 237 } |
221 # that order. | 238 |
222 parse_changelog ("ChangeLog"); | 239 while (defined (my $log = shift @ARGV)) { |
223 for (my $i = 9; $i >= 1; --$i) { | 240 parse_changelog ($log) if -f $log; |
224 my $log = "ChangeLog.$i"; | |
225 parse_changelog ($log) if -f $log; | |
226 } | |
227 } | 241 } |
228 | 242 |
229 | 243 |
230 # grep-changelog ends here. | 244 # grep-changelog ends here. |