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>,
"Tom G. Christensen" <tgc@statsbiblioteket.dk>,
Abhijit Menon-Sen <ams@toroid.org>,
Marcus Griep <marcus@griep.us>
Subject: [PATCH] Git.pm: Use File::Temp->tempfile instead of ->new
Date: Mon, 8 Sep 2008 11:51:03 -0400 [thread overview]
Message-ID: <1220889063-20387-1-git-send-email-marcus@griep.us> (raw)
In-Reply-To: <20080908080548.GA3206@toroid.org>
Perl 5.8.0 ships with File::Temp 0.13, which does not have the new()
interface introduced in 0.14, as pointed out by Tom G. Christensen.
This modifies Git.pm to use the more established tempfile() interface
and updates 'git svn' to match.
Signed-off-by: Marcus Griep <marcus@griep.us>
---
Per the earlier patch versions by Abhijit Menon-Sen and Tom G. Christensen.
Both of you may want to run a test and add your 'Tested-by' to the thread
if everything works out before Eric Wong adds his 'Acked-by'.
git-svn.perl | 4 ++--
perl/Git.pm | 29 +++++++++++++++++++++++------
2 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/git-svn.perl b/git-svn.perl
index ee3f5ed..a6d75db 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -3304,7 +3304,7 @@ sub close_file {
my $out = syswrite($tmp_fh, $str, $res);
defined($out) && $out == $res
or croak("write ",
- $tmp_fh->filename,
+ Git::temp_filename($tmp_fh),
": $!\n");
}
defined $res or croak $!;
@@ -3315,7 +3315,7 @@ sub close_file {
}
$hash = $::_repository->hash_and_insert_object(
- $fh->filename);
+ Git::temp_filename($fh));
$hash =~ /^[a-f\d]{40}$/ or die "not a sha1: $hash\n";
Git::temp_release($fb->{base}, 1);
diff --git a/perl/Git.pm b/perl/Git.pm
index 102e6a4..3ea3fb2 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -937,7 +937,7 @@ sub _close_cat_blob {
{ # %TEMP_* Lexical Context
-my (%TEMP_LOCKS, %TEMP_FILES);
+my (%TEMP_LOCKS, %TEMP_FILES, %TEMP_FILENAMES);
=item temp_acquire ( NAME )
@@ -991,7 +991,7 @@ the same string.
sub temp_release {
my ($self, $temp_fd, $trunc) = _maybe_self(@_);
- if (ref($temp_fd) ne 'File::Temp') {
+ if (exists $TEMP_FILES{$temp_fd}) {
$temp_fd = $TEMP_FILES{$temp_fd};
}
unless ($TEMP_LOCKS{$temp_fd}) {
@@ -1021,12 +1021,12 @@ sub _temp_cache {
carp "Temp file '", $name,
"' was closed. Opening replacement.";
}
- $$temp_fd = File::Temp->new(
- TEMPLATE => 'Git_XXXXXX',
- DIR => File::Spec->tmpdir
- ) or throw Error::Simple("couldn't open new temp file");
+ my $fname;
+ ($$temp_fd, $fname) = File::Temp->tempfile('Git_XXXXXX')
+ or throw Error::Simple("couldn't open new temp file");
$$temp_fd->autoflush;
binmode $$temp_fd;
+ $TEMP_FILENAMES{$$temp_fd} = $fname;
}
$$temp_fd;
}
@@ -1053,6 +1053,23 @@ sub temp_reset {
or throw Error::Simple("expected file position to be reset");
}
+=item temp_filename ( NAME )
+
+=item temp_filename ( FILEHANDLE )
+
+Returns the filenae associated with the given tempfile.
+
+=cut
+
+sub temp_filename {
+ my ($self, $temp_fd) = _maybe_self(@_);
+
+ if (exists $TEMP_FILES{$temp_fd}) {
+ $temp_fd = $TEMP_FILES{$temp_fd};
+ }
+ $TEMP_FILENAMES{$temp_fd};
+}
+
sub END {
unlink values %TEMP_FILES if %TEMP_FILES;
}
--
1.6.0.1.400.gd2470
next prev parent reply other threads:[~2008-09-08 15:52 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-01 9:27 Git 1.6.0.1 breaks git-svn with perl 5.8.0 Tom G. Christensen
2008-09-01 9:46 ` Matthieu Moy
2008-09-01 10:04 ` [PATCH] Git.pm: Require File::Temp 0.14 for new() Abhijit Menon-Sen
2008-09-01 10:21 ` Tom G. Christensen
2008-09-01 10:42 ` [PATCH] Git.pm: Use File::Temp->tempfile instead of ->new Abhijit Menon-Sen
2008-09-01 11:03 ` Tom G. Christensen
2008-09-07 5:27 ` Junio C Hamano
2008-09-07 9:26 ` Abhijit Menon-Sen
2008-09-07 16:50 ` Marcus Griep
2008-09-08 8:05 ` Abhijit Menon-Sen
2008-09-08 15:51 ` Marcus Griep [this message]
2008-09-08 16:53 ` [PATCH v2] " Marcus Griep
2008-09-09 1:53 ` Eric Wong
2008-09-10 3:53 ` Junio C Hamano
2008-09-10 10:09 ` Eric Wong
2008-09-09 2:06 ` Abhijit Menon-Sen
2008-09-09 17:35 ` Marcus Griep
2008-09-09 7:41 ` Tom G. Christensen
2008-09-09 17:55 ` Marcus Griep
2008-09-10 7:16 ` Tom G. Christensen
2008-09-10 15:09 ` [PATCH] git-svn: Fixes my() parameter list syntax error in pre-5.8 Perl Marcus Griep
2008-09-10 15:11 ` Marcus Griep
2008-09-01 10:13 ` Git 1.6.0.1 breaks git-svn with perl 5.8.0 Tom G. Christensen
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=1220889063-20387-1-git-send-email-marcus@griep.us \
--to=marcus@griep.us \
--cc=ams@toroid.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=normalperson@yhbt.net \
--cc=tgc@statsbiblioteket.dk \
/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).