| | |
| | public function __construct( Git $git, string $subPath ) { |
| | - $this->git = $git; |
| | + $this->git = $git; |
| | $this->subPath = $subPath; |
| | } |
 |
| | header( 'Cache-Control: no-cache' ); |
| | |
| | - $input = file_get_contents( 'php://input' ); |
| | - $wants = []; |
| | - $haves = []; |
| | + $input = file_get_contents( 'php://input' ); |
| | + $wants = []; |
| | + $haves = []; |
| | $offset = 0; |
| | |
| | while( $offset < strlen( $input ) ) { |
| | - $line = $this->readPacketLine( $input, $offset ); |
| | + $result = $this->readPacketLine( $input, $offset ); |
| | + $line = $result[0]; |
| | + $next = $result[1]; |
| | |
| | - if( $line === null || $line === 'done' ) { |
| | + if( $next === $offset || $line === 'done' ) { |
| | break; |
| | } |
| | + |
| | + $offset = $next; |
| | |
| | if( $line === '' ) { |
 |
| | private function sendSidebandData( int $band, string $data ): void { |
| | $chunkSize = 65000; |
| | - $len = strlen( $data ); |
| | + $len = strlen( $data ); |
| | |
| | for( $offset = 0; $offset < $len; $offset += $chunkSize ) { |
| | $chunk = substr( $data, $offset, $chunkSize ); |
| | |
| | $this->packetWrite( chr( $band ) . $chunk ); |
| | } |
| | } |
| | |
| | - private function readPacketLine( string $input, int &$offset ): ?string { |
| | - $line = null; |
| | + private function readPacketLine( string $input, int $offset ): array { |
| | + $line = ''; |
| | + $next = $offset; |
| | |
| | if( $offset + 4 <= strlen( $input ) ) { |
| | $lenHex = substr( $input, $offset, 4 ); |
| | |
| | if( ctype_xdigit( $lenHex ) ) { |
| | $len = hexdec( $lenHex ); |
| | - $offset += 4; |
| | - $valid = $len >= 4 && $offset + ( $len - 4 ) <= strlen( $input ); |
| | - |
| | - $line = ($len === 0) |
| | - ? '' |
| | - : ($valid ? substr( $input, $offset, $len - 4 ) : null); |
| | |
| | - $offset += ($len >= 4) ? ($len - 4) : 0; |
| | + if( $len === 0 ) { |
| | + $next = $offset + 4; |
| | + } elseif( $len >= 4 ) { |
| | + if( $offset + $len <= strlen( $input ) ) { |
| | + $line = substr( $input, $offset + 4, $len - 4 ); |
| | + $next = $offset + $len; |
| | + } |
| | + } |
| | } |
| | } |
| | |
| | - return $line; |
| | + return [$line, $next]; |
| | } |
| | |