Subject: Re: [PATCH 12/18] gitweb: Change file handles (in caching) to lexical variables as opposed to globs

From: Jakub Narebski <[email-masked]>
Date: Thu, 09 Dec 2010 16:16:20 -0800 (PST)

"John 'Warthog9' Hawley" <[email-masked]> writes:

> This isn't a huge change, it just adds global variables for the file handles,
> an additional cleanup to localize the variable a bit more which should alleviate
> the issues that Jakub had with my original approach.
> 
> Signed-off-by: John 'Warthog9' Hawley <[email-masked]>
> ---
>  gitweb/lib/cache.pl |  114 +++++++++++++++++++++++++++++++-------------------
>  1 files changed, 71 insertions(+), 43 deletions(-)
> 
> diff --git a/gitweb/lib/cache.pl b/gitweb/lib/cache.pl
> index 5182a94..fafc028 100644
> --- a/gitweb/lib/cache.pl
> +++ b/gitweb/lib/cache.pl
> @@ -14,6 +14,12 @@ use Digest::MD5 qw(md5 md5_hex md5_base64);
>  use Fcntl ':flock';
>  use File::Copy;
>  
> +# Global declarations
> +our $cacheFile;
> +our $cacheFileBG;
> +our $cacheFileBinWT;
> +our $cacheFileBin;

You are trading globs for global (well, package) variables.  They are
not lexical filehandles... though I'm not sure if it would be possible
without restructuring code; note that if variable holding filehandle
falls out of scope, then file would be automatically closed.

BTW. Do you really need all those types/variables?

> +
>  sub cache_fetch {
>  	my ($action) = @_;
>  	my $cacheTime = 0;
> @@ -49,9 +55,9 @@ sub cache_fetch {
>  	}else{
>  		#if cache is out dated, update
>  		#else displayCache();
> -		open(cacheFile, '<', "$fullhashpath");
> -		stat(cacheFile);
> -		close(cacheFile);
> +		open($cacheFile, '<', "$fullhashpath");
> +		stat($cacheFile);
> +		close($cacheFile);
[...]

-- 
Jakub Narebski
Poland
ShadeHawk on #git