Skip to content

Commit aac5fe5

Browse files
committed
Merge 'add-p-many-files'
This topic branch allows `add -p` and `add -i` with a large number of files. It is kind of a hack that was never really meant to be upstreamed. Let's see if we can do better in the built-in `add -p`. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents a16f849 + e406874 commit aac5fe5

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
@@ -805,6 +805,27 @@ test_expect_success 'checkout -p works with pathological context lines' '
805805
test_cmp expect a
806806
'
807807

808+
test_expect_success EXPENSIVE 'add -i with a lot of files' '
809+
git reset --hard &&
810+
x160=0123456789012345678901234567890123456789 &&
811+
x160=$x160$x160$x160$x160 &&
812+
y= &&
813+
i=0 &&
814+
while test $i -le 200
815+
do
816+
name=$(printf "%s%03d" $x160 $i) &&
817+
echo $name >$name &&
818+
git add -N $name &&
819+
y="${y}y$LF" &&
820+
i=$(($i+1)) ||
821+
break
822+
done &&
823+
echo "$y" | git add -p -- . &&
824+
git diff --cached >staged &&
825+
test_line_count = 1407 staged &&
826+
git reset --hard
827+
'
828+
808829
test_expect_success 'show help from add--helper' '
809830
git reset --hard &&
810831
cat >expect <<-EOF &&

0 commit comments

Comments
 (0)