Skip to content

Commit 5ee7fa1

Browse files
committed
fix some issues handling the dir1 and dir2 parameters and the diff
- dir1 and dir2 are now converted into their absolute pathname before the comparition - the newline from diff was causing diff hits
1 parent a574b30 commit 5ee7fa1

File tree

1 file changed

+39
-22
lines changed

1 file changed

+39
-22
lines changed

tests/diff_hypermail_archives.pl

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
use File::Find;
1919
use FindBin '$Script';
20-
use Cwd 'abs_path';
20+
use Cwd qw( abs_path );
2121

2222
use Getopt::Std;
2323

@@ -46,8 +46,10 @@
4646
our $debug;
4747
# ignore all content below the footer trailer
4848
our $ignore_footer;
49-
# hash with filenames, dirnames that must be ignored
50-
our @ignore_regex;
49+
# hash with filenames|dirnames that must be ignored
50+
our @ignore_files_regex;
51+
# hash with text that must be ignored in the diff output
52+
our @ignore_text_regex;
5153
# thw two dirs that need to be compared
5254
our $dir1;
5355
our $dir2;
@@ -116,17 +118,33 @@ sub filter_filenames {
116118
my $filename = shift;
117119
my $res = 0;
118120

119-
foreach my $regex (@ignore_regex) {
121+
foreach my $regex (@ignore_files_regex) {
120122
if ($filename =~ m/$regex/) {
121-
$res = -1;
122-
print "\n$filename is ignored per regex: " . $regex . "\n" if $show_progress;
123+
$res = 1;
124+
print "$filename is ignored per regex: " . $regex . "\n" unless $quiet;
123125
}
124126
}
125127

126128
return $res;
127129

128130
} # filter_filenames
129131

132+
# filter out text lines we're not interested in
133+
sub filter_text {
134+
my ($text1, $text2) = @_;
135+
my $res = 0;
136+
137+
foreach my $regex (@ignore_text_regex) {
138+
if ($text1 =~ m/$regex/ && $text2 =~ m/$regex/) {
139+
$res = 1;
140+
print "$text1 is ignored per regex: " . $regex . "\n" unless $quiet;
141+
}
142+
}
143+
144+
return $res;
145+
146+
} # filter_text
147+
130148
# does a diff on existing directories, files, and file content
131149
sub diff_files_complete {
132150
my $file = $_;
@@ -145,7 +163,7 @@ sub diff_files_complete {
145163
return;
146164
}
147165

148-
my $is_attachment_dir = $filename1 =~ m/\/$attachment_dir_prefix/;
166+
my $is_attachment_dir = $filename1 =~ m#/$attachment_dir_prefix#;
149167

150168
if (!$is_attachment_dir) {
151169
if ($filename1 =~ m/\.html$/) {
@@ -162,6 +180,8 @@ sub diff_files_complete {
162180
open (my $fh, "-|", @diff_args) || die("cannot diff $filename1 $filename2\n");
163181

164182
while (my $line = <$fh>) {
183+
184+
chomp $line;
165185

166186
if ($line eq "") {
167187
next;
@@ -188,7 +208,7 @@ sub diff_files_complete {
188208
}
189209
$local_errors++;
190210
}
191-
$diffs .= $line;
211+
$diffs .= $line . "\n";
192212
}
193213
close ($fh);
194214

@@ -219,7 +239,7 @@ sub diff_files_dir {
219239
sub process_options {
220240
my %options=();
221241

222-
getopts("qhfpdi:", \%options);
242+
getopts("qhfpdi:v:", \%options);
223243

224244
$dir1 = $ARGV[0];
225245
$dir2 = $ARGV[1];
@@ -246,31 +266,28 @@ sub process_options {
246266
. "\t-h help prints this message\n"
247267
. "\t-f ignore all content below the footer trailer comment\n"
248268
. "\t-i list of colon separated regex corresponding to directories/filenames to ignore\n"
269+
. "\t-v list of colon separated regex corresponding to text that should be ignored in diff reports\n"
249270
. "\tdir1, dir2 paths to the two directories to compare\n\n");
250271
}
251272

252273
# remove trailing / if given
253-
$dir1 =~ s/\/+$//;
254-
$dir2 =~ s/\/+$//;
255-
256-
if (-l $dir1) {
257-
$dir1 = abs_path ($dir1);
258-
}
274+
$dir1 = abs_path ($dir1);
275+
$dir2 = abs_path ($dir2);
259276

260-
if (-l $dir2) {
261-
$dir2 = abs_path ($dir2);
262-
}
263-
264277
if (!-d $dir1) {
265-
die ("directory $dir1 doesn't exist\n");
278+
die ("$dir1 is not a directory\n");
266279
}
267280

268281
if (!-d $dir2) {
269-
die ("directory $dir2 doesn't exist\n");
282+
die ("$dir2 is not a directory\n");
270283
}
271284

272285
if (defined $options{i}) {
273-
@ignore_regex = split (/:/, $options{i});
286+
@ignore_files_regex = split (/:/, $options{i});
287+
}
288+
289+
if (defined $options{v}) {
290+
@ignore_text_regex = split (/:/, $options{v});
274291
}
275292

276293
} # process_options

0 commit comments

Comments
 (0)