git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Prevent warning
@ 2018-10-29 15:39 Pete
  2018-10-29 15:54 ` Torsten Bögershausen
  2018-10-29 16:33 ` Jeff King
  0 siblings, 2 replies; 3+ messages in thread
From: Pete @ 2018-10-29 15:39 UTC (permalink / raw)
  To: git

Prevent the following warning in the web server error log:
gitweb.cgi: Odd number of elements in anonymous hash at /usr/share/gitweb/gitweb.cgi line 3305
---
 gitweb/gitweb.perl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 2594a4badb3d7..200647b683225 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3302,7 +3302,7 @@ sub git_get_remotes_list {
 		next if $wanted and not $remote eq $wanted;
 		my ($url, $key) = ($1, $2);
 
-		$remotes{$remote} ||= { 'heads' => () };
+		$remotes{$remote} ||= { 'heads' => [] };
 		$remotes{$remote}{$key} = $url;
 	}
 	close $fd or return;

--
https://github.com/git/git/pull/548

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Prevent warning
  2018-10-29 15:39 [PATCH] Prevent warning Pete
@ 2018-10-29 15:54 ` Torsten Bögershausen
  2018-10-29 16:33 ` Jeff King
  1 sibling, 0 replies; 3+ messages in thread
From: Torsten Bögershausen @ 2018-10-29 15:54 UTC (permalink / raw)
  To: Pete; +Cc: git

Thanks for the patch.
Could you please sign it off ?
The other remark would be if the header line could be written longer than
just
"Prevent warning".
to give people digging into the Git history an initial information,
where the warning occured and from which module it was caused.
May be something like this as a head line ?

gitweb.perl: Fix Odd number of elements warning



On Mon, Oct 29, 2018 at 03:39:30PM +0000, Pete wrote:
> Prevent the following warning in the web server error log:
> gitweb.cgi: Odd number of elements in anonymous hash at /usr/share/gitweb/gitweb.cgi line 3305
> ---
>  gitweb/gitweb.perl | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index 2594a4badb3d7..200647b683225 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -3302,7 +3302,7 @@ sub git_get_remotes_list {
>  		next if $wanted and not $remote eq $wanted;
>  		my ($url, $key) = ($1, $2);
>  
> -		$remotes{$remote} ||= { 'heads' => () };
> +		$remotes{$remote} ||= { 'heads' => [] };
>  		$remotes{$remote}{$key} = $url;
>  	}
>  	close $fd or return;
> 
> --
> https://github.com/git/git/pull/548

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Prevent warning
  2018-10-29 15:39 [PATCH] Prevent warning Pete
  2018-10-29 15:54 ` Torsten Bögershausen
@ 2018-10-29 16:33 ` Jeff King
  1 sibling, 0 replies; 3+ messages in thread
From: Jeff King @ 2018-10-29 16:33 UTC (permalink / raw)
  To: Pete; +Cc: git

On Mon, Oct 29, 2018 at 03:39:30PM +0000, Pete wrote:

> Prevent the following warning in the web server error log:
> gitweb.cgi: Odd number of elements in anonymous hash at /usr/share/gitweb/gitweb.cgi line 3305
> [...]
> -		$remotes{$remote} ||= { 'heads' => () };
> +		$remotes{$remote} ||= { 'heads' => [] };

This will indeed silence the warning, but the end result is different.
In the original, 'heads' would be set to undef, but now it is set to an
empty array reference.

Do the later users of the struct care about the distinction?

Grepping around, I see two callers that look at "heads":

 1. fill_remote_heads() assigns to it unconditionally, overwriting
    whatever was there before.

 2. git_remote_block() dereferences it as an array reference, and so
    probably would have complained if we ever got there with the undef.
    But we never would, because every call to git_remote_block() is
    preceded by a call to fill_remote_heads().

So nobody actually ever looks at the value we set here. Is an empty
array reference better than undef as a default value? I'd actually argue
no. If we add new code that does not call fill_remote_heads(), it's
probably better for it to be undef to distinguish it from the empty list
(and possibly raise an error that would tell us that we forgot to call
fill_remote_heads().

So I'd say that:

  $remotes{$remote} ||= { heads => undef };

is a preferable conversion. Or simply deleting the line entirely, which
has roughly the same effect.

-Peff

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-10-29 16:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-29 15:39 [PATCH] Prevent warning Pete
2018-10-29 15:54 ` Torsten Bögershausen
2018-10-29 16:33 ` Jeff King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).