This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Zero out high bytes of 80-bit ldnan
[metaconfig.git] / ls-diff.pl
CommitLineData
18be95c2
MBT
1#!/pro/bin/perl
2
3use 5.18.2;
4use warnings;
5
b3aab7a5 6our $VERSION = "0.03";
18be95c2
MBT
7
8sub usage {
9 my $err = shift and select STDERR;
b3aab7a5 10 say "usage: $0 [--list] [--diff[=gd|dp|gp]] [--pat=pattern]";
d8dafc80
MBT
11 say " diff (size) between git / dist / perl";
12 say " where git (g) is the version from the git repo of meta/dist";
13 say " where dist (d) is the unmodified installed version from dist";
14 say " where perl (p) is the *modified* version for use with perl";
18be95c2
MBT
15 exit $err;
16 } # usage
17
18use File::Find;
19use Text::Diff;
20use Getopt::Long qw(:config bundling);
21GetOptions (
22 "help|?" => sub { usage (0); },
23 "V|version" => sub { say $0 =~ s{.*/}{}r, " [$VERSION]"; exit 0; },
24
25 "l|list!" => \my $opt_l,
26 "d|diff=s" => \my $opt_d,
c6667804 27 "c|copy" => \my $opt_c,
b3aab7a5
MBT
28
29 "p|pat=s" => \my $opt_p,
18be95c2
MBT
30 ) or usage (1);
31
32my $pat = shift // ".";
33$pat = qr{$pat};
34
ca5f6937 35my %exempt = map {( s/[\s\n].*\z//rs => 1 )} <DATA>;
18be95c2
MBT
36my %m;
37
d8dafc80
MBT
38foreach my $u ( [ "g", "dist-git/mcon/U" ],
39 [ "d", "dist/U" ],
40 [ "p", "U" ],
18be95c2
MBT
41 ) {
42 my ($t, $dir) = @$u;
43 find (sub {
44 -l $_ and return;
45 m/\.U$/ or return;
46 m{$pat} or return;
47
ca5f6937
MBT
48 $exempt{$_} and return;
49
18be95c2 50 my $u = do { local (@ARGV, $/) = $_; <> };
c6667804
MBT
51 $m{$_}{$t} = {
52 dir => $File::Find::dir,
53 unit => $u,
54 size => length ($u),
55 lines => ($u =~ tr/\n/\n/),
56 };
18be95c2
MBT
57 }, $dir);
58 }
59
d8dafc80
MBT
60foreach my $u (keys %m) {
61 my $g = $m{$u}{g};
62 my $d = $m{$u}{d};
63 my $p = $m{$u}{p};
64
65 $m{$u}{gd} = $g && $d ? length diff (\$g->{unit}, \$d->{unit}) : 0;
66 $m{$u}{dp} = $d && $p ? length diff (\$d->{unit}, \$p->{unit}) : 0;
67 $m{$u}{gp} = $g && $p ? length diff (\$g->{unit}, \$p->{unit}) : 0;
68 }
69
18be95c2
MBT
70$opt_d //= "";
71
72say " # Git Dist Perl Diff Unit";
73say "=== ========= ====== ========= ====== ========= ====== ======================";
74my $i = 1;
d8dafc80 75foreach my $u (sort { $m{$b}{gd} <=> $m{$a}{gd} || $m{$b}{dp} <=> $m{$a}{dp} } keys %m) {
18be95c2 76 my $d = $m{$u}{d} or next;
d8dafc80 77 my $p = $m{$u}{p} or next;
18be95c2
MBT
78 my $g = $m{$u}{g} or next;
79
d8dafc80
MBT
80 my $gd = $m{$u}{gd};
81 my $dp = $m{$u}{dp};
82 my $gp = $m{$u}{gp};
83
84 #$gd == 0 || $gd > 1000 and next;
c6667804 85
b3aab7a5
MBT
86 if ($opt_p) {
87 $d->{unit} =~ $opt_p ||
88 $p->{unit} =~ $opt_p ||
89 $g->{unit} =~ $opt_p or next;
90 }
91
87605c81
MBT
92 my $su = $u;
93 $gd || $dp || $gp or $su .= "\t** NO CHANGES LEFT **";
18be95c2 94 printf "%3d %5d/%3d %6d %5d/%3d %6d %5d/%3d %6d %s\n", $i++,
c6667804 95 $g->{size}, $g->{lines}, $gd,
d8dafc80
MBT
96 $d->{size}, $d->{lines}, $dp,
97 $p->{size}, $p->{lines}, $gp,
87605c81 98 $su;
d8dafc80 99 $opt_l and say " $_ $m{$u}{$_}{dir}/$u" for qw( g d p );
c6667804
MBT
100
101 extdiff ($u, sort split // => $opt_d);
18be95c2 102 }
c6667804
MBT
103
104sub extdiff {
105 my ($u, $from, $to) = (@_, "", "");
106
107 my $f = $m{$u}{$from} or return;
108 my $t = $m{$u}{$to} or return;
109
110 my %tag = (
c6667804 111 g => "git",
d8dafc80
MBT
112 d => "dst",
113 p => "prl",
c6667804
MBT
114 );
115 my $F = $tag{$from};
116 my $T = $tag{$to};
117
118 my $ff = "$f->{dir}/$u";
119 my $tf = "$t->{dir}/$u";
120
121 if ($opt_c) {
122 unlink $ff;
123 system "cp", "-fp", $tf, $ff;
124 }
125
126 open my $fh, "-|", "diff -w $ff $tf";
127 while (<$fh>) {
128 s/^</$F </;
129 s/^>/$T >/;
130 print;
131 }
132 close $fh;
133 } # extdiff
ca5f6937
MBT
134
135__END__
136package.U Will never be equal due to conflicting needs