-alarm 0;
-
-$service eq 'git-upload-pack'
- or gitfail "unknown/unsupported service `$service'";
-
-my $fetch = 2; # 0:don't; 1:try; 2:force
-my $url = $specpath;
-
-while ($url =~ s#\s+(\[)([^][{}]+)\]$## ||
- $url =~ s#\s+(\{)([^][{}]+)\}$##) {
- $_ = $2;
- my $must = $1 eq '{';
- if (m/^fetch=try$/) {
- $fetch = 1;
- } elsif (m/^fetch=no$/) {
- $fetch = 0;
- } elsif (m/^fetch=must$/) {
- $fetch = 2; # the default
- } elsif (m/^timeout=(\d+)$/) {
- $fetchtimeout = $1 <= $maxfetchtimeout ? $1 : $maxfetchtimeout;
- } elsif ($must) {
- gitfail "unknown/unsupported option `$_'";
+sub readcommand () {
+ $SIG{ALRM} = sub { fail "timeout" };
+ alarm 30;
+
+ 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,$specpath,$spechost) = $line =~
+ m|^(git-[a-z-]+) /*([!-~ ]+)\0host=([!-~]+)\0$|) {
+ $line =~ s|[^ -~]+| |g;
+ gitfail "unknown/unsupported instruction `$line'"