alarm 30;
sub xread {
- my $length = shift; $_ = "";
- while ($length > length) {
- my $ret = sysread STDIN, $_, $length, length;
- fail "Expected $length bytes, got ".length
+ my $length = shift;
+ my $buffer = "";
+ while ($length > length $buffer) {
+ my $ret = sysread STDIN, $buffer, $length, length $buffer;
+ fail "Expected $length bytes, got ".length $buffer
if defined $ret and $ret == 0;
fail "read: $!" if not defined $ret and $! != EINTR and $! != EAGAIN;
}
+ return $buffer;
}
-xread 4;
-fail "Bad hex in packet length" unless m|^[0-9a-fA-F]{4}$|;
-xread hex;
-unless (($service,$path,$host) =
+my $hex_len = xread 4;
+fail "Bad hex in packet length" unless $hex_len =~ m|^[0-9a-fA-F]{4}$|;
+my $line = xread -4 + hex $hex_len;
+unless (($service,$path,$host) = $line =~
m|^(git-[a-z-]+) /*([!-~]+)\0host=([!-~]+)\0$|) {
- s|[^ -~]+| |g;
- fail "Could not parse \"$_\""
+ $line =~ s|[^ -~]+| |g;
+ fail "Could not parse \"$line\""
}
our $uri = $_ = "git://$host/$path";
for my $cf (@ARGV) { do $cf }