summaryrefslogtreecommitdiff
path: root/perl/Git.pm
diff options
context:
space:
mode:
authorPetr Baudis <pasky@suse.cz>2006-06-25 01:54:23 (GMT)
committerJunio C Hamano <junkio@cox.net>2006-07-03 00:14:42 (GMT)
commita6065b548fc74ce4d8a655e17bfb1dba39540464 (patch)
tree9f0a94064afa29de18e759d87820d018e6851120 /perl/Git.pm
parentf6276fe159fe985af2d5831f4629ceefb33d082e (diff)
downloadgit-a6065b548fc74ce4d8a655e17bfb1dba39540464.zip
git-a6065b548fc74ce4d8a655e17bfb1dba39540464.tar.gz
git-a6065b548fc74ce4d8a655e17bfb1dba39540464.tar.bz2
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>
Diffstat (limited to 'perl/Git.pm')
-rw-r--r--perl/Git.pm68
1 files changed, 57 insertions, 11 deletions
diff --git a/perl/Git.pm b/perl/Git.pm
index 7bbb5be..6173043 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -663,18 +663,29 @@ sub _command_common_pipe {
}
_check_valid_cmd($cmd);
- my $pid = open(my $fh, $direction);
- if (not defined $pid) {
- throw Error::Simple("open failed: $!");
- } elsif ($pid == 0) {
- if (defined $opts{STDERR}) {
- close STDERR;
- }
- if ($opts{STDERR}) {
- open (STDERR, '>&', $opts{STDERR})
- or die "dup failed: $!";
+ my $fh;
+ if ($^O eq '##INSERT_ACTIVESTATE_STRING_HERE##') {
+ # ActiveState Perl
+ #defined $opts{STDERR} and
+ # warn 'ignoring STDERR option - running w/ ActiveState';
+ $direction eq '-|' or
+ die 'input pipe for ActiveState not implemented';
+ tie ($fh, 'Git::activestate_pipe', $cmd, @args);
+
+ } else {
+ my $pid = open($fh, $direction);
+ if (not defined $pid) {
+ throw Error::Simple("open failed: $!");
+ } elsif ($pid == 0) {
+ if (defined $opts{STDERR}) {
+ close STDERR;
+ }
+ if ($opts{STDERR}) {
+ open (STDERR, '>&', $opts{STDERR})
+ or die "dup failed: $!";
+ }
+ _cmd_exec($self, $cmd, @args);
}
- _cmd_exec($self, $cmd, @args);
}
return wantarray ? ($fh, join(' ', $cmd, @args)) : $fh;
}
@@ -749,4 +760,39 @@ sub AUTOLOAD {
sub DESTROY { }
+# Pipe implementation for ActiveState Perl.
+
+package Git::activestate_pipe;
+use strict;
+
+sub TIEHANDLE {
+ my ($class, @params) = @_;
+ # FIXME: This is probably horrible idea and the thing will explode
+ # at the moment you give it arguments that require some quoting,
+ # but I have no ActiveState clue... --pasky
+ my $cmdline = join " ", @params;
+ my @data = qx{$cmdline};
+ bless { i => 0, data => \@data }, $class;
+}
+
+sub READLINE {
+ my $self = shift;
+ if ($self->{i} >= scalar @{$self->{data}}) {
+ return undef;
+ }
+ return $self->{'data'}->[ $self->{i}++ ];
+}
+
+sub CLOSE {
+ my $self = shift;
+ delete $self->{data};
+ delete $self->{i};
+}
+
+sub EOF {
+ my $self = shift;
+ return ($self->{i} >= scalar @{$self->{data}});
+}
+
+
1; # Famous last words