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

[PATCH v2 3/5] gitweb: Always use three argument form of open

From
Jakub Narebski <jnareb@gmail.com>
Date
May 11, 2009, 01:29 UTC
Message-ID
<200905110329.40666.jnareb@gmail.com>
In-Reply-To
<200905100238.34838.jnareb@gmail.com>
>From 94638fb6edf3ea693228c680a6a30271ccd77522 Mon Sep 17 00:00:00 2001
From: Jakub Narebski <jnareb@gmail.com>
Date: Mon, 11 May 2009 03:25:55 +0200
Subject: [PATCH] gitweb: Localize magic variable $/

Instead of undefining and then restoring magic variable $/ (input record separator) for 'slurp mode', localize it.

While at it, state explicitely that "local $/;" makes it undefined, by using explicit "local $/ = undef;".

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This also required correction. I am extremely sorry about that.
Below there is (whitespace mangled) interdiff to previous version
	diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
	index 76c0684..4efeeed 100755
	--- a/gitweb/gitweb.perl
	+++ b/gitweb/gitweb.perl
	@@ -4906,11 +4906,12 @@ sub git_tree {
	        }
	        die_error(404, "No such tree") unless defined($hash);
	 
	+       my @entries = ();
	        {
	                local $/ = "\0";
	                open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
	                        or die_error(500, "Open git-ls-tree failed");
	-               my @entries = map { chomp; $_ } <$fd>;
	+               @entries = map { chomp; $_ } <$fd>;
	                close $fd
	                        or die_error(404, "Reading tree failed");
	        }
 gitweb/gitweb.perl |   25 ++++++++++++++-----------
 1 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index e7cab90..4efeeed 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3325,7 +3325,7 @@ sub git_get_link_target {
 	open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
 		or return;
 	{
-		local $/;
+		local $/ = undef;
 		$link_target = <$fd>;
 	}
 	close $fd
@@ -4800,11 +4800,10 @@ sub git_blob_plain {
 		-content_disposition =>
 			($sandbox ? 'attachment' : 'inline')
 			. '; filename="' . $save_as . '"');
-	undef $/;
+	local $/ = undef;
 	binmode STDOUT, ':raw';
 	print <$fd>;
 	binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
-	$/ = "\n";
 	close $fd;
 }
 
@@ -4906,12 +4905,16 @@ sub git_tree {
 		}
 	}
 	die_error(404, "No such tree") unless defined($hash);
-	$/ = "\0";
-	open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
-		or die_error(500, "Open git-ls-tree failed");
-	my @entries = map { chomp; $_ } <$fd>;
-	close $fd or die_error(404, "Reading tree failed");
-	$/ = "\n";
+
+	my @entries = ();
+	{
+		local $/ = "\0";
+		open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
+			or die_error(500, "Open git-ls-tree failed");
+		@entries = map { chomp; $_ } <$fd>;
+		close $fd
+			or die_error(404, "Reading tree failed");
+	}
 
 	my $refs = git_get_references();
 	my $ref = format_ref_marker($refs, $hash_base);
@@ -5806,7 +5809,7 @@ sub git_search {
 
 		print "<table class=\"pickaxe search\">\n";
 		my $alternate = 1;
-		$/ = "\n";
+		local $/ = "\n";
 		open my $fd, '-|', git_cmd(), '--no-pager', 'log', @diff_opts,
 			'--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
 			($search_use_regexp ? '--pickaxe-regex' : ());
@@ -5876,7 +5879,7 @@ sub git_search {
 		print "<table class=\"grep_search\">\n";
 		my $alternate = 1;
 		my $matches = 0;
-		$/ = "\n";
+		local $/ = "\n";
 		open my $fd, "-|", git_cmd(), 'grep', '-n',
 			$search_use_regexp ? ('-E', '-i') : '-F',
 			$searchtext, $co{'tree'};
-- 
1.6.3
Previous: Jakub NarebskiNext: Jakub Narebski
Message 9 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.