Skip to content

Commit a2f31b0

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 8d3443c + 767d92e commit a2f31b0

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
@@ -953,6 +953,27 @@ test_expect_success 'checkout -p patch editing of added file' '
953953
)
954954
'
955955

956+
test_expect_success EXPENSIVE 'add -i with a lot of files' '
957+
git reset --hard &&
958+
x160=0123456789012345678901234567890123456789 &&
959+
x160=$x160$x160$x160$x160 &&
960+
y= &&
961+
i=0 &&
962+
while test $i -le 200
963+
do
964+
name=$(printf "%s%03d" $x160 $i) &&
965+
echo $name >$name &&
966+
git add -N $name &&
967+
y="${y}y$LF" &&
968+
i=$(($i+1)) ||
969+
break
970+
done &&
971+
echo "$y" | git add -p -- . &&
972+
git diff --cached >staged &&
973+
test_line_count = 1407 staged &&
974+
git reset --hard
975+
'
976+
956977
test_expect_success 'show help from add--helper' '
957978
git reset --hard &&
958979
cat >expect <<-EOF &&

0 commit comments

Comments
 (0)