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 <pasky@suse.cz> Signed-off-by: Junio C Hamano <junkio@cox.net>
Petr Baudis committed
Jun 25, 2006 at 03:54 UTC
a6065b548fc74ce4d8a655e17bfb1dba39540464
1 file changed
+57
-11
perl/Git.pm
+57
-11
@@ -663,18 +663,29 @@ sub _command_common_pipe {
663
}
664
_check_valid_cmd($cmd);
665
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);
688
}
677
- _cmd_exec($self, $cmd, @args);
689
}
690
return wantarray ? ($fh, join(' ', $cmd, @args)) : $fh;
691
}
@@ -749,4 +760,39 @@ sub AUTOLOAD {
760
sub DESTROY { }
761
762
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
+
798
1; # Famous last words