cvsimport: introduce _fetchfile() method and used a 1M buffer to read()
File retrieval from the socket is now moved to _fetchfile() and we now cap reads at 1MB. This should limit the memory growth of the cvsimport process. Signed-off-by: Martin Langhoff <martin@catalyst.net.nz> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
e73aefe4fd
commit
55cad84299
@ -315,15 +315,7 @@ sub _line {
|
|||||||
chomp $cnt;
|
chomp $cnt;
|
||||||
die "Duh: Filesize $cnt" if $cnt !~ /^\d+$/;
|
die "Duh: Filesize $cnt" if $cnt !~ /^\d+$/;
|
||||||
$line="";
|
$line="";
|
||||||
$res=0;
|
$res = $self->_fetchfile($fh, $cnt);
|
||||||
while($cnt) {
|
|
||||||
my $buf;
|
|
||||||
my $num = $self->{'socketi'}->read($buf,$cnt);
|
|
||||||
die "Server: Filesize $cnt: $num: $!\n" if not defined $num or $num<=0;
|
|
||||||
print $fh $buf;
|
|
||||||
$res += $num;
|
|
||||||
$cnt -= $num;
|
|
||||||
}
|
|
||||||
} elsif($line =~ s/^ //) {
|
} elsif($line =~ s/^ //) {
|
||||||
print $fh $line;
|
print $fh $line;
|
||||||
$res += length($line);
|
$res += length($line);
|
||||||
@ -335,14 +327,7 @@ sub _line {
|
|||||||
chomp $cnt;
|
chomp $cnt;
|
||||||
die "Duh: Mbinary $cnt" if $cnt !~ /^\d+$/ or $cnt<1;
|
die "Duh: Mbinary $cnt" if $cnt !~ /^\d+$/ or $cnt<1;
|
||||||
$line="";
|
$line="";
|
||||||
while($cnt) {
|
$res += $self->_fetchfile($fh, $cnt);
|
||||||
my $buf;
|
|
||||||
my $num = $self->{'socketi'}->read($buf,$cnt);
|
|
||||||
die "S: Mbinary $cnt: $num: $!\n" if not defined $num or $num<=0;
|
|
||||||
print $fh $buf;
|
|
||||||
$res += $num;
|
|
||||||
$cnt -= $num;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
chomp $line;
|
chomp $line;
|
||||||
if($line eq "ok") {
|
if($line eq "ok") {
|
||||||
@ -384,6 +369,23 @@ sub file {
|
|||||||
|
|
||||||
return ($name, $res);
|
return ($name, $res);
|
||||||
}
|
}
|
||||||
|
sub _fetchfile {
|
||||||
|
my ($self, $fh, $cnt) = @_;
|
||||||
|
my $res;
|
||||||
|
my $bufsize = 1024 * 1024;
|
||||||
|
while($cnt) {
|
||||||
|
if ($bufsize > $cnt) {
|
||||||
|
$bufsize = $cnt;
|
||||||
|
}
|
||||||
|
my $buf;
|
||||||
|
my $num = $self->{'socketi'}->read($buf,$bufsize);
|
||||||
|
die "Server: Filesize $cnt: $num: $!\n" if not defined $num or $num<=0;
|
||||||
|
print $fh $buf;
|
||||||
|
$res += $num;
|
||||||
|
$cnt -= $num;
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
package main;
|
package main;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user