3 # cmpVERSION - compare the current Perl source tree and a given tag
4 # for modules that have identical version numbers but different contents.
6 # with -d option, output the diffs too
7 # with -x option, exclude dual-life modules (after all, there are tools
8 # like core-cpan-diff that can already deal with them)
10 # Original by slaven@rezic.de, modified by jhi and matt.w.johnson@gmail.com.
15 use ExtUtils::MakeMaker;
17 use File::Spec::Functions qw(devnull);
20 my ($diffs, $exclude_dual, $tag_to_compare);
21 unless (GetOptions('diffs' => \$diffs,
22 'exclude|x' => \$exclude_dual,
23 'tag=s' => \$tag_to_compare,
25 die "usage: $0 [ -d -x --tag TAG]";
28 die "$0: This does not look like a Perl directory\n"
29 unless -f "perl.h" && -d "Porting";
30 die "$0: 'This is a Perl directory but does not look like Git working directory\n"
35 unless (defined $tag_to_compare) {
36 # Thanks to David Golden for this suggestion.
38 $tag_to_compare = `git describe --abbrev=0`;
39 chomp $tag_to_compare;
42 my $tag_exists = `git --no-pager tag -l $tag_to_compare 2>$null`;
45 die "$0: '$tag_to_compare' is not a known Git tag\n"
46 unless $tag_exists eq $tag_to_compare;
50 unshift @INC, 'Porting';
53 for my $m (grep $Maintainers::Modules{$_}{CPAN},
54 keys %Maintainers::Modules) {
55 $dual_files{$_} = 1 for Maintainers::get_module_files($m);
59 # Files to skip from the check for one reason or another,
60 # usually because they pull in their version from some other file.
64 'lib/Config.pm', # no version number but contents will vary
65 'lib/Exporter/Heavy.pm',
68 my $skip_dirs = qr|^t/lib|;
70 my @all_diffs = `git --no-pager diff --name-only $tag_to_compare`;
73 my @module_diffs = grep {
75 $this_dir = $1 if m/^(.*)\//;
77 (!defined($this_dir) || ($this_dir !~ $skip_dirs)) &&
79 !exists $dual_files{$_}
82 my (@output_files, @output_diffs);
84 foreach my $pm_file (@module_diffs) {
85 (my $xs_file = $pm_file) =~ s/\.pm$/.xs/;
86 my $pm_eq = compare_git_file($pm_file, $tag_to_compare);
87 next unless defined $pm_eq;
90 $xs_eq = compare_git_file($xs_file, $tag_to_compare);
91 next unless defined $xs_eq;
93 next if ($pm_eq && $xs_eq);
94 my $pm_version = eval {MM->parse_version($pm_file)};
95 my $orig_pm_content = get_file_from_git($pm_file, $tag_to_compare);
96 my $orig_pm_version = eval {MM->parse_version(\$orig_pm_content)};
97 next if ( ! defined $pm_version || ! defined $orig_pm_version );
98 next if ( $pm_version eq 'undef' || $orig_pm_version eq 'undef' ); # sigh
99 next if $pm_version ne $orig_pm_version;
100 push @output_files, $pm_file;
101 push @output_diffs, $pm_file unless $pm_eq;
102 push @output_diffs, $xs_file unless $xs_eq;
105 sub compare_git_file {
106 my ($file, $tag) = @_;
107 open(my $orig_fh, "-|", "git --no-pager show $tag:$file 2>$null");
108 return undef if eof($orig_fh);
109 my $is_eq = compare($file, $orig_fh) == 0;
114 sub get_file_from_git {
115 my ($file, $tag) = @_;
117 my $file_content = `git --no-pager show $tag:$file 2>$null`;
118 return $file_content;
121 for (sort @output_files) {
127 for (sort @output_diffs) {
129 system "git --no-pager diff $tag_to_compare '$_'";