-
-my $len_hex = xread 4;
-fail "non-hexadecimal packet length" unless $len_hex =~ m{^[0-9a-zA-Z]{4}$};
-my $len = hex $len_hex;
-
-my $line = xread $len;
-unless ($line =~ m{^git-upload-pack (?:~($TILDE)/)?($REPO[.]git)\0host=($HOSTNAME)\0$}) {
- $line =~ s/[^ -~]+/ /g;
- fail "could not parse \"$line\""
+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$|) {
+ $line =~ s|[^ -~]+| |g;
+ fail "Could not parse \"$line\""