- my $cmd = [ qw(git apply --cached --ignore-whitespace
- --whitespace=warn --verbose) ];
- my $rdr = { 0 => fileno($tmp), 2 => 1 };
- my $qsp = PublicInbox::Qspawn->new($cmd, $self->{git_env}, $rdr);
+ my @cmd = qw(git apply --cached --ignore-whitespace
+ --whitespace=warn --verbose);
+ my $len = length(join(' ', @cmd));
+ my $total = $self->{tot};
+ my $di; # keep track of the last one for "git ls-files"
+
+ do {
+ my $i = ++$self->{nr};
+ $di = shift @$patches;
+ dbg($self, "\napplying [$i/$total] " . di_url($self, $di) .
+ "\n" . join('', @{$di->{hdr_lines}}));
+ my $pn = $total + 1 - $i;
+ my $path = "$dn/$pn";
+ $len += length($path) + 1;
+ push @cmd, $path;
+ } while (@$patches && $len < $ARG_SIZE_MAX);
+
+ my $rdr = { 2 => 1 };
+ my $qsp = PublicInbox::Qspawn->new(\@cmd, $self->{git_env}, $rdr);