@matheusbsbs / matheus-bagliano / commits / 38a5b1d6ed
Fork 0

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>

Jeff King committed Dec 14, 2007 at 04:15 UTC 38a5b1d6ed2ba632504be7748e63f1441c93976d
1 file changed +23 -14
git-cvsexportcommit.perl
+23 -14
@@ -195,11 +195,11 @@ foreach my $f (@files) {
195 my %cvsstat;
196 if (@canstatusfiles) {
197 if ($opt_u) {
198 - my @updated = safe_pipe_capture(@cvs, 'update', @canstatusfiles);
198 + my @updated = xargs_safe_pipe_capture([@cvs, 'update'], @canstatusfiles);
199 print @updated;
200 }
201 my @cvsoutput;
202 - @cvsoutput= safe_pipe_capture(@cvs, 'status', @canstatusfiles);
202 + @cvsoutput = xargs_safe_pipe_capture([@cvs, 'status'], @canstatusfiles);
203 my $matchcount = 0;
204 foreach my $l (@cvsoutput) {
205 chomp $l;
@@ -295,7 +295,7 @@ if ($dirtypatch) {
295
296 if ($opt_c) {
297 print "Autocommit\n $cmd\n";
298 - print safe_pipe_capture(@cvs, 'commit', '-F', '.msg', @files);
298 + print xargs_safe_pipe_capture([@cvs, 'commit', '-F', '.msg'], @files);
299 if ($?) {
300 die "Exiting: The commit did not succeed";
301 }
@@ -335,15 +335,24 @@ sub safe_pipe_capture {
335 return wantarray ? @output : join('',@output);
336 }
337
338 -sub safe_pipe_capture_blob {
339 - my $output;
340 - if (my $pid = open my $child, '-|') {
341 - local $/;
342 - undef $/;
343 - $output = (<$child>);
344 - close $child or die join(' ',@_).": $! $?";
345 - } else {
346 - exec(@_) or die "$! $?"; # exec() can fail the executable can't be found
347 - }
348 - return $output;
338 +sub xargs_safe_pipe_capture {
339 + my $MAX_ARG_LENGTH = 65536;
340 + my $cmd = shift;
341 + my @output;
342 + my $output;
343 + while(@_) {
344 + my @args;
345 + my $length = 0;
346 + while(@_ && $length < $MAX_ARG_LENGTH) {
347 + push @args, shift;
348 + $length += length($args[$#args]);
349 + }
350 + if (wantarray) {
351 + push @output, safe_pipe_capture(@$cmd, @args);
352 + }
353 + else {
354 + $output .= safe_pipe_capture(@$cmd, @args);
355 + }
356 + }
357 + return wantarray ? @output : $output;
358 }