Dave Jarvis' Repositories

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

Fixes raw references

Author Dave Jarvis <email>
Date 2026-03-01 00:28:46 GMT-0800
Commit 090c6673928edbc1177678fe77b9a4cf396b72d9
Parent e9846c9
model/Router.php
private const ACTION_TAGS = 'tags';
- private const GET_REPOSITORY = 'repo';
- private const GET_ACTION = 'action';
- private const GET_HASH = 'hash';
- private const GET_NAME = 'name';
-
private const REFERENCE_HEAD = 'HEAD';
private const ROUTE_REPO = 'repo';
private const EXTENSION_GIT = '.git';
private array $repos = [];
private Git $git;
-
- private string $repoName = '';
- private array $repoData = [];
- private string $action = '';
- private string $commitHash = '';
- private string $filePath = '';
- private string $baseHash = '';
public function __construct( string $reposPath, string $orderFile ) {
public function route(): Page {
$this->normalizeQueryString();
+
$uriParts = $this->parseUriParts();
$repoName = !empty( $uriParts ) ? array_shift( $uriParts ) : '';
array $uriParts
): Page {
- $this->repoData = $this->repos[$repoName];
- $this->repoName = $repoName;
+ $repoData = $this->repos[$repoName];
- $this->git->setRepository( $this->repoData['path'] );
+ $this->git->setRepository( $repoData['path'] );
- $act = array_shift( $uriParts );
- $this->action = $act ?: self::ACTION_TREE;
+ $act = array_shift( $uriParts );
+ $action = $act ?: self::ACTION_TREE;
- $this->commitHash = self::REFERENCE_HEAD;
- $this->filePath = '';
- $this->baseHash = '';
+ $commitHash = self::REFERENCE_HEAD;
+ $filePath = '';
+ $baseHash = '';
$hasHash = [
- self::ACTION_TREE, self::ACTION_BLOB, self::ACTION_RAW,
+ self::ACTION_TREE,
+ self::ACTION_BLOB,
+ self::ACTION_RAW,
self::ACTION_COMMITS
];
- if( in_array( $this->action, $hasHash ) ) {
- $hash = array_shift( $uriParts );
- $this->commitHash = $hash ?: self::REFERENCE_HEAD;
- $this->filePath = implode( '/', $uriParts );
- } elseif( $this->action === self::ACTION_COMMIT ) {
- $this->commitHash = array_shift( $uriParts ) ?? self::REFERENCE_HEAD;
- } elseif( $this->action === self::ACTION_COMPARE ) {
- $this->commitHash = array_shift( $uriParts ) ?? self::REFERENCE_HEAD;
- $this->baseHash = array_shift( $uriParts ) ?? '';
+ if( in_array( $action, $hasHash ) ) {
+ $hash = array_shift( $uriParts );
+ $commitHash = $hash ?: self::REFERENCE_HEAD;
+ $filePath = implode( '/', $uriParts );
+ } elseif( $action === self::ACTION_COMMIT ) {
+ $commitHash = array_shift( $uriParts ) ?? self::REFERENCE_HEAD;
+ } elseif( $action === self::ACTION_COMPARE ) {
+ $commitHash = array_shift( $uriParts ) ?? self::REFERENCE_HEAD;
+ $baseHash = array_shift( $uriParts ) ?? '';
}
-
- $this->populateGet();
- return $this->createPage();
+ return $this->createPage(
+ $action, $repoData, $commitHash, $filePath, $baseHash
+ );
}
- private function createPage(): Page {
- return match( $this->action ) {
+ private function createPage(
+ string $action,
+ array $repoData,
+ string $commitHash,
+ string $filePath,
+ string $baseHash
+ ): Page {
+ return match( $action ) {
self::ACTION_TREE,
self::ACTION_BLOB => new FilePage(
- $this->repos, $this->repoData, $this->git, $this->commitHash,
- $this->filePath
+ $this->repos, $repoData, $this->git, $commitHash, $filePath
),
self::ACTION_RAW => new RawPage(
- $this->git, $this->commitHash
+ $this->git, $commitHash, $repoData['safe_name'], $filePath
),
self::ACTION_COMMITS => new CommitsPage(
- $this->repos, $this->repoData, $this->git, $this->commitHash
+ $this->repos, $repoData, $this->git, $commitHash
),
self::ACTION_COMMIT => new DiffPage(
- $this->repos, $this->repoData, $this->git, $this->commitHash
+ $this->repos, $repoData, $this->git, $commitHash
),
self::ACTION_TAGS => new TagsPage(
- $this->repos, $this->repoData, $this->git
+ $this->repos, $repoData, $this->git
),
self::ACTION_COMPARE => new ComparePage(
- $this->repos, $this->repoData, $this->git, $this->commitHash,
- $this->baseHash
+ $this->repos, $repoData, $this->git, $commitHash, $baseHash
),
default => new FilePage(
- $this->repos, $this->repoData, $this->git, self::REFERENCE_HEAD, ''
+ $this->repos, $repoData, $this->git, self::REFERENCE_HEAD, ''
)
};
return $uriParts;
- }
-
- private function populateGet(): void {
- $_GET[self::GET_REPOSITORY] = $this->repoName;
- $_GET[self::GET_ACTION] = $this->action;
- $_GET[self::GET_HASH] = $this->commitHash;
- $_GET[self::GET_NAME] = $this->filePath;
}
}
pages/RawPage.php
private Git $git;
private string $hash;
+ private string $repo;
+ private string $name;
- public function __construct( Git $git, string $hash ) {
+ public function __construct(
+ Git $git,
+ string $hash,
+ string $repo,
+ string $name
+ ) {
$this->git = $git;
$this->hash = $hash;
+ $this->repo = $repo;
+ $this->name = $name;
}
public function render(): void {
- $name = $_GET['name'] ?? '';
- $file = $this->git->readFile( $this->hash, $name );
+ if( $this->name === '' ) {
+ header( "Location: /{$this->repo}/" );
+ } else {
+ $file = $this->git->readFile( $this->hash, $this->name );
- while( ob_get_level() > 0 ) {
- if( !ob_end_clean() ) {
- break;
+ while( ob_get_level() > 0 ) {
+ if( !ob_end_clean() ) {
+ break;
+ }
}
- }
- $file->emitRawHeaders();
+ $file->emitRawHeaders();
- $this->git->stream(
- $this->hash,
- function( string $data ): void {
- echo $data;
- },
- $name
- );
+ $this->git->stream(
+ $this->hash,
+ function( string $data ): void {
+ echo $data;
+ },
+ $this->name
+ );
+ }
exit;
Delta 65 lines added, 66 lines removed, 1-line decrease