+ die "No idea which .pm file corresponds to '$xs', so aborting";
+}
+
+# Key is the .pm file from which we check the version.
+# Value is a reference to an array of files to check for differences
+# The trivial case is a pure perl module, where the array holds one element,
+# the perl module's file. The "fun" comes with XS modules, and the real fun
+# with XS modules with more than one XS file, and "interesting" layouts.
+
+my %module_diffs;
+
+foreach (`git --no-pager diff --name-only $tag_to_compare --diff-filter=ACMRTUXB`) {
+ chomp;
+ next unless m/^(.*)\//;
+ my $this_dir = $1;
+ next if $this_dir =~ $skip_dirs || exists $skip{$_};
+ next if exists $upstream_files{$_};
+ if (/\.pm\z/ || m|^lib/.*\.pl\z| || /_pm\.PL\z/) {
+ push @{$module_diffs{$_}}, $_;
+ } elsif (/\.xs\z/ && !/\bt\b/) {
+ push @{$module_diffs{pm_file_from_xs($_)}}, $_;
+ }
+}
+
+unless (%module_diffs) {
+ print "1..1\nok 1 - No difference found\n" if $tap;
+ exit;
+}
+
+printf "1..%d\n" => scalar keys %module_diffs if $tap;
+
+my $count;
+my $diff_cmd = "git --no-pager diff $tag_to_compare ";
+my $q = ($^O eq 'MSWin32' || $^O eq 'NetWare' || $^O eq 'VMS') ? '"' : "'";
+my (@diff);
+
+foreach my $pm_file (sort keys %module_diffs) {
+ # git has already told us that the files differ, so no need to grab each as
+ # a blob from git, and do the comparison ourselves.
+ my $pm_version = eval {MM->parse_version($pm_file)};
+ my $orig_pm_content = get_file_from_git($pm_file, $tag_to_compare);
+ my $orig_pm_version = eval {MM->parse_version(\$orig_pm_content)};
+ ++$count;
+
+ if (!defined $orig_pm_version || $orig_pm_version eq 'undef') { # sigh
+ print "ok $count - SKIP Can't parse \$VERSION in $pm_file\n"
+ if $tap;
+ } elsif (!defined $pm_version || $pm_version eq 'undef') {
+ print "not ok $count - in $pm_file version was $orig_pm_version, now unparsable\n" if $tap;
+ } elsif ($pm_version ne $orig_pm_version) { # good
+ print "ok $count - $pm_file\n" if $tap;
+ } else {
+ if ($tap) {
+ foreach (sort @{$module_diffs{$pm_file}}) {
+ print "# $_" for `$diff_cmd $q$_$q`;
+ }
+ if (exists $skip_versions{$pm_file}
+ and grep $pm_version eq $_, @{$skip_versions{$pm_file}}) {
+ print "ok $count - SKIP $pm_file version $pm_version\n";
+ } else {
+ print "not ok $count - $pm_file\n";
+ }
+ } else {
+ push @diff, @{$module_diffs{$pm_file}};
+ print "$pm_file\n";
+ }
+ }
+}
+
+sub get_file_from_git {
+ my ($file, $tag) = @_;
+ local $/;
+
+ use open IN => ':raw';
+ return scalar `git --no-pager show $tag:$file 2>$null`;
+}
+
+if ($diffs) {
+ for (sort @diff) {
+ print "\n";
+ system "$diff_cmd $q$_$q";
+ }
+}