Re: [PATCH 12/18] gitweb: Change file handles (in caching) to lexical variables as opposed to globs
- From
Jakub Narebski <jnareb@gmail.com>
- Date
- Dec 10, 2010, 00:16 UTC
- Message-ID
- <m3d3pa1o0j.fsf@localhost.localdomain>
- In-Reply-To
- <1291931844-28454-13-git-send-email-warthog9@eaglescrag.net>
"John 'Warthog9' Hawley" <warthog9@eaglescrag.net> writes:
Show 22 quoted lines
> 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 <warthog9@eaglescrag.net> > --- > 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?
Show 14 quoted lines
> +
> 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