annotate lib-src/grep-changelog @ 74346:7318aed68fe7

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Fri, 01 Dec 2006 00:47:25 +0000
parents 3e566ec9ef5d
children 3d45362f1d38 02cf29720f31
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28823
72c6f8275e0b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents: 25216
diff changeset
1 #! /usr/bin/perl
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
64769
6358e3c6075c Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64083
diff changeset
3 # Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
68647
3661e9b3c48f Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64769
diff changeset
4 # 2005, 2006 Free Software Foundation, Inc.
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5 #
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 # This file is part of GNU Emacs.
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7 #
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8 # GNU Emacs is free software; you can redistribute it and/or modify
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9 # it under the terms of the GNU General Public License as published by
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10 # the Free Software Foundation; either version 2, or (at your option)
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11 # any later version.
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12 #
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 # GNU Emacs is distributed in the hope that it will be useful,
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 # GNU General Public License for more details.
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 #
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 # You should have received a copy of the GNU General Public License
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 # along with GNU Emacs; see the file COPYING. If not, write to the
64083
23a17af379b1 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 54324
diff changeset
20 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23a17af379b1 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 54324
diff changeset
21 # Boston, MA 02110-1301, USA.
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24 # Extract entries from ChangeLogs matching specified criteria.
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25 # Optionally format the resulting output to a form suitable for RCS
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26 # logs, like they are used in Emacs, for example. In this format,
38551
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
27 # author lines, leading spaces, and file names are removed.
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 require 5;
38509
59acf1c91dd2 (main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents: 38504
diff changeset
30 use strict;
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 # Parse command line options.
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33
38509
59acf1c91dd2 (main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents: 38504
diff changeset
34 use vars qw($author $regexp $exclude $from_date $to_date
38551
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
35 $rcs_log $with_date $version $help $reverse
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
36 @entries);
38509
59acf1c91dd2 (main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents: 38504
diff changeset
37
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38 use Getopt::Long;
73621
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
39
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
40 my $result;
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
41
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
42 if (@ARGV == 0) {
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
43
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
44 # No arguments cannot posibly mean "show everything"!!
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
45 $result = 0;
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
46
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
47 } else {
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48
73621
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
49 $result = GetOptions ("author=s" => \$author,
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
50 "text=s" => \$regexp,
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
51 "exclude=s" => \$exclude,
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
52 "from-date=s" => \$from_date,
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
53 "to-date=s" => \$to_date,
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
54 "rcs-log" => \$rcs_log,
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
55 "with-date" => \$with_date,
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
56 "reverse!" => \$reverse,
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
57 "version" => \$version,
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
58 "help" => \$help);
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59
73621
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
60 # If date options are specified, check that they have the format
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
61 # YYYY-MM-DD.
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
62
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
63 $result = 0 if $from_date && $from_date !~ /^\d\d\d\d-\d\d-\d\d$/;
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
64 $result = 0 if $to_date && $to_date !~ /^\d\d\d\d-\d\d-\d\d$/;
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
65 }
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 # Print usage information and exit when necessary.
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 if ($result == 0 || $help) {
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 print <<USAGE;
54324
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
71
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 Usage: $0 [options] [CHANGELOG...]
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73
54324
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
74 Print entries in ChangeLogs matching various criteria.
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
75 Valid options are:
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
76
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
77 --author=AUTHOR Match entries whose author line matches
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 regular expression AUTHOR
54324
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
79 --text=TEXT Match entries whose text matches regular
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
80 expression TEXT
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
81 --exclude=TEXT Exclude entries matching TEXT
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
82 --from-date=YYYY-MM-DD Match entries not older than given date
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
83 --to-date=YYYY-MM-DD Match entries not younger than given date
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
84 --rcs-log Format output suitable for RCS log entries
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
85 --with-date Print short date line in RCS log
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
86 --reverse Show entries in reverse (chronological) order
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
87 --version Print version info
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
88 --help Print this help
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 If no CHANGELOG is specified scan the files "ChangeLog" and
73621
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
91 "ChangeLog.N+" in the current directory. Old-style dates in ChangeLogs
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 are not recognized.
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 USAGE
54324
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
94 exit !$help;
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 }
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97 # Print version info and exit if `--version' was specified.
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 if ($version) {
73621
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
100 print "0.3\n";
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 exit 0;
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 }
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 # Value is non-zero if HEADER matches according to command line
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106 # options specified, i.e. it matches $author, and its date is in
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107 # the range $from_date <= date <= $to_date.
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108
54324
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
109 sub header_match_p {
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 my $header = shift;
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111
38502
180f542bf5b4 (entry_match_p, header_match_p): Fix handling of null or empty
Gerd Moellmann <gerd@gnu.org>
parents: 38500
diff changeset
112 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
113
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114 # No match if AUTHOR-regexp specified and doesn't match.
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 return 0 if $author && $header !~ /$author/;
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117 # Check that the date of the entry matches if date options
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118 # `--from-date' and/or `--to-date' were specified . Old-style
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 # dates in ChangeLogs are not recognized, and never match.
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120 if ($from_date || $to_date) {
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
121 if ($header =~ /^(\d\d\d\d-\d\d-\d\d)/) {
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
122 my $date = $1;
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
123 return 0 if $from_date && $date lt $from_date;
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124 return 0 if $to_date && $date gt $to_date;
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 } else {
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126 # Don't bother recognizing old-style dates.
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
127 return 0;
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128 }
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129 }
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131 return 1;
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132 }
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134
29638
f6a97d806845 Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents: 28823
diff changeset
135 # Value is non-zero if ENTRY matches the criteria specified on the
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 # command line, i.e. it matches $regexp, and it doesn't match
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 # $exclude.
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138
54324
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
139 sub entry_match_p {
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140 my $entry = shift;
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141
38502
180f542bf5b4 (entry_match_p, header_match_p): Fix handling of null or empty
Gerd Moellmann <gerd@gnu.org>
parents: 38500
diff changeset
142 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
143
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 if ($regexp) {
29638
f6a97d806845 Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents: 28823
diff changeset
145 return 1 if ($entry =~ /$regexp/
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 && (!$exclude || $entry !~ $exclude));
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 } else {
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148 return 1 if !$exclude || $entry !~ $exclude;
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149 }
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151 return 0;
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
152 }
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 # Print HEADER and/or ENTRY in a format suitable for what was
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 # specified on the command line. If $rcs_log is specified, author
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157 # lines are not printed, and leading spaces and file names are removed
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158 # from ChangeLog entries.
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159
54324
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
160 sub print_log {
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161 my ($header, $entry) = @_;
38551
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
162 my $output = '';
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164 if ($rcs_log) {
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165 # Remove leading whitespace from entry.
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 $entry =~ s/^\s+//mg;
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 # Remove file name parts.
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168 $entry =~ s/^\*.*\(/(/mg;
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
169 # Remove file name parts, 2.
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
170 $entry =~ s/^\*.*://mg;
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 if ($with_date) {
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172 $header =~ /(\d\d\d\d-\d\d-\d\d)/;
38551
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
173 $output = "!changelog-date $1\n";
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 }
38551
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
175 $output .= $entry;
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176 } else {
38551
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
177 $output .= $header . $entry;
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
178 }
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
179
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
180 if ($reverse) {
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
181 push @entries, $output;
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
182 } else {
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
183 print $output;
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
184 }
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185 }
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
186
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187 # Scan LOG for matching entries, and print them to standard output.
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188
54324
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
189 sub parse_changelog {
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190 my $log = shift;
38509
59acf1c91dd2 (main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents: 38504
diff changeset
191 my $entry = undef;
59acf1c91dd2 (main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents: 38504
diff changeset
192 my $header = undef;
38551
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
193
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
194 @entries = () if $reverse;
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196 # Open the ChangeLog.
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
197 open (IN, "< $log") || die "Cannot open $log: $!";
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
198
38509
59acf1c91dd2 (main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents: 38504
diff changeset
199 while (defined(my $line = <IN>)) {
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200 if ($line =~ /^\S/) {
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
201 # Line is an author-line. Print previous entry if
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202 # it matches.
29638
f6a97d806845 Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents: 28823
diff changeset
203 print_log ($header, $entry)
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204 if header_match_p ($header) && entry_match_p ($entry);
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206 $entry = "";
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207 $header = $line;
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209 # 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
210 while (defined($line = <IN>) && $line =~ /^\s*$/) {
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211 $header = "$header$line";
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212 }
29638
f6a97d806845 Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents: 28823
diff changeset
213 }
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214
38504
1d53627a58ae (parse_changelog): Add another test for defined value to
Gerd Moellmann <gerd@gnu.org>
parents: 38502
diff changeset
215 last unless defined $line;
1d53627a58ae (parse_changelog): Add another test for defined value to
Gerd Moellmann <gerd@gnu.org>
parents: 38502
diff changeset
216
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
217 if ($line =~ /^\s*\*/) {
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218 # LINE is the first line of a ChangeLog entry. Print
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 # previous entry if it matches.
29638
f6a97d806845 Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents: 28823
diff changeset
220 print_log ($header, $entry)
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
221 if header_match_p ($header) && entry_match_p ($entry);
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
222 $entry = $line;
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
223 } else {
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
224 # Add LINE to the current entry.
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
225 $entry = "$entry$line";
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226 }
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
227 }
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229 # Print last entry if it matches.
29638
f6a97d806845 Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents: 28823
diff changeset
230 print_log ($header, $entry)
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
231 if header_match_p ($header) && entry_match_p ($entry);
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
232
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
233 close IN;
38551
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
234
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
235 if ($reverse) {
54324
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
236 for (my $entry = @entries; $entry; $entry--) {
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
237 print $entries[$entry-1];
38551
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
238 }
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
239 }
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
240 }
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
241
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
242
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
243 # Main program. Process ChangeLogs.
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
244
38551
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
245 # If files were specified on the command line, parse those files in the
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
246 # order supplied by the user; otherwise parse default files ChangeLog and
73621
3e566ec9ef5d When called with no arguments (not even a filter), show help instead of
Juanma Barranquero <lekktu@gmail.com>
parents: 68647
diff changeset
247 # ChangeLog.NNN according to $reverse.
38551
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
248 unless (@ARGV > 0) {
54324
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
249 @ARGV = ("ChangeLog");
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
250
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
251 push @ARGV,
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
252 map {"ChangeLog.$_"}
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
253 sort {$b <=> $a}
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
254 map {/\.(\d+)$/; $1}
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
255 do {
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
256 opendir D, '.';
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
257 grep /^ChangeLog\.\d+$/, readdir D;
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
258 };
bdf4aa3226e7 Changes to support ChangeLog.10+.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
259
38551
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
260 @ARGV = reverse @ARGV if $reverse;
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
261 }
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
262
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
263 while (defined (my $log = shift @ARGV)) {
6bd3c93022e7 (parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents: 38510
diff changeset
264 parse_changelog ($log) if -f $log;
25216
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
265 }
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
266
40dc181e545b Initial revision
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
267
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 38551
diff changeset
268 # arch-tag: 9e4f6749-e053-4bb7-b3ad-11947318418e
29638
f6a97d806845 Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents: 28823
diff changeset
269 # grep-changelog ends here.