[devscripts] 08/16: licensecheck: optimize regex used to ignore or check files

dod at debian.org dod at debian.org
Thu May 14 16:34:26 UTC 2015


This is an automated email from the git hooks/post-receive script.

dod pushed a commit to branch master
in repository devscripts.

commit cc5b674167bbf96ee830f2dfc7f6ee9b8dc34d0b
Author: Dominique Dumont <dod at debian.org>
Date:   Thu May 14 16:30:16 2015 +0200

    licensecheck: optimize regex used to ignore or check files
---
 scripts/licensecheck.pl | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/scripts/licensecheck.pl b/scripts/licensecheck.pl
index 86e78e1..aa21dd5 100755
--- a/scripts/licensecheck.pl
+++ b/scripts/licensecheck.pl
@@ -242,8 +242,9 @@ GetOptions(\%OPT,
 ) or die "Usage: $progname [options] filelist\nRun $progname --help for more details\n";
 
 $OPT{'lines'} = $def_lines if $OPT{'lines'} !~ /^[1-9][0-9]*$/;
-my $ignore_regex = length($OPT{ignore}) ? $OPT{ignore} : $default_ignore_regex;
+my $ignore_regex = length($OPT{ignore}) ? qr/$OPT{ignore}/ : $default_ignore_regex;
 $OPT{'check'} = $default_check_regex if ! length $OPT{'check'};
+my $check_regex = qr/$OPT{check}/;
 
 if ($OPT{'noconf'}) {
     fatal("--no-conf is only acceptable as the first command-line option!");
@@ -269,16 +270,16 @@ while (@ARGV) {
 	open my $FIND, '-|', 'find', $file, @find_args
 	    or die "$progname: couldn't exec find: $!\n";
 
-	while (<$FIND>) {
-	    chomp;
-	    next unless m%$OPT{'check'}%;
+	while (my $found = <$FIND>) {
+	    chomp ($found);
+	    next unless $found =~ $check_regex;
 	    # Skip empty files
-	    next if (-z $_);
-	    push @files, $_ unless $ignore_regex;
+	    next if (-z $found);
+	    push @files, $found unless $found =~ $ignore_regex;
 	}
 	close $FIND;
     } else {
-	next unless ($files_count == 1) or $file =~ m%$OPT{'check'}%;
+	next unless ($files_count == 1) or $file =~ $check_regex;
 	push @files, $file unless $file =~ $ignore_regex;
     }
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/devscripts.git



More information about the devscripts-devel mailing list