cvsexportcommit: fix massive commits

Because we feed the changed filenames to CVS on the command
line, it was possible for massive commits to overflow the
system exec limits. Instead, we now do an xargs-like split
of the arguments.

This means that we lose some of the atomicity of calling CVS
in one shot. Since CVS commits are not atomic, but the CVS
protocol is, the possible effects of this are not clear;
however, since CVS doesn't provide a different interface,
this is our only option for large commits (short of writing
a CVS client library).

The argument size limit is arbitrarily set to 64kB. This
should be high enough to trigger only in rare cases where it
is necessary, so normal-sized commits are not affected by
the atomicity change.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King 2007-12-14 04:15:47 -05:00 committed by Junio C Hamano
parent 71362bd552
commit 38a5b1d6ed

View File

@ -195,11 +195,11 @@ foreach my $f (@files) {
my %cvsstat; my %cvsstat;
if (@canstatusfiles) { if (@canstatusfiles) {
if ($opt_u) { if ($opt_u) {
my @updated = safe_pipe_capture(@cvs, 'update', @canstatusfiles); my @updated = xargs_safe_pipe_capture([@cvs, 'update'], @canstatusfiles);
print @updated; print @updated;
} }
my @cvsoutput; my @cvsoutput;
@cvsoutput= safe_pipe_capture(@cvs, 'status', @canstatusfiles); @cvsoutput = xargs_safe_pipe_capture([@cvs, 'status'], @canstatusfiles);
my $matchcount = 0; my $matchcount = 0;
foreach my $l (@cvsoutput) { foreach my $l (@cvsoutput) {
chomp $l; chomp $l;
@ -295,7 +295,7 @@ if ($dirtypatch) {
if ($opt_c) { if ($opt_c) {
print "Autocommit\n $cmd\n"; print "Autocommit\n $cmd\n";
print safe_pipe_capture(@cvs, 'commit', '-F', '.msg', @files); print xargs_safe_pipe_capture([@cvs, 'commit', '-F', '.msg'], @files);
if ($?) { if ($?) {
die "Exiting: The commit did not succeed"; die "Exiting: The commit did not succeed";
} }
@ -335,15 +335,24 @@ sub safe_pipe_capture {
return wantarray ? @output : join('',@output); return wantarray ? @output : join('',@output);
} }
sub safe_pipe_capture_blob { sub xargs_safe_pipe_capture {
my $output; my $MAX_ARG_LENGTH = 65536;
if (my $pid = open my $child, '-|') { my $cmd = shift;
local $/; my @output;
undef $/; my $output;
$output = (<$child>); while(@_) {
close $child or die join(' ',@_).": $! $?"; my @args;
} else { my $length = 0;
exec(@_) or die "$! $?"; # exec() can fail the executable can't be found while(@_ && $length < $MAX_ARG_LENGTH) {
} push @args, shift;
return $output; $length += length($args[$#args]);
}
if (wantarray) {
push @output, safe_pipe_capture(@$cmd, @args);
}
else {
$output .= safe_pipe_capture(@$cmd, @args);
}
}
return wantarray ? @output : $output;
} }