threads / patch / 5580

patchgitweb: fix uninitialized variable warning.

Subject: [PATCH] gitweb: fix uninitialized variable warning.

## tl;dr

2 messages between Sep 16, 2006 and Sep 17, 2006. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Martin Waitz· Sep 16, 2006, 21:09 UTC · lore

Perl spit out a varning when "blob" or "blob_plain" actions were used without a $hash parameter.

Signed-off-by: Martin Waitz <tali@admingilde.org>
---
 gitweb/gitweb.perl |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)
Show changes to gitweb/gitweb.perl +8 −8
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 2789657..ee561c6 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2380,11 +2380,7 @@ sub git_heads {
 }
 
 sub git_blob_plain {
-	# blobs defined by non-textual hash id's can be cached
 	my $expires;
-	if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
-		$expires = "+1d";
-	}
 
 	if (!defined $hash) {
 		if (defined $file_name) {
@@ -2394,7 +2390,11 @@ sub git_blob_plain {
 		} else {
 			die_error(undef, "No file name defined");
 		}
+	} elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
+		# blobs defined by non-textual hash id's can be cached
+		$expires = "+1d";
 	}
+
 	my $type = shift;
 	open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
 		or die_error(undef, "Couldn't cat $file_name, $hash");
@@ -2422,11 +2422,7 @@ sub git_blob_plain {
 }
 
 sub git_blob {
-	# blobs defined by non-textual hash id's can be cached
 	my $expires;
-	if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
-		$expires = "+1d";
-	}
 
 	if (!defined $hash) {
 		if (defined $file_name) {
@@ -2436,7 +2432,11 @@ sub git_blob {
 		} else {
 			die_error(undef, "No file name defined");
 		}
+	} elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
+		# blobs defined by non-textual hash id's can be cached
+		$expires = "+1d";
 	}
+
 	my $have_blame = gitweb_check_feature('blame');
 	open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
 		or die_error(undef, "Couldn't cat $file_name, $hash");
-- 
1.4.2.gb8b6b

-- 
Martin Waitz
Junio C Hamano· Sep 17, 2006, 09:00 UTC · re: Martin Waitz · lore

Re: [PATCH] gitweb: fix uninitialized variable warning.

Martin Waitz <tali@admingilde.org> writes:
Show 12 quoted lines
> @@ -2436,7 +2432,11 @@ sub git_blob {
>  		} else {
>  			die_error(undef, "No file name defined");
>  		}
> +	} elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
> +		# blobs defined by non-textual hash id's can be cached
> +		$expires = "+1d";
>  	}
> +
>  	my $have_blame = gitweb_check_feature('blame');
>  	open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
>  		or die_error(undef, "Couldn't cat $file_name, $hash");
Will apply, but you seem to be out of sync.

← back to recent threads