git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Git.pm: Use File::Temp->tempfile instead of ->new

From
AMAbhijit Menon-Sen <ams@toroid.org>
Date
Sep 8, 2008, 08:05 UTC
Message-ID
<20080908080548.GA3206@toroid.org>
In-Reply-To
<48C40670.6090106@gmail.com>
At 2008-09-07 12:50:56 -0400, neoeinstein@gmail.com wrote:
>
> As I was the one who brought File::Temp->new over from git-svn, I can
> take a look at reducing the dependency to ->tempfile.  If you don't
> patch in first, I'll get one in as well.
Please do.

Here's my latest patch, in case you find it useful as a starting point. I do not have more time or inclination to work on this at the moment. The problem with this patch is that the caller (git-svn in this case) assumes that a File::Temp object will be returned, and depends on the OO interface (e.g. by calling $tmp_fh->filename).

Unfortunately, I do not think the problem is limited to filename(). I blessed $$temp_fd into a stub package that provided a fake filename() method, but t9100-git-svn-basic.sh failed a little further on, and I did not investigate further. Anyway, I don't think emulating the File::Temp OO interface is a good solution at all.

(Tom: I'm sorry I ran out of energy before I could put together a complete fix for you.)

-- ams
From: Abhijit Menon-Sen <ams@toroid.org>
Date: Mon, 8 Sep 2008 12:26:59 +0530
Subject: [PATCH] Git.pm: Use File::Temp->tempfile instead of ->new

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.

Signed-off-by: Abhijit Menon-Sen <ams@toroid.org>
---
 perl/Git.pm |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/perl/Git.pm b/perl/Git.pm
index 102e6a4..b0498ca 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -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,10 +1021,13 @@ 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");
+		eval {
+			($$temp_fd) = File::Temp->tempfile(
+				'Git_XXXXXX',
+				DIR => File::Spec->tmpdir
+			);
+		};
+		throw Error::Simple("couldn't open new temp file") if $@;
 		$$temp_fd->autoflush;
 		binmode $$temp_fd;
 	}
-- 
1.6.0.1.196.g01914
Previous: Marcus GriepNext: Marcus Griep
Message 10 of 23 in “Git 1.6.0.1 breaks git-svn with perl 5.8.0”
  1. Tom G. ChristensenSep 1, 2008
  2. Matthieu MoySep 1, 2008
  3. Git.pm: Require File::Temp 0.14 for new()Abhijit Menon-Sen, Sep 1, 2008
  4. Tom G. ChristensenSep 1, 2008
  5. Git.pm: Use File::Temp->tempfile instead of ->newAbhijit Menon-Sen, Sep 1, 2008
  6. Tom G. ChristensenSep 1, 2008
  7. Junio C HamanoSep 7, 2008
  8. Abhijit Menon-SenSep 7, 2008
  9. Marcus GriepSep 7, 2008
  10. Abhijit Menon-SenSep 8, 2008
  11. Git.pm: Use File::Temp->tempfile instead of ->newMarcus Griep, Sep 8, 2008
  12. Git.pm: Use File::Temp->tempfile instead of ->newMarcus Griep, Sep 8, 2008
  13. Eric WongSep 9, 2008
  14. Junio C HamanoSep 10, 2008
  15. Eric WongSep 10, 2008
  16. Abhijit Menon-SenSep 9, 2008
  17. Marcus GriepSep 9, 2008
  18. Tom G. ChristensenSep 9, 2008
  19. Marcus GriepSep 9, 2008
  20. Tom G. ChristensenSep 10, 2008
  21. git-svn: Fixes my() parameter list syntax error in pre-5.8 PerlMarcus Griep, Sep 10, 2008
  22. Marcus GriepSep 10, 2008
  23. Tom G. ChristensenSep 1, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.