Skip to content

Commit a6065b5

Browse files
Petr BaudisJunio C Hamano
Petr Baudis
authored and
Junio C Hamano
committed
Git.pm: Try to support ActiveState output pipe
The code is stolen from git-annotate and completely untested since I don't have access to any Microsoft operating system now. Someone ActiveState-savvy should look at it anyway and try to implement the input pipe as well, if it is possible at all; also, the implementation seems to be horribly whitespace-unsafe. Signed-off-by: Petr Baudis <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f6276fe commit a6065b5

File tree

1 file changed

+57
-11
lines changed

1 file changed

+57
-11
lines changed

perl/Git.pm

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -663,18 +663,29 @@ sub _command_common_pipe {
663663
}
664664
_check_valid_cmd($cmd);
665665

666-
my $pid = open(my $fh, $direction);
667-
if (not defined $pid) {
668-
throw Error::Simple("open failed: $!");
669-
} elsif ($pid == 0) {
670-
if (defined $opts{STDERR}) {
671-
close STDERR;
672-
}
673-
if ($opts{STDERR}) {
674-
open (STDERR, '>&', $opts{STDERR})
675-
or die "dup failed: $!";
666+
my $fh;
667+
if ($^O eq '##INSERT_ACTIVESTATE_STRING_HERE##') {
668+
# ActiveState Perl
669+
#defined $opts{STDERR} and
670+
# warn 'ignoring STDERR option - running w/ ActiveState';
671+
$direction eq '-|' or
672+
die 'input pipe for ActiveState not implemented';
673+
tie ($fh, 'Git::activestate_pipe', $cmd, @args);
674+
675+
} else {
676+
my $pid = open($fh, $direction);
677+
if (not defined $pid) {
678+
throw Error::Simple("open failed: $!");
679+
} elsif ($pid == 0) {
680+
if (defined $opts{STDERR}) {
681+
close STDERR;
682+
}
683+
if ($opts{STDERR}) {
684+
open (STDERR, '>&', $opts{STDERR})
685+
or die "dup failed: $!";
686+
}
687+
_cmd_exec($self, $cmd, @args);
676688
}
677-
_cmd_exec($self, $cmd, @args);
678689
}
679690
return wantarray ? ($fh, join(' ', $cmd, @args)) : $fh;
680691
}
@@ -749,4 +760,39 @@ sub AUTOLOAD {
749760
sub DESTROY { }
750761

751762

763+
# Pipe implementation for ActiveState Perl.
764+
765+
package Git::activestate_pipe;
766+
use strict;
767+
768+
sub TIEHANDLE {
769+
my ($class, @params) = @_;
770+
# FIXME: This is probably horrible idea and the thing will explode
771+
# at the moment you give it arguments that require some quoting,
772+
# but I have no ActiveState clue... --pasky
773+
my $cmdline = join " ", @params;
774+
my @data = qx{$cmdline};
775+
bless { i => 0, data => \@data }, $class;
776+
}
777+
778+
sub READLINE {
779+
my $self = shift;
780+
if ($self->{i} >= scalar @{$self->{data}}) {
781+
return undef;
782+
}
783+
return $self->{'data'}->[ $self->{i}++ ];
784+
}
785+
786+
sub CLOSE {
787+
my $self = shift;
788+
delete $self->{data};
789+
delete $self->{i};
790+
}
791+
792+
sub EOF {
793+
my $self = shift;
794+
return ($self->{i} >= scalar @{$self->{data}});
795+
}
796+
797+
752798
1; # Famous last words

0 commit comments

Comments
 (0)