Skip to content

Instantly share code, notes, and snippets.

@rmloveland
Last active December 1, 2020 15:22
Show Gist options
  • Save rmloveland/d429c0af36ef650d1219eb232b0eb4f9 to your computer and use it in GitHub Desktop.
Save rmloveland/d429c0af36ef650d1219eb232b0eb4f9 to your computer and use it in GitHub Desktop.
#!perl
use strict;
use warnings;
use experimentals;
use constant DEBUG => undef;
die usage() unless scalar @ARGV >= 2;
sub usage {
return <<"EOF";
Usage: reldupes v20.2.1.md v20.2.2.md
(Checks release note pages for duplicate commit references.)
EOF
}
my ( $old, $new ) = @ARGV;
my %old;
$old{name} = $old;
my %new;
$new{name} = $new;
open my $old_fh, '<', $old;
while (<$old_fh>) {
if (/(\[#[0-9]+\])/) {
$old{$1}++;
say $1 if DEBUG;
}
}
close $old_fh;
open my $new_fh, '<', $new;
while (<$new_fh>) {
if (/(\[#[0-9]+\])/) {
$new{$1}++;
say $1 if DEBUG;
}
}
close $new_fh;
my @dupes;
KEY: for my $k ( keys %old ) {
if ( exists $new{$k} ) {
next KEY if $k eq 'name';
say qq[Found duplicate: $k] if DEBUG;
push @dupes, $k;
}
}
if (@dupes) {
say qq[Found duplicates in $new{name}!] if DEBUG;
say for @dupes;
}
else {
printf( "No duplicates found between files: '%s' and '%s'\n",
$old{name}, $new{name} )
if DEBUG;
}
__END__
$ reldupes v20.2.1.md v20.2.2.md
Found duplicates in v20.2.2.md!
[#56678]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment