git-svn: Eliminate temp file usage in libsvn_get_file()
This means we'll have a loose object when we encounter a symlink but that's not the common case. We also don't have to worry about svn:eol-style when using the SVN libraries, either. So remove the code to deal with that. Signed-off-by: Eric Wong <normalperson@yhbt.net>
Eric Wong committed
Jun 15, 2006 at 13:36 UTC
968bdf1f3da677255c8950bb5b5a9de7e1150279
1 file changed
+23
-33
contrib/git-svn/git-svn.perl
+23
-33
@@ -31,6 +31,7 @@ use File::Path qw/mkpath/;
31
use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev pass_through/;
32
use File::Spec qw//;
33
use POSIX qw/strftime/;
34
+use IPC::Open3;
35
use Memoize;
36
memoize('revisions_eq');
37
@@ -2335,47 +2336,36 @@ sub libsvn_get_file {
2336
my $p = $f;
2337
return unless ($p =~ s#^\Q$SVN_PATH\E/?##);
2338
2338
- my $fd = IO::File->new_tmpfile or croak $!;
2339
+ my ($hash, $pid, $in, $out);
2340
my $pool = SVN::Pool->new;
2340
- my ($r, $props) = $SVN->get_file($f, $rev, $fd, $pool);
2341
+ defined($pid = open3($in, $out, '>&STDERR',
2342
+ qw/git-hash-object -w --stdin/)) or croak $!;
2343
+ my ($r, $props) = $SVN->get_file($f, $rev, $in, $pool);
2344
+ $in->flush == 0 or croak $!;
2345
+ close $in or croak $!;
2346
$pool->clear;
2342
- $fd->flush == 0 or croak $!;
2343
- seek $fd, 0, 0 or croak $!;
2344
- if (my $es = $props->{'svn:eol-style'}) {
2345
- my $new_fd = IO::File->new_tmpfile or croak $!;
2346
- eol_cp_fd($fd, $new_fd, $es);
2347
- close $fd or croak $!;
2348
- $fd = $new_fd;
2349
- seek $fd, 0, 0 or croak $!;
2350
- $fd->flush == 0 or croak $!;
2351
- }
2352
- my $mode = '100644';
2353
- if (exists $props->{'svn:executable'}) {
2354
- $mode = '100755';
2355
- }
2347
+ chomp($hash = do { local $/; <$out> });
2348
+ close $out or croak $!;
2349
+ waitpid $pid, 0;
2350
+ $hash =~ /^$sha1$/o or die "not a sha1: $hash\n";
2351
+
2352
+ my $mode = exists $props->{'svn:executable'} ? '100755' : '100644';
2353
if (exists $props->{'svn:special'}) {
2354
$mode = '120000';
2358
- local $/;
2359
- my $link = <$fd>;
2355
+ my $link = `git-cat-file blob $hash`;
2356
$link =~ s/^link // or die "svn:special file with contents: <",
2357
$link, "> is not understood\n";
2362
- seek $fd, 0, 0 or croak $!;
2363
- truncate $fd, 0 or croak $!;
2364
- print $fd $link or croak $!;
2365
- seek $fd, 0, 0 or croak $!;
2366
- $fd->flush == 0 or croak $!;
2367
- }
2368
- my $pid = open my $ho, '-|';
2369
- defined $pid or croak $!;
2370
- if (!$pid) {
2371
- open STDIN, '<&', $fd or croak $!;
2372
- exec qw/git-hash-object -w --stdin/ or croak $!;
2358
+ defined($pid = open3($in, $out, '>&STDERR',
2359
+ qw/git-hash-object -w --stdin/)) or croak $!;
2360
+ print $in $link;
2361
+ $in->flush == 0 or croak $!;
2362
+ close $in or croak $!;
2363
+ chomp($hash = do { local $/; <$out> });
2364
+ close $out or croak $!;
2365
+ waitpid $pid, 0;
2366
+ $hash =~ /^$sha1$/o or die "not a sha1: $hash\n";
2367
}
2374
- chomp(my $hash = do { local $/; <$ho> });
2375
- close $ho or croak $?;
2376
- $hash =~ /^$sha1$/o or die "not a sha1: $hash\n";
2368
print $gui $mode,' ',$hash,"\t",$p,"\0" or croak $!;
2378
- close $fd or croak $?;
2369
}
2370
2371
sub libsvn_log_entry {