Skip to content

Commit 510b094

Browse files
neoeinsteinEric Wong
authored andcommitted
git-svn: Reduce temp file usage when dealing with non-links
Currently, in sub 'close_file', git-svn creates a temporary file and copies the contents of the blob to be written into it. This is useful for symlinks because svn stores symlinks in the form: link $FILE_PATH Git creates a blob only out of '$FILE_PATH' and uses file mode to indicate that the blob should be interpreted as a symlink. As git-hash-object is invoked with --stdin-paths, a duplicate of the link from svn must be created that leaves off the first five bytes, i.e. 'link '. However, this is wholly unnecessary for normal blobs, though, as we already have a temp file with their contents. Copying the entire file gains nothing, and effectively requires a file to be written twice before making it into the object db. This patch corrects that issue, holding onto the substr-like duplication for symlinks, but skipping it altogether for normal blobs by reusing the existing temp file. Signed-off-by: Marcus Griep <marcus@griep.us> Acked-by: Eric Wong <normalperson@yhbt.net>
1 parent 0b19138 commit 510b094

1 file changed

Lines changed: 22 additions & 24 deletions

File tree

git-svn.perl

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3268,38 +3268,36 @@ sub close_file {
32683268
"expected: $exp\n got: $got\n";
32693269
}
32703270
}
3271-
sysseek($fh, 0, 0) or croak $!;
32723271
if ($fb->{mode_b} == 120000) {
3273-
eval {
3274-
sysread($fh, my $buf, 5) == 5 or croak $!;
3275-
$buf eq 'link ' or die "$path has mode 120000",
3276-
" but is not a link";
3277-
};
3278-
if ($@) {
3279-
warn "$@\n";
3280-
sysseek($fh, 0, 0) or croak $!;
3281-
}
3282-
}
3283-
3284-
my $tmp_fh = Git::temp_acquire('svn_hash');
3285-
my $result;
3286-
while ($result = sysread($fh, my $string, 1024)) {
3287-
my $wrote = syswrite($tmp_fh, $string, $result);
3288-
defined($wrote) && $wrote == $result
3289-
or croak("write ",
3290-
$tmp_fh->filename, ": $!\n");
3291-
}
3292-
defined $result or croak $!;
3272+
sysseek($fh, 0, 0) or croak $!;
3273+
sysread($fh, my $buf, 5) == 5 or croak $!;
32933274

3275+
unless ($buf eq 'link ') {
3276+
warn "$path has mode 120000",
3277+
" but is not a link\n";
3278+
} else {
3279+
my $tmp_fh = Git::temp_acquire('svn_hash');
3280+
my $res;
3281+
while ($res = sysread($fh, my $str, 1024)) {
3282+
my $out = syswrite($tmp_fh, $str, $res);
3283+
defined($out) && $out == $res
3284+
or croak("write ",
3285+
$tmp_fh->filename,
3286+
": $!\n");
3287+
}
3288+
defined $res or croak $!;
32943289

3295-
Git::temp_release($fh, 1);
3290+
($fh, $tmp_fh) = ($tmp_fh, $fh);
3291+
Git::temp_release($tmp_fh, 1);
3292+
}
3293+
}
32963294

32973295
$hash = $::_repository->hash_and_insert_object(
3298-
$tmp_fh->filename);
3296+
$fh->filename);
32993297
$hash =~ /^[a-f\d]{40}$/ or die "not a sha1: $hash\n";
33003298

33013299
Git::temp_release($fb->{base}, 1);
3302-
Git::temp_release($tmp_fh, 1);
3300+
Git::temp_release($fh, 1);
33033301
} else {
33043302
$hash = $fb->{blob} or die "no blob information\n";
33053303
}

0 commit comments

Comments
 (0)