Skip to content

Commit 79470da

Browse files
dschoGit for Windows Build Agent
authored andcommitted
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 f2404b9 + 5de44ff commit 79470da

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
@@ -860,6 +860,27 @@ test_expect_success 'checkout -p patch editing of added file' '
860860
)
861861
'
862862

863+
test_expect_success EXPENSIVE 'add -i with a lot of files' '
864+
git reset --hard &&
865+
x160=0123456789012345678901234567890123456789 &&
866+
x160=$x160$x160$x160$x160 &&
867+
y= &&
868+
i=0 &&
869+
while test $i -le 200
870+
do
871+
name=$(printf "%s%03d" $x160 $i) &&
872+
echo $name >$name &&
873+
git add -N $name &&
874+
y="${y}y$LF" &&
875+
i=$(($i+1)) ||
876+
break
877+
done &&
878+
echo "$y" | git add -p -- . &&
879+
git diff --cached >staged &&
880+
test_line_count = 1407 staged &&
881+
git reset --hard
882+
'
883+
863884
test_expect_success 'show help from add--helper' '
864885
git reset --hard &&
865886
cat >expect <<-EOF &&

0 commit comments

Comments
 (0)