From: Marcus Griep <marcus@griep.us>
To: Git Mailing List <git@vger.kernel.org>
Cc: Eric Wong <normalperson@yhbt.net>,
Junio C Hamano <gitster@pobox.com>,
Marcus Griep <marcus@griep.us>
Subject: [PATCH] Git.pm: Make File::Spec and File::Temp requirement lazy
Date: Fri, 15 Aug 2008 11:10:32 -0400 [thread overview]
Message-ID: <1218813032-18203-1-git-send-email-marcus@griep.us> (raw)
In-Reply-To: <20080814065800.GA16918@untitled>
This will ensure that the API at large is accessible to nearly
all Perl versions, while only the temp file caching API is tied to
the File::Temp and File::Spec modules being available.
Signed-off-by: Marcus Griep <marcus@griep.us>
---
Eric Wong wrote:
> What about just lazy requiring inside _temp_cache() so it
> won't get loaded by folks that don't need it? (completely untested):
>
> eval { require File::Temp };
> if ($@) {
> throw Error::Simple("couldn't require File::Temp: $@");
> }
> eval { require File::Spec };
> if ($@) {
> throw Error::Simple("couldn't require File::Spec: $@");
> }
>
> It'll also remove the minor performance hit CGI/gitweb users got since
> we won't load these extra modules during startup.
This recommendation is implemented with this patch, but in such a way that only
the first test will be used, and that result cached. That way we aren't doing
a compile _every_ time we want a temporary file, just the first time.
perl/Git.pm | 14 ++++++++++++--
1 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/perl/Git.pm b/perl/Git.pm
index 405f68f..9b6b637 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -100,8 +100,6 @@ use Carp qw(carp croak); # but croak is bad - throw instead
use Error qw(:try);
use Cwd qw(abs_path);
use IPC::Open2 qw(open2);
-use File::Temp ();
-require File::Spec;
use Fcntl qw(SEEK_SET SEEK_CUR);
}
@@ -940,6 +938,7 @@ sub _close_cat_blob {
{ # %TEMP_* Lexical Context
my (%TEMP_LOCKS, %TEMP_FILES);
+my $require_test;
=item temp_acquire ( NAME )
@@ -1009,6 +1008,8 @@ sub temp_release {
sub _temp_cache {
my ($name) = @_;
+ _verify_require();
+
my $temp_fd = \$TEMP_FILES{$name};
if (defined $$temp_fd and $$temp_fd->opened) {
if ($TEMP_LOCKS{$$temp_fd}) {
@@ -1031,6 +1032,15 @@ sub _temp_cache {
$$temp_fd;
}
+sub _verify_require {
+ unless (defined $require_test) {
+ $require_test = "";
+ eval { require File::Temp; require File::Spec; };
+ $require_test .= "$@";
+ }
+ $require_test and throw Error::Simple($require_test);
+}
+
=item temp_reset ( FILEHANDLE )
Truncates and resets the position of the C<FILEHANDLE>.
--
1.6.0.rc2.6.g8eda3
next prev parent reply other threads:[~2008-08-15 15:11 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-08 22:41 [PATCH] git-svn: Make it scream by minimizing temp files Marcus Griep
2008-08-08 22:59 ` Junio C Hamano
2008-08-09 1:12 ` Marcus Griep
2008-08-09 6:25 ` Eric Wong
2008-08-09 15:45 ` Marcus Griep
2008-08-10 1:46 ` Eric Wong
2008-08-10 3:53 ` Junio C Hamano
2008-08-10 7:47 ` Eric Wong
2008-08-10 8:26 ` Junio C Hamano
2008-08-10 8:09 ` Eric Wong
2008-08-11 15:53 ` [PATCH 0/3] git-svn and temporary file improvements Marcus Griep
2008-08-11 15:53 ` [PATCH 1/3] Git.pm: Add faculties to allow temp files to be cached Marcus Griep
2008-08-11 15:53 ` [PATCH 2/3] git-svn: Make it scream by minimizing temp files Marcus Griep
2008-08-11 15:53 ` [PATCH 3/3] git-svn: Reduce temp file usage when dealing with non-links Marcus Griep
2008-08-12 3:37 ` Eric Wong
2008-08-12 15:53 ` Marcus Griep
2008-08-12 16:01 ` Marcus Griep
2008-08-12 16:45 ` [PATCH v2 " Marcus Griep
2008-08-13 3:29 ` [PATCH " Eric Wong
2008-08-13 3:42 ` Marcus Griep
2008-08-13 3:52 ` Eric Wong
2008-08-12 3:14 ` [PATCH 2/3] git-svn: Make it scream by minimizing temp files Eric Wong
2008-08-12 15:50 ` Marcus Griep
2008-08-12 16:00 ` [PATCH 2/3] git-svn: Make it incrementally faster " Marcus Griep
2008-08-13 3:29 ` Eric Wong
2008-08-12 3:08 ` [PATCH 1/3] Git.pm: Add faculties to allow temp files to be cached Eric Wong
2008-08-12 15:41 ` Marcus Griep
2008-08-12 16:00 ` Marcus Griep
2008-08-13 3:28 ` Eric Wong
2008-08-13 20:05 ` Lea Wiemann
2008-08-13 20:13 ` Marcus Griep
2008-08-13 20:31 ` Marcus Griep
2008-08-13 20:38 ` Junio C Hamano
2008-08-13 22:28 ` Lea Wiemann
2008-08-13 22:30 ` [PATCH] Git.pm: require Perl 5.6.1 Lea Wiemann
2008-08-14 6:58 ` [PATCH 1/3] Git.pm: Add faculties to allow temp files to be cached Eric Wong
2008-08-15 15:10 ` Marcus Griep [this message]
2008-08-15 19:31 ` [PATCH] Git.pm: Make File::Spec and File::Temp requirement lazy Bryan Donlan
2008-08-15 19:46 ` Marcus Griep
2008-08-15 19:53 ` [PATCH v2] " Marcus Griep
2008-08-13 20:52 ` [PATCH 1/3] Git.pm: Add faculties to allow temp files to be cached Miklos Vajna
2008-08-14 6:29 ` Junio C Hamano
2008-08-14 14:35 ` Marcus Griep
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1218813032-18203-1-git-send-email-marcus@griep.us \
--to=marcus@griep.us \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=normalperson@yhbt.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).