Thread (11 messages) flat view 11 messages, 2 authors, 2016-06-15
DORMANTno replies

Revision v1 of 2 in this series.

Revisions (2)
  1. v1 current
  2. v1 [diff vs current]

[PATCH 2/5] gitweb: Do not use bareword filehandles

From: Jakub Narebski <hidden>
Date: 2016-06-15 22:46:44
Subsystem: the rest · Maintainer: Linus Torvalds

The script was using bareword filehandles.  This is considered a bad
practice so they have been changed to indirect filehandles.
Changes touch git_get_project_ctags and mimetype_guess_file.

While at it rename local variable from $mime to $mimetype (in
mimetype_guess_file) to better reflect its value (its contents).

Signed-off-by: Jakub Narebski <redacted>
---
Perl::Critic::Policy::InputOutput::ProhibitBarewordFileHandles

  Write open my $fh, q{<}, $filename; instead of open FH, q{<}, $filename;.

  Using bareword symbols to refer to file handles is particularly evil
  because they are global, and you have no idea if that symbol already
  points to some other file handle. You can mitigate some of that risk by
  'local'izing the symbol first, but that's pretty ugly. Since Perl 5.6, you
  can use an undefined scalar variable as a lexical reference to an
  anonymous filehandle.

See also Damian Conway's book "Perl Best Practices",
chapter "10.1. Filehandles" (Don't use bareword filehandles.)


This follows similar patch for git-send-email.perl by Bill Pemberton
http://permalink.gmane.org/gmane.comp.version-control.git/117886

CC-ed Pasky, who is responsible for code in both cases...

 gitweb/gitweb.perl |   22 +++++++++++-----------
 1 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 06e9160..a9daa1d 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2065,18 +2065,18 @@ sub git_get_project_ctags {
 	my $ctags = {};
 
 	$git_dir = "$projectroot/$path";
-	unless (opendir D, "$git_dir/ctags") {
+	unless (opendir my $dh, "$git_dir/ctags") {
 		return $ctags;
 	}
-	foreach (grep { -f $_ } map { "$git_dir/ctags/$_" } readdir(D)) {
-		open CT, $_ or next;
-		my $val = <CT>;
+	foreach (grep { -f $_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
+		open my $ct, $_ or next;
+		my $val = <$ct>;
 		chomp $val;
-		close CT;
+		close $ct;
 		my $ctag = $_; $ctag =~ s#.*/##;
 		$ctags->{$ctag} = $val;
 	}
-	closedir D;
+	closedir $dh;
 	$ctags;
 }
 
@@ -2804,18 +2804,18 @@ sub mimetype_guess_file {
 	-r $mimemap or return undef;
 
 	my %mimemap;
-	open(MIME, $mimemap) or return undef;
-	while (<MIME>) {
+	open(my $mh, $mimemap) or return undef;
+	while (<$mh>) {
 		next if m/^#/; # skip comments
-		my ($mime, $exts) = split(/\t+/);
+		my ($mimetype, $exts) = split(/\t+/);
 		if (defined $exts) {
 			my @exts = split(/\s+/, $exts);
 			foreach my $ext (@exts) {
-				$mimemap{$ext} = $mime;
+				$mimemap{$ext} = $mimetype;
 			}
 		}
 	}
-	close(MIME);
+	close($mh);
 
 	$filename =~ /\.([^.]*)$/;
 	return $mimemap{$1};
-- 
1.6.3
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help