Skip to content

Commit 4381063

Browse files
committed
Merge pull request #305 from dscho/msysgit_issues_182
Allow `add -p` and `add -i` with a large number of files
2 parents 855a5d9 + 646fcb3 commit 4381063

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

git-add--interactive.perl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,24 @@ sub run_cmd_pipe {
160160
die "$^O does not support: @invalid\n" if @invalid;
161161
my @args = map { m/ /o ? "\"$_\"": $_ } @_;
162162
return qx{@args};
163+
} elsif (($^O eq 'MSWin32' || $^O eq 'msys') && (scalar @_ > 200) &&
164+
grep $_ eq '--', @_) {
165+
use File::Temp qw(tempfile);
166+
my ($fhargs, $filename) =
167+
tempfile('git-args-XXXXXX', UNLINK => 1);
168+
169+
my $cmd = 'cat '.$filename.' | xargs -0 -s 20000 ';
170+
while ($_[0] ne '--') {
171+
$cmd = $cmd . shift(@_) . ' ';
172+
}
173+
174+
shift(@_);
175+
print $fhargs join("\0", @_);
176+
close($fhargs);
177+
178+
my $fh = undef;
179+
open($fh, '-|', $cmd) or die;
180+
return <$fh>;
163181
} else {
164182
my $fh = undef;
165183
open($fh, '-|', @_) or die;

t/t3701-add-interactive.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,4 +493,25 @@ test_expect_success 'add -p works even with color.ui=always' '
493493
test_cmp expect actual
494494
'
495495

496+
test_expect_success EXPENSIVE 'add -i with a lot of files' '
497+
git reset --hard &&
498+
x160=0123456789012345678901234567890123456789 &&
499+
x160=$x160$x160$x160$x160 &&
500+
y= &&
501+
i=0 &&
502+
while test $i -le 200
503+
do
504+
name=$(printf "%s%03d" $x160 $i) &&
505+
echo $name >$name &&
506+
git add -N $name &&
507+
y="${y}y$LF" &&
508+
i=$(($i+1)) ||
509+
break
510+
done &&
511+
echo "$y" | git add -p -- . &&
512+
git diff --cached >staged &&
513+
test_line_count = 1407 staged &&
514+
git reset --hard
515+
'
516+
496517
test_done

0 commit comments

Comments
 (0)