Prechádzať zdrojové kódy

scripts: Switch unused capturing groups to non-capturing ones

These have better runtime performance, not that it matters in many of
the instances here though.

Addresses RegularExpressions::ProhibitUnusedCapture.

Warned-by: perlcritic
Guillem Jover 13 rokov pred
rodič
commit
395f6ced94

+ 7 - 7
scripts/Dpkg/Changelog/Debian.pm

@@ -102,7 +102,7 @@ sub parse {
 	    }
 	    $expect= START_CHANGES;
 	    @blanklines = ();
-	} elsif (m/^(;;\s*)?Local variables:/io) {
+	} elsif (m/^(?:;;\s*)?Local variables:/io) {
 	    last; # skip Emacs variables at end of file
 	} elsif (m/^vim:/io) {
 	    last; # skip vim variables at end of file
@@ -112,11 +112,11 @@ sub parse {
 	    next; # skip comments, even that's not supported
 	} elsif (m{^/\*.*\*/}o) {
 	    next; # more comments
-	} elsif (m/^(\w+\s+\w+\s+\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}\s+[\w\s]*\d{4})\s+(.*)\s+[<\(](.*)[\)>]/o
-		 || m/^(\w+\s+\w+\s+\d{1,2},?\s*\d{4})\s+(.*)\s+[<\(](.*)[\)>]/o
-		 || m/^(\w[-+0-9a-z.]*) \(([^\(\) \t]+)\)\;?/io
-		 || m/^([\w.+-]+)[- ](\S+) Debian (\S+)/io
-		 || m/^Changes from version (.*) to (.*):/io
+	} elsif (m/^(?:\w+\s+\w+\s+\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}\s+[\w\s]*\d{4})\s+(?:.*)\s+[<\(](?:.*)[\)>]/o
+		 || m/^(?:\w+\s+\w+\s+\d{1,2},?\s*\d{4})\s+(?:.*)\s+[<\(](?:.*)[\)>]/o
+		 || m/^(?:\w[-+0-9a-z.]*) \((?:[^\(\) \t]+)\)\;?/io
+		 || m/^(?:[\w.+-]+)[- ](?:\S+) Debian (?:\S+)/io
+		 || m/^Changes from version (?:.*) to (?:.*):/io
 		 || m/^Changes for [\w.+-]+-[\w.+-]+:?\s*$/io
 		 || m/^Old Changelog:\s*$/io
 		 || m/^(?:\d+:)?\w[\w.+~-]*:?\s*$/o) {
@@ -140,7 +140,7 @@ sub parse {
 	    $expect = NEXT_OR_EOF;
 	} elsif (m/^ \-\-/) {
 	    $self->parse_error($file, $., _g('badly formatted trailer line'), "$_");
-	} elsif (m/^\s{2,}(\S)/) {
+	} elsif (m/^\s{2,}(?:\S)/) {
 	    unless ($expect eq START_CHANGES or $expect eq CHANGES_OR_TRAILER) {
 		$self->parse_error($file, $., sprintf(_g('found change data' .
 		    ' where expected %s'), $expect), "$_");

+ 1 - 1
scripts/Dpkg/Source/Package/V3/Bzr.pm

@@ -69,7 +69,7 @@ sub sanity_check {
     my $abs_srcdir = Cwd::abs_path($srcdir);
     find(sub {
         if (-l $_) {
-            if (Cwd::abs_path(readlink($_)) !~ /^\Q$abs_srcdir\E(\/|$)/) {
+            if (Cwd::abs_path(readlink($_)) !~ /^\Q$abs_srcdir\E(?:\/|$)/) {
                 error(_g('%s is a symlink to outside %s'),
                       $File::Find::name, $srcdir);
             }

+ 1 - 1
scripts/Dpkg/Source/Patch.pm

@@ -489,7 +489,7 @@ sub analyze {
 	while (defined($_ = _getline($self))) {
 	    # read hunk header (@@)
 	    next if /^\\ /;
-	    last unless (/^@@ -\d+(,(\d+))? \+\d+(,(\d+))? @\@( .*)?$/);
+	    last unless (/^@@ -\d+(,(\d+))? \+\d+(,(\d+))? @\@(?: .*)?$/);
 	    my ($olines, $nlines) = ($1 ? $2 : 1, $3 ? $4 : 1);
 	    # read hunk
 	    while ($olines || $nlines) {

+ 1 - 1
scripts/Dpkg/Source/Quilt.pm

@@ -259,7 +259,7 @@ sub read_patch_list {
     open(my $series_fh, '<' , $file) or syserr(_g('cannot read %s'), $file);
     while (defined($_ = <$series_fh>)) {
         chomp; s/^\s+//; s/\s+$//; # Strip leading/trailing spaces
-        s/(^|\s+)#.*$//; # Strip comment
+        s/(?:^|\s+)#.*$//; # Strip comment
         next unless $_;
         if (/^(\S+)\s+(.*)$/) {
             $_ = $1;

+ 4 - 4
scripts/Dpkg/Vendor/Debian.pm

@@ -115,21 +115,21 @@ sub add_hardening_flags {
     }
 
     # Mask features that are not available on certain architectures.
-    if ($os !~ /^(linux|knetbsd|hurd)$/ or
-	$cpu =~ /^(hppa|mips|mipsel|avr32)$/) {
+    if ($os !~ /^(?:linux|knetbsd|hurd)$/ or
+	$cpu =~ /^(?:hppa|mips|mipsel|avr32)$/) {
 	# Disabled on non-linux/knetbsd/hurd (see #430455 and #586215).
 	# Disabled on hppa, mips/mipsel (#532821), avr32
 	#  (#574716).
 	$use_feature{pie} = 0;
     }
-    if ($cpu =~ /^(ia64|alpha|mips|mipsel|hppa|arm64)$/ or $arch eq 'arm') {
+    if ($cpu =~ /^(?:ia64|alpha|mips|mipsel|hppa|arm64)$/ or $arch eq 'arm') {
 	# Stack protector disabled on ia64, alpha, arm64, mips, mipsel, hppa.
 	#   "warning: -fstack-protector not supported for this target"
 	# Stack protector disabled on arm (ok on armel).
 	#   compiler supports it incorrectly (leads to SEGV)
 	$use_feature{stackprotector} = 0;
     }
-    if ($cpu =~ /^(ia64|hppa|avr32)$/) {
+    if ($cpu =~ /^(?:ia64|hppa|avr32)$/) {
 	# relro not implemented on ia64, hppa, avr32.
 	$use_feature{relro} = 0;
     }

+ 1 - 1
scripts/dpkg-architecture.pl

@@ -155,7 +155,7 @@ while (@ARGV) {
     } elsif (m/^-L$/) {
         list_arches();
         exit unless @ARGV;
-    } elsif (m/^-(\?|-help)$/) {
+    } elsif (m/^-(?:\?|-help)$/) {
         usage();
        exit 0;
     } elsif (m/^--version$/) {

+ 1 - 1
scripts/dpkg-buildflags.pl

@@ -82,7 +82,7 @@ while (@ARGV) {
         usageerr(_g('two commands specified: --%s and --%s'), $1, $action)
             if defined($action);
         $action = $1;
-    } elsif (m/^-(\?|-help)$/) {
+    } elsif (m/^-(?:\?|-help)$/) {
         usage();
         exit 0;
     } elsif (m/^--version$/) {

+ 4 - 4
scripts/dpkg-buildpackage.pl

@@ -193,7 +193,7 @@ if ($build_opts->has('nocheck')) {
 while (@ARGV) {
     $_ = shift @ARGV;
 
-    if (/^(--help|-\?)$/) {
+    if (/^(?:--help|-\?)$/) {
 	usage;
 	exit 0;
     } elsif (/^--version$/) {
@@ -251,10 +251,10 @@ while (@ARGV) {
 	$cleansource = 1;
     } elsif (/^-t(.*)$/) {
 	$targetgnusystem = $1; # Order DOES matter!
-    } elsif (/^(--target|-T)$/) {
+    } elsif (/^(?:--target|-T)$/) {
         $call_target = shift @ARGV;
-    } elsif (/^(--target=|-T)(.+)$/) {
-        $call_target = $2;
+    } elsif (/^(?:--target=|-T)(.+)$/) {
+        $call_target = $1;
     } elsif (/^--as-root$/) {
         $call_target_as_root = 1;
     } elsif (/^-nc$/) {

+ 1 - 1
scripts/dpkg-distaddfile.pl

@@ -57,7 +57,7 @@ while (@ARGV && $ARGV[0] =~ m/^-/) {
     $_=shift(@ARGV);
     if (m/^-f/p) {
         $fileslistfile = ${^POSTMATCH};
-    } elsif (m/^-(\?|-help)$/) {
+    } elsif (m/^-(?:\?|-help)$/) {
         usage();
         exit(0);
     } elsif (m/^--version$/) {

+ 3 - 3
scripts/dpkg-genchanges.pl

@@ -194,7 +194,7 @@ while (@ARGV) {
         $remove{$1} = 1;
     } elsif (m/^-V(\w[-:0-9A-Za-z]*)[=:](.*)$/s) {
 	$substvars->set($1, $2);
-    } elsif (m/^-(\?|-help)$/) {
+    } elsif (m/^-(?:\?|-help)$/) {
 	usage();
 	exit(0);
     } elsif (m/^--version$/) {
@@ -418,7 +418,7 @@ if (!is_binaryonly) {
     my $ext = compression_get_file_extension_regex();
     if ((($sourcestyle =~ m/i/ && !$include_tarball) ||
 	 $sourcestyle =~ m/d/) &&
-	any { m/\.(debian\.tar|diff)\.$ext$/ } $checksums->get_files())
+	any { m/\.(?:debian\.tar|diff)\.$ext$/ } $checksums->get_files())
     {
 	$origsrcmsg= _g('not including original source code in upload');
 	foreach my $f (grep { m/\.orig(-.+)?\.tar\.$ext$/ } $checksums->get_files()) {
@@ -426,7 +426,7 @@ if (!is_binaryonly) {
 	}
     } else {
 	if ($sourcestyle =~ m/d/ &&
-	    none { m/\.(debian\.tar|diff)\.$ext$/ } $checksums->get_files()) {
+	    none { m/\.(?:debian\.tar|diff)\.$ext$/ } $checksums->get_files()) {
 	    warning(_g('ignoring -sd option for native Debian package'));
 	}
         $origsrcmsg= _g('including full source code in upload');

+ 1 - 1
scripts/dpkg-gencontrol.pl

@@ -130,7 +130,7 @@ while (@ARGV) {
 	$substvars_loaded = 1;
     } elsif (m/^-n/p) {
         $forcefilename = ${^POSTMATCH};
-    } elsif (m/^-(\?|-help)$/) {
+    } elsif (m/^-(?:\?|-help)$/) {
         usage();
         exit(0);
     } elsif (m/^--version$/) {

+ 1 - 1
scripts/dpkg-gensymbols.pl

@@ -130,7 +130,7 @@ while (@ARGV) {
 	$verbose_output = 1;
     } elsif (m/^-a(.+)$/) {
 	$host_arch = $1;
-    } elsif (m/^-(\?|-help)$/) {
+    } elsif (m/^-(?:\?|-help)$/) {
 	usage();
 	exit(0);
     } elsif (m/^--version$/) {

+ 1 - 1
scripts/dpkg-parsechangelog.pl

@@ -113,7 +113,7 @@ while (@ARGV) {
 	}
     } elsif (m/^--all$/) {
 	$options{all} = undef;
-    } elsif (m/^-(\?|-help)$/) {
+    } elsif (m/^-(?:\?|-help)$/) {
 	usage(); exit(0);
     } elsif (m/^--version$/) {
 	version(); exit(0);

+ 1 - 1
scripts/dpkg-shlibdeps.pl

@@ -95,7 +95,7 @@ foreach (@ARGV) {
 	$stdout = 1;
     } elsif (m/^-O(.+)$/) {
 	$varlistfile = $1;
-    } elsif (m/^-(\?|-help)$/) {
+    } elsif (m/^-(?:\?|-help)$/) {
 	usage(); exit(0);
     } elsif (m/^--version$/) {
 	version(); exit(0);

+ 3 - 3
scripts/dpkg-source.pl

@@ -84,7 +84,7 @@ while (@ARGV && $ARGV[0] =~ m/^-/) {
         setopmode('-b');
     } elsif (m/^-x$/) {
         setopmode('-x');
-    } elsif (m/^--(before|after)-build$/) {
+    } elsif (m/^--(?:before|after)-build$/) {
         setopmode($_);
     } elsif (m/^--commit$/) {
         setopmode($_);
@@ -190,7 +190,7 @@ while (@options) {
         $substvars->set($1, $2);
     } elsif (m/^-T(.*)$/) {
 	$substvars->load($1) if -e $1;
-    } elsif (m/^-(\?|-help)$/) {
+    } elsif (m/^-(?:\?|-help)$/) {
         usage();
         exit(0);
     } elsif (m/^--version$/) {
@@ -245,7 +245,7 @@ if ($options{opmode} =~ /^(-b|--print-format|--(before|after)-build|--commit)$/)
 	    $fields->{$_} = $v;
 	} elsif (m/^Uploaders$/i) {
 	    ($fields->{$_} = $v) =~ s/\s*[\r\n]\s*/ /g; # Merge in a single-line
-	} elsif (m/^Build-(Depends|Conflicts)(-Arch|-Indep)?$/i) {
+	} elsif (m/^Build-(?:Depends|Conflicts)(?:-Arch|-Indep)?$/i) {
 	    my $dep;
 	    my $type = field_get_dep_type($_);
 	    $dep = deps_parse($v, build_dep => 1, union => $type eq 'union');

+ 1 - 1
scripts/dpkg-vendor.pl

@@ -66,7 +66,7 @@ while (@ARGV) {
         $action = $1;
         $param = shift(@ARGV);
         usageerr(_g('%s needs a parameter'), $_) unless defined $param;
-    } elsif (m/^-(\?|-help)$/) {
+    } elsif (m/^-(?:\?|-help)$/) {
         usage();
         exit 0;
     } elsif (m/^--version$/) {