@matheusbsbs / matheus-bagliano / commits / 510b0945d0
Fork 0

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>

Marcus Griep committed Aug 12, 2008 at 12:45 UTC 510b0945d041752db2f53dda00f1188308e2df4e
1 file changed +22 -24
git-svn.perl
+22 -24
@@ -3268,38 +3268,36 @@ sub close_file {
3268 "expected: $exp\n got: $got\n";
3269 }
3270 }
3271 - sysseek($fh, 0, 0) or croak $!;
3271 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 $!;
3274
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 $!;
3289
3295 - Git::temp_release($fh, 1);
3290 + ($fh, $tmp_fh) = ($tmp_fh, $fh);
3291 + Git::temp_release($tmp_fh, 1);
3292 + }
3293 + }
3294
3295 $hash = $::_repository->hash_and_insert_object(
3298 - $tmp_fh->filename);
3296 + $fh->filename);
3297 $hash =~ /^[a-f\d]{40}$/ or die "not a sha1: $hash\n";
3298
3299 Git::temp_release($fb->{base}, 1);
3302 - Git::temp_release($tmp_fh, 1);
3300 + Git::temp_release($fh, 1);
3301 } else {
3302 $hash = $fb->{blob} or die "no blob information\n";
3303 }