Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/treetrek.git
git/Git.php
foreach( $objs as $sha => $type ) {
- // Obtain uncompressed size from index/header without loading object data.
$size = $this->getObjectSize( $sha );
$byte = $type << 4 | $size & 0x0f;
yield $hdr;
- // Stream-compress the object data without ever holding the full raw
- // content in memory. deflate_add() with ZLIB_NO_FLUSH produces
- // compressed output incrementally; we accumulate only the (much
- // smaller) compressed bytes.
$deflate = deflate_init( ZLIB_ENCODING_DEFLATE );
- $compBuf = '';
- $this->slurp( $sha, function( $chunk ) use ( $deflate, $ctx, &$compBuf ) {
+ $this->slurp( $sha, function( $chunk ) use ( $deflate, $ctx ) {
$compressed = deflate_add( $deflate, $chunk, ZLIB_NO_FLUSH );
if( $compressed !== '' ) {
hash_update( $ctx, $compressed );
- $compBuf .= $compressed;
+ echo $compressed;
}
} );
$final = deflate_add( $deflate, '', ZLIB_FINISH );
if( $final !== '' ) {
hash_update( $ctx, $final );
- $compBuf .= $final;
- }
-
- // Yield the compressed body in 64 KB chunks.
- $pos = 0;
- $len = strlen( $compBuf );
-
- while( $pos < $len ) {
- yield substr( $compBuf, $pos, 65536 );
- $pos += 65536;
+ yield $final;
}
}
git/GitPacks.php
private const MAX_READ = 1040576;
private const MAX_RAM = 1048576;
- private const MAX_BASE_RAM = 524288;
- private const MAX_DEPTH = 50;
+ private const MAX_BASE_RAM = 2097152;
+ private const MAX_DEPTH = 200;
private string $objectsPath;
if( strlen( $sha ) === 40 && ctype_xdigit( $sha ) ) {
$binarySha = hex2bin( $sha );
+
if( $this->lastPack !== '' ) {
$offset = $this->findInIdx( $this->lastPack, $binarySha );
): bool {
if( $depth >= self::MAX_DEPTH ) {
- return false;
+ throw new RuntimeException( "Delta depth limit exceeded" );
}
$deltaPos = ftell( $handle );
$base = '';
-
$baseSize = $this->extractPackedSize( $handle, $offset - $neg );
if( $baseSize > self::MAX_BASE_RAM ) {
- return false;
+ throw new RuntimeException( "Base object too large: $baseSize" );
}
if( $baseSize > self::MAX_BASE_RAM ) {
- return false;
+ throw new RuntimeException( "Base object too large: $baseSize" );
}
pages/ClonePage.php
private function sendSidebandData( int $band, string $data ): void {
- $chunkSize = 65000;
+ $chunkSize = 65515;
$len = strlen( $data );

Improves sideband chunking

Author Dave Jarvis <email>
Date 2026-02-20 01:52:49 GMT-0800
Commit 1e0586ce531de7913ad3580749b4f75146bc80ec
Parent 69f70d0
Delta 10 lines added, 25 lines removed, 15-line decrease