git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Jakub Narebski <jnareb@gmail.com>
Date
May 11, 2009, 01:21 UTC
Message-ID
<200905110321.08109.jnareb@gmail.com>
In-Reply-To
<200905100236.20158.jnareb@gmail.com>
gitweb: Do not use bareword filehandles

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 <jnareb@gmail.com>
---
I'm extremely sorry for this stupid mistake. Below there is interdiff
(indented, as to not be mistaken for diff itself)
	diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
	index a9daa1d..584644c 100755
	--- a/gitweb/gitweb.perl
	+++ b/gitweb/gitweb.perl
	@@ -2065,9 +2065,8 @@ sub git_get_project_ctags {
	        my $ctags = {};
	 
	        $git_dir = "$projectroot/$path";
	-       unless (opendir my $dh, "$git_dir/ctags") {
	-               return $ctags;
	-       }
	+       opendir my $dh, "$git_dir/ctags"
	+               or return $ctags;
	        foreach (grep { -f $_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
	                open my $ct, $_ or next;
	                my $val = <$ct>;
 gitweb/gitweb.perl |   25 ++++++++++++-------------
 1 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 06e9160..584644c 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2065,18 +2065,17 @@ sub git_get_project_ctags {
 	my $ctags = {};
 
 	$git_dir = "$projectroot/$path";
-	unless (opendir D, "$git_dir/ctags") {
-		return $ctags;
-	}
-	foreach (grep { -f $_ } map { "$git_dir/ctags/$_" } readdir(D)) {
-		open CT, $_ or next;
-		my $val = <CT>;
+	opendir my $dh, "$git_dir/ctags"
+		or return $ctags;
+	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 +2803,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
Previous: Jakub NarebskiNext: Jakub Narebski
Message 7 of 16 in “gitweb: Some code cleanups (up to perlcritic --stern)”
  1. 0/5 gitweb: Some code cleanups (up to perlcritic --stern)Jakub Narebski, May 10, 2009
  2. 1/5 gitweb: Remove function prototypesJakub Narebski, May 10, 2009
  3. Jakub NarebskiMay 10, 2009
  4. 2/5 gitweb: Do not use bareword filehandlesJakub Narebski, May 10, 2009
  5. Petr BaudisMay 10, 2009
  6. Jakub NarebskiMay 10, 2009
  7. 2/5 gitweb: Do not use bareword filehandlesJakub Narebski, May 11, 2009
  8. 3/5 gitweb: Always use three argument form of openJakub Narebski, May 10, 2009
  9. 3/5 gitweb: Always use three argument form of openJakub Narebski, May 11, 2009
  10. 4/5 gitweb: Localize magic variable $/Jakub Narebski, May 10, 2009
  11. 5/5 gitweb: Use block form of map/grep in a few cases moreJakub Narebski, May 10, 2009
  12. Junio C HamanoMay 11, 2009
  13. Jakub NarebskiMay 11, 2009
  14. Junio C HamanoMay 11, 2009
  15. Daniel PittmanMay 11, 2009
  16. Jakub NarebskiMay 11, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.