17
17
18
18
use File::Find;
19
19
use FindBin ' $Script' ;
20
- use Cwd ' abs_path' ;
20
+ use Cwd qw( abs_path ) ;
21
21
22
22
use Getopt::Std;
23
23
46
46
our $debug ;
47
47
# ignore all content below the footer trailer
48
48
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 ;
51
53
# thw two dirs that need to be compared
52
54
our $dir1 ;
53
55
our $dir2 ;
@@ -116,17 +118,33 @@ sub filter_filenames {
116
118
my $filename = shift ;
117
119
my $res = 0;
118
120
119
- foreach my $regex (@ignore_regex ) {
121
+ foreach my $regex (@ignore_files_regex ) {
120
122
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 ;
123
125
}
124
126
}
125
127
126
128
return $res ;
127
129
128
130
} # filter_filenames
129
131
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
+
130
148
# does a diff on existing directories, files, and file content
131
149
sub diff_files_complete {
132
150
my $file = $_ ;
@@ -145,7 +163,7 @@ sub diff_files_complete {
145
163
return ;
146
164
}
147
165
148
- my $is_attachment_dir = $filename1 =~ m / \/ $attachment_dir_prefix / ;
166
+ my $is_attachment_dir = $filename1 =~ m # / $attachment_dir_prefix # ;
149
167
150
168
if (!$is_attachment_dir ) {
151
169
if ($filename1 =~ m /\. html$ / ) {
@@ -162,6 +180,8 @@ sub diff_files_complete {
162
180
open (my $fh , " -|" , @diff_args ) || die (" cannot diff $filename1 $filename2 \n " );
163
181
164
182
while (my $line = <$fh >) {
183
+
184
+ chomp $line ;
165
185
166
186
if ($line eq " " ) {
167
187
next ;
@@ -188,7 +208,7 @@ sub diff_files_complete {
188
208
}
189
209
$local_errors ++;
190
210
}
191
- $diffs .= $line ;
211
+ $diffs .= $line . " \n " ;
192
212
}
193
213
close ($fh );
194
214
@@ -219,7 +239,7 @@ sub diff_files_dir {
219
239
sub process_options {
220
240
my %options =();
221
241
222
- getopts(" qhfpdi:" , \%options );
242
+ getopts(" qhfpdi:v: " , \%options );
223
243
224
244
$dir1 = $ARGV [0];
225
245
$dir2 = $ARGV [1];
@@ -246,31 +266,28 @@ sub process_options {
246
266
. " \t -h help prints this message\n "
247
267
. " \t -f ignore all content below the footer trailer comment\n "
248
268
. " \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 "
249
270
. " \t dir1, dir2 paths to the two directories to compare\n\n " );
250
271
}
251
272
252
273
# 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 );
259
276
260
- if (-l $dir2 ) {
261
- $dir2 = abs_path ($dir2 );
262
- }
263
-
264
277
if (!-d $dir1 ) {
265
- die (" directory $dir1 doesn't exist \n " );
278
+ die (" $dir1 is not a directory \n " );
266
279
}
267
280
268
281
if (!-d $dir2 ) {
269
- die (" directory $dir2 doesn't exist \n " );
282
+ die (" $dir2 is not a directory \n " );
270
283
}
271
284
272
285
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 });
274
291
}
275
292
276
293
} # process_options
0 commit comments