Skip to content

Commit

Permalink
Perl: Support piping commands on MSWin32
Browse files Browse the repository at this point in the history
Replace the legacy TIEHANDLE used to fake out a pipe and replace it with
real pipes.  As modern Perl seems to handle these simple pipes well, the
need for a special-case object has evaporated.

As a consequence of this change, input pipes are now supported.

Closes: git-for-windows#1603
Signed-off-by: Chris Lindee <[email protected]>
  • Loading branch information
ColMelvin committed Oct 15, 2018
1 parent fff0040 commit 5d4934a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 46 deletions.
50 changes: 5 additions & 45 deletions perl/Git.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1607,15 +1607,11 @@ sub _command_common_pipe {
# ActiveState Perl
#defined $opts{STDERR} and
# warn 'ignoring STDERR option - running w/ ActiveState';
$direction eq '-|' or
die 'input pipe for ActiveState not implemented';
# the strange construction with *ACPIPE is just to
# explain the tie below that we want to bind to
# a handle class, not scalar. It is not known if
# it is something specific to ActiveState Perl or
# just a Perl quirk.
tie (*ACPIPE, 'Git::activestate_pipe', $cmd, @args);
$fh = *ACPIPE;
my $cmdline = make_windows_commandline('git', $cmd, @args);
my $pid = open($fh, $direction, $cmdline);
if (not defined $pid) {
throw Error::Simple("open failed: $!");
}

} else {
my $pid = open($fh, $direction);
Expand Down Expand Up @@ -1686,42 +1682,6 @@ sub DESTROY {
}


# Pipe implementation for ActiveState Perl.

package Git::activestate_pipe;

sub TIEHANDLE {
my ($class, @params) = @_;
my $cmdline = make_windows_commandline('git', @params);
my @data = qx{$cmdline};
bless { i => 0, data => \@data }, $class;
}

sub READLINE {
my $self = shift;
if ($self->{i} >= scalar @{$self->{data}}) {
return undef;
}
my $i = $self->{i};
if (wantarray) {
$self->{i} = $#{$self->{'data'}} + 1;
return splice(@{$self->{'data'}}, $i);
}
$self->{i} = $i + 1;
return $self->{'data'}->[ $i ];
}

sub CLOSE {
my $self = shift;
delete $self->{data};
delete $self->{i};
}

sub EOF {
my $self = shift;
return ($self->{i} >= scalar @{$self->{data}});
}

sub make_windows_commandline {
my $cmdline = join ' ', unescape_windows_commandline_args(@_);

Expand Down
2 changes: 1 addition & 1 deletion t/t9701/test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ BEGIN
require_ok('Git');

foreach (@tests) {
my $cmdline = Git::activestate_pipe::make_windows_commandline($^X, '-e', 'print $ARGV[0]', $_);
my $cmdline = Git::make_windows_commandline($^X, '-e', 'print $ARGV[0]', $_);
is qx{$cmdline}, $_, $cmdline;
}

Expand Down

0 comments on commit 5d4934a

Please sign in to comment.