Dave Jarvis' Repositories

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

Adds missing file

AuthorDave Jarvis <email>
Date2026-02-21 11:06:45 GMT-0800
Commit69edb8d2c7b14c512eac22f03d22144a7ef1df33
Parent4eeb003
git/PackLocator.php
+<?php
+require_once __DIR__ . '/PackIndex.php';
+require_once __DIR__ . '/FileHandlePool.php';
+
+class PackLocator {
+ private array $indexes;
+
+ public function __construct( string $objectsPath ) {
+ $this->indexes = [];
+ $packFiles = glob( "{$objectsPath}/pack/*.idx" ) ?: [];
+
+ foreach( $packFiles as $indexFile ) {
+ $this->indexes[] = new PackIndex( $indexFile );
+ }
+ }
+
+ public function locate(
+ FileHandlePool $pool,
+ string $sha,
+ callable $action
+ ): void {
+ if( strlen( $sha ) === 40 && ctype_xdigit( $sha ) ) {
+ $binarySha = hex2bin( $sha );
+ $found = false;
+ $count = count( $this->indexes );
+ $index = 0;
+
+ while( !$found && $index < $count ) {
+ $this->indexes[$index]->search(
+ $pool,
+ $binarySha,
+ function(
+ string $packFile,
+ int $offset
+ ) use (
+ &$found,
+ $index,
+ $action
+ ): void {
+ $found = true;
+
+ if( $index > 0 ) {
+ $temp = $this->indexes[0];
+ $this->indexes[0] = $this->indexes[$index];
+ $this->indexes[$index] = $temp;
+ }
+
+ $action( $packFile, $offset );
+ }
+ );
+
+ $index++;
+ }
+ }
+ }
+}
Delta56 lines added, 0 lines removed, 56-line increase