Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/treetrek.git

Attempts to fix cloning

Author Dave Jarvis <email>
Date 2026-02-20 01:56:44 GMT-0800
Commit 6a69b304f570969255961db2b9e43c563639c496
Parent 7651083
git/Git.php
$deflate = deflate_init( ZLIB_ENCODING_DEFLATE );
- // Use a reference to collect chunks correctly within the generator
- $this->slurp( $sha, function( $chunk ) use ( $deflate, $ctx, &$out ) {
+ $this->slurp( $sha, function( $chunk ) use ( $deflate, $ctx ) {
$compressed = deflate_add( $deflate, $chunk, ZLIB_NO_FLUSH );
if( $compressed !== '' ) {
hash_update( $ctx, $compressed );
- $out = $compressed;
+ echo $compressed;
}
} );
-
- // The slurp callback happens synchronously; yield the last chunk if set
- if( isset( $out ) ) {
- yield $out;
- unset( $out );
- }
$final = deflate_add( $deflate, '', ZLIB_FINISH );
pages/ClonePage.php
header( 'Cache-Control: no-cache' );
- $input = file_get_contents( 'php://input' );
- $wants = [];
- $haves = [];
- $offset = 0;
- $isGzip = isset( $_SERVER['HTTP_CONTENT_ENCODING'] ) &&
- $_SERVER['HTTP_CONTENT_ENCODING'] === 'gzip';
-
- if( $isGzip ) {
- $decoded = gzdecode( $input );
+ $wants = [];
+ $haves = [];
+ $handle = fopen( 'php://input', 'rb' );
- if( is_string( $decoded ) ) {
- $input = $decoded;
+ if( $handle ) {
+ // If the input is gzipped, we wrap the stream
+ if( isset( $_SERVER['HTTP_CONTENT_ENCODING'] ) &&
+ $_SERVER['HTTP_CONTENT_ENCODING'] === 'gzip' ) {
+ stream_filter_append( $handle, 'zlib.inflate', STREAM_FILTER_READ, [
+ 'window' => 31
+ ] );
}
- }
- while( $offset < strlen( $input ) ) {
- $result = $this->readPacketLine( $input, $offset );
- $line = $result[0];
- $next = $result[1];
+ while( !feof( $handle ) ) {
+ $lenHex = fread( $handle, 4 );
- if( $next === $offset || $line === 'done' ) {
- break;
- }
+ if( strlen( $lenHex ) < 4 ) {
+ break;
+ }
- $offset = $next;
+ $len = hexdec( $lenHex );
- if( $line === '' ) {
- continue;
- }
+ if( $len === 0 ) { // Flush packet
+ break;
+ }
- $trim = trim( $line );
+ if( $len <= 4 ) {
+ continue;
+ }
- if( strpos( $trim, 'want ' ) === 0 ) {
- $wants[] = explode( ' ', $trim )[1];
- } elseif( strpos( $trim, 'have ' ) === 0 ) {
- $haves[] = explode( ' ', $trim )[1];
+ $line = fread( $handle, $len - 4 );
+ $trim = trim( $line );
+
+ if( strpos( $trim, 'want ' ) === 0 ) {
+ $wants[] = explode( ' ', $trim )[1];
+ } elseif( strpos( $trim, 'have ' ) === 0 ) {
+ $haves[] = explode( ' ', $trim )[1];
+ }
+
+ if( $trim === 'done' ) {
+ break;
+ }
}
+
+ fclose( $handle );
}
if( !empty( $wants ) ) {
$this->packetWrite( "NAK\n" );
$objects = $this->git->collectObjects( $wants, $haves );
- $packGen = $this->git->generatePackfile( $objects );
- foreach( $packGen as $chunk ) {
+ ob_start();
+ foreach( $this->git->generatePackfile( $objects ) as $chunk ) {
+ $buffered = ob_get_clean();
+
+ if( $buffered !== '' ) {
+ $this->sendSidebandData( 1, $buffered );
+ }
+
if( $chunk !== '' ) {
$this->sendSidebandData( 1, $chunk );
}
+ ob_start();
}
+ ob_end_clean();
}
Delta 48 lines added, 39 lines removed, 9-line increase