git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/7] Git.pm: Try to support ActiveState output pipe

From
Petr Baudis <pasky@suse.cz>
Date
Jun 25, 2006, 01:54 UTC
Message-ID
<20060625015423.29906.86666.stgit@machine.or.cz>
In-Reply-To
<20060625015421.29906.50002.stgit@machine.or.cz>

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>
---
 perl/Git.pm |   68 +++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 57 insertions(+), 11 deletions(-)
diff --git a/perl/Git.pm b/perl/Git.pm
index 08f56c0..6da11a6 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -748,18 +748,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;
 }
@@ -834,4 +845,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
Previous: Petr BaudisNext: Petr Baudis
Message 2 of 11 in “Git.pm: Introduce ident() and ident_person() methods”
  1. 1/7 Git.pm: Introduce ident() and ident_person() methodsPetr Baudis, Jun 25, 2006
  2. 2/7 Git.pm: Try to support ActiveState output pipePetr Baudis, Jun 25, 2006
  3. 3/7 Git.pm: Swap hash_object() parametersPetr Baudis, Jun 25, 2006
  4. 4/7 Git.pm: Fix Git->repository("/somewhere/totally/elsewhere")Petr Baudis, Jun 25, 2006
  5. 5/7 Make it possible to set up libgit directly (instead of from the environment)Petr Baudis, Jun 25, 2006
  6. 6/7 Git.pm: Introduce fast get_object() methodPetr Baudis, Jun 25, 2006
  7. 7/7 Convert git-annotate to use Git.pmPetr Baudis, Jun 25, 2006
  8. Ryan AndersonJun 25, 2006
  9. Petr BaudisJun 25, 2006
  10. Petr BaudisJun 25, 2006
  11. Junio C HamanoJun 25, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.