git-svn: avoid filling up the disk with temp files.
[gitweb.git] / git-svn.perl
index dcb8b779c8c97df8197185d614a11568ed84cbe8..50ace22da24be76d731dfdba852f967ca80569aa 100755 (executable)
@@ -1023,6 +1023,7 @@ sub get_commit_entry {
                my $in_msg = 0;
                my $author;
                my $saw_from = 0;
+               my $msgbuf = "";
                while (<$msg_fh>) {
                        if (!$in_msg) {
                                $in_msg = 1 if (/^\s*$/);
@@ -1035,14 +1036,15 @@ sub get_commit_entry {
                                if (/^From:/ || /^Signed-off-by:/) {
                                        $saw_from = 1;
                                }
-                               print $log_fh $_ or croak $!;
+                               $msgbuf .= $_;
                        }
                }
+               $msgbuf =~ s/\s+$//s;
                if ($Git::SVN::_add_author_from && defined($author)
                    && !$saw_from) {
-                       print $log_fh "\nFrom: $author\n"
-                             or croak $!;
+                       $msgbuf .= "\n\nFrom: $author";
                }
+               print $log_fh $msgbuf or croak $!;
                command_close_pipe($msg_fh, $ctx);
        }
        close $log_fh or croak $!;
@@ -1923,7 +1925,7 @@ sub prop_walk {
 
        foreach (sort keys %$dirent) {
                next if $dirent->{$_}->{kind} != $SVN::Node::dir;
-               $self->prop_walk($p . $_, $rev, $sub);
+               $self->prop_walk($self->{path} . $p . $_, $rev, $sub);
        }
 }
 
@@ -2575,8 +2577,8 @@ sub rebuild {
        my ($log, $ctx) =
            command_output_pipe(qw/rev-list --pretty=raw --no-color --reverse/,
                                $self->refname, '--');
-       my $full_url = $self->full_url;
-       remove_username($full_url);
+       my $metadata_url = $self->metadata_url;
+       remove_username($metadata_url);
        my $svn_uuid = $self->ra_uuid;
        my $c;
        while (<$log>) {
@@ -2594,7 +2596,7 @@ sub rebuild {
                # if we merged or otherwise started elsewhere, this is
                # how we break out of it
                if (($uuid ne $svn_uuid) ||
-                   ($full_url && $url && ($url ne $full_url))) {
+                   ($metadata_url && $url && ($url ne $metadata_url))) {
                        next;
                }
 
@@ -3241,7 +3243,9 @@ sub close_file {
                my ($tmp_fh, $tmp_filename) = File::Temp::tempfile(UNLINK => 1);
                my $result;
                while ($result = sysread($fh, my $string, 1024)) {
-                       syswrite($tmp_fh, $string, $result);
+                       my $wrote = syswrite($tmp_fh, $string, $result);
+                       defined($wrote) && $wrote == $result
+                               or croak("write $tmp_filename: $!\n");
                }
                defined $result or croak $!;
                close $tmp_fh or croak $!;
@@ -3249,6 +3253,7 @@ sub close_file {
                close $fh or croak $!;
 
                $hash = $::_repository->hash_and_insert_object($tmp_filename);
+               unlink($tmp_filename);
                $hash =~ /^[a-f\d]{40}$/ or die "not a sha1: $hash\n";
                close $fb->{base} or croak $!;
        } else {