Dave Jarvis' Repositories

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

Renames file

AuthorDave Jarvis <email>
Date2026-02-21 11:05:31 GMT-0800
Commit4eeb003be0adb13e1b96c7b5387a5debd329dfa6
Parent731ccb8
git/PathLocator.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++;
- }
- }
- }
-}
Delta0 lines added, 56 lines removed, 56-line decrease