2 # diffstat -- lintian collection script for source packages
4 # Copyright (C) 1998 Richard Braakman
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, you can find it on the World Wide
18 # Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
19 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
22 # This could be written more easily in shell script, but I'm trying
23 # to keep everything as perl to cut down on the number of processes
24 # that need to be started in a lintian scan. Eventually all the
25 # perl code will be perl modules, so only one perl interpreter
30 my $LINTIAN_ROOT = $ENV{'LINTIAN_ROOT'} || '/usr/share/lintian';
32 ($#ARGV == 1) or fail("syntax: diffstat <pkg>");
35 -f "fields/version" or fail("diffstat invoked in wrong directory");
37 open (V, '<', "fields/version") or fail("cannot open fields/version: $!");
38 my $ver = <V>; chomp $ver;
41 $ver =~ s/^\d://; #Remove epoch for this
43 my $diff_file = "${pkg}_${ver}.diff.gz";
44 unless (-f $diff_file) {
45 # we have to write an empty file so that the checks don't crap out. <sigh>
46 open (D, '>', "diffstat"); close D;
50 use lib "$ENV{'LINTIAN_ROOT'}/lib";
52 pipeline((sub { exec('gzip', '-dc', $diff_file); }),
56 open (STAT, '>', "diffstat") or fail("cannot open scripts output file: $!");
57 # diffstat is noisy on stderr if its stdout is not a tty.
58 # Shut it up by redirecting stderr to /dev/null.
59 open STDERR, ">/dev/null";
60 open (DIFF, '-|', qw/diffstat -p1 debian-patch/)
61 or fail("cannot open pipe to diffstat on debian-patch: $!");
62 # Copy all except last line to the STAT file
65 print STAT $previous if $previous;
68 close DIFF or fail("cannot close pipe to diffstat on debian-patch: $!");
69 close STAT or fail("error writing diffstat file: $!");
73 # -----------------------------------
77 print STDERR "internal error: $_[0]\n";
79 print STDERR "internal error: $!\n";
81 print STDERR "internal error.\n";