File: diff-tarballs

package info (click to toggle)
doc-linux-nonfree 2006.09-1
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 3,412 kB
  • ctags: 15
  • sloc: perl: 390; makefile: 151; sh: 122
file content (140 lines) | stat: -rw-r--r-- 3,990 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/perl
# 2003 by Frank Lichtenheld
#
# just run debian/diff-tarballs in the packages source directory
# it runs then a diff on the content listings of the latest
# two HOWTO tarballs and emits a corresponding changelog entry
# listing add, changed and removed HOWTOs
#
# This script uses the following external commands:
#  - tar
#  - diff
#  - rgrep

use strict;
use warnings;

my @files;
opendir my $dh, 'HOWTO' or die "E: couldn't open directory HOWTO: $!";
while( my $f = readdir $dh ) {
    $f =~ /^Linux-HOWTOs-\d+\.tar\.bz2$/o && push @files, $f;
}
closedir $dh or warn "W: couldn't close directory HOWTO: $!\n";
die "E: couldn't find two files to diff" if @files < 2;

my ( $newfile, $oldfile ) = reverse sort @files;

#print STDERR "I: diffing $newfile against $oldfile\n";

#print STDERR "I: writing list of old HOWTOs\n";

my @old_list = `tar tjvf HOWTO/$oldfile`;
my $num_old = @old_list;

foreach ( @old_list ) {
    s/^[-rwx]{10}\s+\w+\/\w+\s+//o;
}

open my $fh, '>', "old-howtos" or die "E: couldn't open old-howtos: $!";
print $fh join( '', @old_list );
close $fh or warn "W: couldn't close old-howtos: $!\n";

#print STDERR "I: writing list of new HOWTOs\n";

my @new_list = `tar tjvf HOWTO/$newfile`;
my $num_new = @new_list;

foreach ( @new_list ) {
    s/^[-rwx]{10}\s+\w+\/\w+\s+//o;
}
open $fh, '>', "new-howtos" or die "E: couldn't open new-howtos: $!";
print $fh join( '', @new_list );
close $fh or warn "W: couldn't close new-howtos: $!\n";

my @diff_out = `diff -U 0 old-howtos new-howtos`;

my ( %added, %removed, %modified );

shift @diff_out;
shift @diff_out;
foreach ( @diff_out ) {
    chomp;
    /^@/ && next;
    /\s(HOWTO-)?INDEX$/ && next;
    /\s\.htaccess/ && next;
    /^-/ && do {
	s/^-//;
	my ( $size, $date, $time, $name ) = split;
	if ( exists $added{$name} ) {
	    if ( "$date $time" ne $added{$name}{time} ) {
		$modified{$name} = {
		    oldsize => $size,
		    oldtime => "$date $time",
		    newsize => $added{$name}{size},
		    newtime => $added{$name}{time},
		};
	    }
	    delete $added{$name};
	} else {
	    $removed{$name} = {
		size => $size,
		time => "$date $time",
	    };
	}
	next;
    };
    /^\+/ && do {
	s/^\+//;
	my ( $size, $date, $time, $name ) = split;
	if ( exists $removed{$name} ) {
	    if ( "$date $time" ne $removed{$name}{time} ) {
		$modified{$name} = {
		    newsize => $size,
		    newtime => "$date $time",
		    oldsize => $removed{$name}{size},
		    oldtime => $removed{$name}{time},
		};
	    }
	    delete $removed{$name};
	} else {
	    $added{$name} = {
		size => $size,
		time => "$date $time",
	    };
	}
	next;
    };
}

my @nonfree_list = qx'rgrep --exclude *.svn* ^HOWTO: debian/copyrights/non-free/ | perl -p -e "s/^\S+\s*//o" | sort | uniq';
my @removed_list = qx'rgrep --exclude *.svn* ^HOWTO: debian/copyrights/removed/ | perl -p -e "s/^\S+\s*//o" | sort | uniq';
my @undistributable_list = qx'rgrep --exclude *.svn* ^HOWTO: debian/copyrights/undistributable/ | perl -p -e "s/^\S+\s*//o" | sort | uniq';
my %nonfree_list;
foreach (@nonfree_list, @removed_list, @undistributable_list) {
    chomp;
    $nonfree_list{$_}++;
}

#print STDERR "D: old_num: $num_old\n";
#print STDERR "D: new_num: $num_new\n";
#print STDERR "D: diff_num: ".($num_new - $num_old)."\n";
#print STDERR "D: rm_num: ".scalar( keys( %removed ))."\n";
#print STDERR "D: m_num: ".scalar( keys( %modified ))."\n";
#print STDERR "D: add_num: ".scalar( keys( %added ))."\n";

print "\t* Removed HOWTOs:\n" if scalar( keys( %removed ));
foreach ( sort keys %removed ) {
    print "\t $_\n";
}
print "\t* Updated HOWTOs:\n" if scalar( keys( %modified ));
foreach ( sort keys %modified ) {
    my $nonfree = exists $nonfree_list{$_} ? "(nonfree)" : "";
    print "\t $_ $nonfree\n";
}
print "\t* Added HOWTOs:\n" if scalar( keys( %added ));
foreach ( sort keys %added ) {
    #filter out known nonfree HOWTOs in case we diff with a free-only tar ball
    unless ( exists $nonfree_list{$_} ) {
	print "\t $_\n";
    }
}