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

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

From
Marcus Griep <marcus@griep.us>
Date
Sep 8, 2008, 15:51 UTC
Message-ID
<1220889063-20387-1-git-send-email-marcus@griep.us>
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
Previous: Abhijit Menon-SenNext: Marcus Griep
Message 11 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.