5 # Copyright © 1996 Ian Jackson
6 # Copyright © 2001 Wichert Akkerman
7 # Copyright © 2006-2012 Guillem Jover <guillem@debian.org>
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <https://www.gnu.org/licenses/>.
28 use Dpkg
::ErrorHandling
;
29 use Dpkg
::Changelog
::Parse
;
31 textdomain
('dpkg-dev');
37 printf g_
("Debian %s version %s.\n"), $Dpkg::PROGNAME
, $Dpkg::PROGVERSION
;
40 This is free software; see the GNU General Public License version 2 or
41 later for copying conditions. There is NO warranty.
47 'Usage: %s [<option>...]')
50 -l, --file <changelog-file>
51 get per-version info from this file.
52 -F <changelog-format> force changelog format.
53 -S, --show-field <field> show the values for <field>.
54 -?, --help show this help message.
55 --version show the version.')
58 --format <output-format>
59 set output format (defaults to 'dpkg').
60 --reverse include all changes in reverse order.
61 --all include all changes.
62 -s, --since <version> include all changes later than <version>.
64 -u, --until <version> include all changes earlier than <version>.
65 -f, --from <version> include all changes equal or later than <version>.
66 -t, --to <version> include all changes up to or equal than <version>.
67 -c, --count <number> include <number> entries from the top (or tail
68 if <number> is lower than 0).
70 -o, --offset <number> change starting point for --count, counted from
71 the top (or tail if <number> is lower than 0).
75 @ARGV = normalize_options
(args
=> \
@ARGV, delim
=> '--');
78 last unless $ARGV[0] =~ m/^-/;
84 } elsif ($arg eq '-L') {
85 warning
(g_
('-L is obsolete; it is without effect'));
86 } elsif ($arg eq '-F') {
87 $options{changelogformat
} = shift;
88 usageerr
(g_
('bad changelog format name'))
89 unless length $options{changelogformat
} and
90 $options{changelogformat
} =~ m/^([0-9a-z]+)$/;
91 } elsif ($arg eq '--format') {
92 $options{format
} = shift;
93 } elsif ($arg eq '--reverse') {
94 $options{reverse} = 1;
95 } elsif ($arg eq '-l' or $arg eq '--file') {
96 $options{file
} = shift;
97 usageerr
(g_
('missing changelog filename'))
98 unless length $options{file
};
99 } elsif ($arg eq '-S' or $arg eq '--show-field') {
101 } elsif ($arg eq '-c' or $arg eq '--count' or $arg eq '-n') {
102 $options{count
} = shift;
103 } elsif ($arg eq '-f' or $arg eq '--from') {
104 $options{from
} = shift;
105 } elsif ($arg eq '-o' or $arg eq '--offset') {
106 $options{offset
} = shift;
107 } elsif ($arg eq '-s' or $arg eq '--since' or $arg eq '-v') {
108 $options{since
} = shift;
109 } elsif ($arg eq '-t' or $arg eq '--to') {
110 $options{to
} = shift;
111 } elsif ($arg eq '-u' or $arg eq '--until') {
112 ## no critic (ControlStructures::ProhibitUntilBlocks)
113 $options{until} = shift;
115 } elsif ($arg eq '--all') {
116 $options{all
} = undef;
117 } elsif ($arg eq '-?' or $arg eq '--help') {
119 } elsif ($arg eq '--version') {
122 usageerr
(g_
("unknown option '%s'"), $arg);
125 usageerr
(g_
('takes no non-option arguments')) if @ARGV;
128 my @fields = changelog_parse
(%options);
129 foreach my $f (@fields) {
130 print "\n" if $count++;
132 next if not exists $f->{$fieldname};
134 my ($first_line, @lines) = split /\n/, $f->{$fieldname};
137 $v .= $first_line if length $first_line;
141 if (length == 0 or /^\.+$/) {