aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorGerd Moellmann2001-07-25 13:00:30 +0000
committerGerd Moellmann2001-07-25 13:00:30 +0000
commit3205760ab3c1853a2e29628aca63c994253e4864 (patch)
treedf1a79173e3e126d3fe48746044fb23366958f28 /lib-src
parent8d5b986d0f880ddbd887865ae12b403df0464168 (diff)
downloademacs-3205760ab3c1853a2e29628aca63c994253e4864.tar.gz
emacs-3205760ab3c1853a2e29628aca63c994253e4864.zip
(parse_changelog): Remove unused local variable.
(main): Add new option --reverse. (print_log): Use it. (parse_changelog): Use it.
Diffstat (limited to 'lib-src')
-rwxr-xr-xlib-src/grep-changelog52
1 files changed, 33 insertions, 19 deletions
diff --git a/lib-src/grep-changelog b/lib-src/grep-changelog
index bfd21c3f933..82a14efb383 100755
--- a/lib-src/grep-changelog
+++ b/lib-src/grep-changelog
@@ -23,7 +23,7 @@
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
28require 5; 28require 5;
29use strict; 29use strict;
@@ -31,7 +31,8 @@ use strict;
31# Parse command line options. 31# Parse command line options.
32 32
33use vars qw($author $regexp $exclude $from_date $to_date 33use 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
36use Getopt::Long; 37use Getopt::Long;
37my $result = GetOptions ("author=s" => \$author, 38my $result = GetOptions ("author=s" => \$author,
@@ -41,6 +42,7 @@ my $result = GetOptions ("author=s" => \$author,
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
@@ -67,6 +69,7 @@ are
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
@@ -142,6 +145,7 @@ sub entry_match_p ($) {
142 145
143sub print_log ($$) { 146sub 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.
@@ -152,11 +156,17 @@ sub print_log ($$) {
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
@@ -166,7 +176,8 @@ 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: $!";
@@ -206,24 +217,27 @@ sub parse_changelog ($) {
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
214if (@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); 234unless (@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"); 239while (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