Skip to content

Commit 04e3de4

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 cb81faa + 1af16eb commit 04e3de4

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
@@ -174,6 +174,24 @@ sub run_cmd_pipe {
174174
die "$^O does not support: @invalid\n" if @invalid;
175175
my @args = map { m/ /o ? "\"$_\"": $_ } @_;
176176
return qx{@args};
177+
} elsif (($^O eq 'MSWin32' || $^O eq 'msys') && (scalar @_ > 200) &&
178+
grep $_ eq '--', @_) {
179+
use File::Temp qw(tempfile);
180+
my ($fhargs, $filename) =
181+
tempfile('git-args-XXXXXX', UNLINK => 1);
182+
183+
my $cmd = 'cat '.$filename.' | xargs -0 -s 20000 ';
184+
while ($_[0] ne '--') {
185+
$cmd = $cmd . shift(@_) . ' ';
186+
}
187+
188+
shift(@_);
189+
print $fhargs join("\0", @_);
190+
close($fhargs);
191+
192+
my $fh = undef;
193+
open($fh, '-|', $cmd) or die;
194+
return <$fh>;
177195
} else {
178196
my $fh = undef;
179197
open($fh, '-|', @_) or die;

t/t3701-add-interactive.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,4 +639,25 @@ test_expect_success 'add -p patch editing works with pathological context lines'
639639
test_cmp expected-2 actual
640640
'
641641

642+
test_expect_success EXPENSIVE 'add -i with a lot of files' '
643+
git reset --hard &&
644+
x160=0123456789012345678901234567890123456789 &&
645+
x160=$x160$x160$x160$x160 &&
646+
y= &&
647+
i=0 &&
648+
while test $i -le 200
649+
do
650+
name=$(printf "%s%03d" $x160 $i) &&
651+
echo $name >$name &&
652+
git add -N $name &&
653+
y="${y}y$LF" &&
654+
i=$(($i+1)) ||
655+
break
656+
done &&
657+
echo "$y" | git add -p -- . &&
658+
git diff --cached >staged &&
659+
test_line_count = 1407 staged &&
660+
git reset --hard
661+
'
662+
642663
test_done

0 commit comments

Comments
 (0)