Mercurial > emacs
annotate lib-src/grep-changelog @ 38510:951057587d19
Remove RCS Id keyword.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Fri, 20 Jul 2001 11:06:36 +0000 |
parents | 59acf1c91dd2 |
children | 6bd3c93022e7 |
rev | line source |
---|---|
28823 | 1 #! /usr/bin/perl |
25216 | 2 |
38500
3db3b0888252
(parse_changelog): Add test for defined value to
Gerd Moellmann <gerd@gnu.org>
parents:
29638
diff
changeset
|
3 # Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. |
25216 | 4 # |
5 # This file is part of GNU Emacs. | |
6 # | |
7 # GNU Emacs is free software; you can redistribute it and/or modify | |
8 # it under the terms of the GNU General Public License as published by | |
9 # the Free Software Foundation; either version 2, or (at your option) | |
10 # any later version. | |
11 # | |
12 # GNU Emacs is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU General Public License for more details. | |
16 # | |
17 # You should have received a copy of the GNU General Public License | |
18 # along with GNU Emacs; see the file COPYING. If not, write to the | |
19 # Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 # Boston, MA 02111-1307, USA. | |
21 | |
22 | |
23 # Extract entries from ChangeLogs matching specified criteria. | |
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, | |
26 # author lines leading spaces, and file names are removed. | |
27 | |
28 require 5; | |
38509
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
29 use strict; |
25216 | 30 |
31 # Parse command line options. | |
32 | |
38509
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
33 use vars qw($author $regexp $exclude $from_date $to_date |
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
34 $rcs_log $with_date $version $help); |
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
35 |
25216 | 36 use Getopt::Long; |
38509
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
37 my $result = GetOptions ("author=s" => \$author, |
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
38 "text=s" => \$regexp, |
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
39 "exclude=s" => \$exclude, |
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
40 "from-date=s" => \$from_date, |
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
41 "to-date=s" => \$to_date, |
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
42 "rcs-log" => \$rcs_log, |
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
43 "with-date" => \$with_date, |
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
44 "version" => \$version, |
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
45 "help" => \$help); |
25216 | 46 |
47 # If date options are specified, check that they have the format | |
48 # YYYY-MM-DD. | |
49 | |
50 $result = 0 if $from_date && $from_date !~ /^\d\d\d\d-\d\d-\d\d$/; | |
51 $result = 0 if $to_date && $to_date !~ /^\d\d\d\d-\d\d-\d\d$/; | |
52 | |
53 # Print usage information and exit when necessary. | |
54 | |
55 if ($result == 0 || $help) { | |
56 print <<USAGE; | |
57 Usage: $0 [options] [CHANGELOG...] | |
58 Print entries in ChangeLogs matching various criteria. Valid options | |
59 are | |
60 | |
29638
f6a97d806845
Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents:
28823
diff
changeset
|
61 --author=AUTHOR match entries whose author line matches |
25216 | 62 regular expression AUTHOR |
63 --text=TEXT match entries whose text matches regular | |
64 expression TEXT. | |
65 --exclude=TEXT exclude entries matching TEXT. | |
66 --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 | |
68 --rcs-log format output suitable for RCS log entries. | |
69 --with-date print short date line in RCS log | |
70 --version print version info | |
71 --help print this help | |
72 | |
73 If no CHANGELOG is specified scan the files "ChangeLog" and | |
29638
f6a97d806845
Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents:
28823
diff
changeset
|
74 "ChangeLog.[9-1]" in the current directory. Old-style dates in ChangeLogs |
25216 | 75 are not recognized. |
76 USAGE | |
77 exit $help ? 0 : 1; | |
78 } | |
79 | |
80 # Print version info and exit if `--version' was specified. | |
81 | |
82 if ($version) { | |
83 print "0.1\n"; | |
84 exit 0; | |
85 } | |
86 | |
87 | |
88 # Value is non-zero if HEADER matches according to command line | |
89 # options specified, i.e. it matches $author, and its date is in | |
90 # the range $from_date <= date <= $to_date. | |
91 | |
92 sub header_match_p ($) { | |
93 my $header = shift; | |
94 | |
38502
180f542bf5b4
(entry_match_p, header_match_p): Fix handling of null or empty
Gerd Moellmann <gerd@gnu.org>
parents:
38500
diff
changeset
|
95 return 0 unless $header; |
180f542bf5b4
(entry_match_p, header_match_p): Fix handling of null or empty
Gerd Moellmann <gerd@gnu.org>
parents:
38500
diff
changeset
|
96 |
25216 | 97 # No match if AUTHOR-regexp specified and doesn't match. |
98 return 0 if $author && $header !~ /$author/; | |
99 | |
100 # Check that the date of the entry matches if date options | |
101 # `--from-date' and/or `--to-date' were specified . Old-style | |
102 # dates in ChangeLogs are not recognized, and never match. | |
103 if ($from_date || $to_date) { | |
104 if ($header =~ /^(\d\d\d\d-\d\d-\d\d)/) { | |
105 my $date = $1; | |
106 return 0 if $from_date && $date lt $from_date; | |
107 return 0 if $to_date && $date gt $to_date; | |
108 } else { | |
109 # Don't bother recognizing old-style dates. | |
110 return 0; | |
111 } | |
112 } | |
113 | |
114 return 1; | |
115 } | |
116 | |
117 | |
29638
f6a97d806845
Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents:
28823
diff
changeset
|
118 # Value is non-zero if ENTRY matches the criteria specified on the |
25216 | 119 # command line, i.e. it matches $regexp, and it doesn't match |
120 # $exclude. | |
121 | |
122 sub entry_match_p ($) { | |
123 my $entry = shift; | |
124 | |
38502
180f542bf5b4
(entry_match_p, header_match_p): Fix handling of null or empty
Gerd Moellmann <gerd@gnu.org>
parents:
38500
diff
changeset
|
125 return 0 unless $entry; |
180f542bf5b4
(entry_match_p, header_match_p): Fix handling of null or empty
Gerd Moellmann <gerd@gnu.org>
parents:
38500
diff
changeset
|
126 |
25216 | 127 if ($regexp) { |
29638
f6a97d806845
Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents:
28823
diff
changeset
|
128 return 1 if ($entry =~ /$regexp/ |
25216 | 129 && (!$exclude || $entry !~ $exclude)); |
130 } else { | |
131 return 1 if !$exclude || $entry !~ $exclude; | |
132 } | |
133 | |
134 return 0; | |
135 } | |
136 | |
137 | |
138 # Print HEADER and/or ENTRY in a format suitable for what was | |
139 # specified on the command line. If $rcs_log is specified, author | |
140 # lines are not printed, and leading spaces and file names are removed | |
141 # from ChangeLog entries. | |
142 | |
143 sub print_log ($$) { | |
144 my ($header, $entry) = @_; | |
145 | |
146 if ($rcs_log) { | |
147 # Remove leading whitespace from entry. | |
148 $entry =~ s/^\s+//mg; | |
149 # Remove file name parts. | |
150 $entry =~ s/^\*.*\(/(/mg; | |
151 # Remove file name parts, 2. | |
152 $entry =~ s/^\*.*://mg; | |
153 if ($with_date) { | |
154 $header =~ /(\d\d\d\d-\d\d-\d\d)/; | |
155 print "!changelog-date $1\n"; | |
156 } | |
157 print $entry; | |
158 } else { | |
159 print $header, $entry; | |
160 } | |
161 } | |
162 | |
163 # Scan LOG for matching entries, and print them to standard output. | |
164 | |
165 sub parse_changelog ($) { | |
166 my $log = shift; | |
38509
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
167 my $entry = undef; |
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
168 my $header = undef; |
25216 | 169 my $match; |
170 | |
171 # Open the ChangeLog. | |
172 open (IN, "< $log") || die "Cannot open $log: $!"; | |
173 | |
38509
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
174 while (defined(my $line = <IN>)) { |
25216 | 175 if ($line =~ /^\S/) { |
176 # Line is an author-line. Print previous entry if | |
177 # it matches. | |
29638
f6a97d806845
Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents:
28823
diff
changeset
|
178 print_log ($header, $entry) |
25216 | 179 if header_match_p ($header) && entry_match_p ($entry); |
180 | |
181 $entry = ""; | |
182 $header = $line; | |
183 | |
184 # Add empty lines below the header. | |
38500
3db3b0888252
(parse_changelog): Add test for defined value to
Gerd Moellmann <gerd@gnu.org>
parents:
29638
diff
changeset
|
185 while (defined($line = <IN>) && $line =~ /^\s*$/) { |
25216 | 186 $header = "$header$line"; |
187 } | |
29638
f6a97d806845
Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents:
28823
diff
changeset
|
188 } |
25216 | 189 |
38504
1d53627a58ae
(parse_changelog): Add another test for defined value to
Gerd Moellmann <gerd@gnu.org>
parents:
38502
diff
changeset
|
190 last unless defined $line; |
1d53627a58ae
(parse_changelog): Add another test for defined value to
Gerd Moellmann <gerd@gnu.org>
parents:
38502
diff
changeset
|
191 |
25216 | 192 if ($line =~ /^\s*\*/) { |
193 # LINE is the first line of a ChangeLog entry. Print | |
194 # previous entry if it matches. | |
29638
f6a97d806845
Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents:
28823
diff
changeset
|
195 print_log ($header, $entry) |
25216 | 196 if header_match_p ($header) && entry_match_p ($entry); |
197 $entry = $line; | |
198 } else { | |
199 # Add LINE to the current entry. | |
200 $entry = "$entry$line"; | |
201 } | |
202 } | |
203 | |
204 # Print last entry if it matches. | |
29638
f6a97d806845
Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents:
28823
diff
changeset
|
205 print_log ($header, $entry) |
25216 | 206 if header_match_p ($header) && entry_match_p ($entry); |
207 | |
208 close IN; | |
209 } | |
210 | |
211 | |
212 # Main program. Process ChangeLogs. | |
213 | |
214 if (@ARGV > 0) { | |
215 # If files were specified on the command line, parse those files. | |
38509
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
216 while (defined(my $log = shift @ARGV)) { |
25216 | 217 parse_changelog ($log); |
218 } | |
219 } else { | |
220 # Parse default files ChangeLog and ChangeLog.9...ChangeLog.1 in | |
221 # that order. | |
222 parse_changelog ("ChangeLog"); | |
38509
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
223 for (my $i = 9; $i >= 1; --$i) { |
25216 | 224 my $log = "ChangeLog.$i"; |
225 parse_changelog ($log) if -f $log; | |
226 } | |
227 } | |
228 | |
229 | |
29638
f6a97d806845
Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents:
28823
diff
changeset
|
230 # grep-changelog ends here. |