From 16810bcaf37ecedadc62abfa27b305f04f5a70cf Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Wed, 14 May 2014 15:03:28 +0300 Subject: [PATCH 1/3] Treat possible commit as partial hash as fallback. --- src/GitList/Util/Routing.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/GitList/Util/Routing.php b/src/GitList/Util/Routing.php index c687c3c..f00af82 100644 --- a/src/GitList/Util/Routing.php +++ b/src/GitList/Util/Routing.php @@ -58,11 +58,22 @@ class Routing } } - if ($matchedBranch === null) { - throw new EmptyRepositoryException('This repository is currently empty. There are no commits.'); + if ($matchedBranch !== null) { + $commitish = $matchedBranch; } + } - $commitish = $matchedBranch; + if ($commitish === null) { + // We may have partial commit hash as our commitish. + $hash = $slashPosition === false ? $commitishPath : substr($commitishPath, 0, $slashPosition); + if ($repository->hasCommit($hash)) { + $commit = $repository->getCommit($hash); + $commitish = $commit->getHash(); + } + } + + if ($commitish === null) { + throw new EmptyRepositoryException('This repository is currently empty. There are no commits.'); } $commitishLength = strlen($commitish); From 851a0dfb0ec5aabe846f96af202c4f2b08250cd1 Mon Sep 17 00:00:00 2001 From: Samuel Lemaitre Date: Wed, 14 May 2014 16:11:37 +0200 Subject: [PATCH 2/3] Shorter and less condition --- src/GitList/Util/Routing.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/GitList/Util/Routing.php b/src/GitList/Util/Routing.php index f00af82..e32e49a 100644 --- a/src/GitList/Util/Routing.php +++ b/src/GitList/Util/Routing.php @@ -61,20 +61,19 @@ class Routing if ($matchedBranch !== null) { $commitish = $matchedBranch; } - } - - if ($commitish === null) { - // We may have partial commit hash as our commitish. - $hash = $slashPosition === false ? $commitishPath : substr($commitishPath, 0, $slashPosition); - if ($repository->hasCommit($hash)) { - $commit = $repository->getCommit($hash); - $commitish = $commit->getHash(); + else + { + // We may have partial commit hash as our commitish. + $hash = $slashPosition === false ? $commitishPath : substr($commitishPath, 0, $slashPosition); + if ($repository->hasCommit($hash)) { + $commit = $repository->getCommit($hash); + $commitish = $commit->getHash(); + } + else + throw new EmptyRepositoryException('This repository is currently empty. There are no commits.'); } } - if ($commitish === null) { - throw new EmptyRepositoryException('This repository is currently empty. There are no commits.'); - } $commitishLength = strlen($commitish); $path = substr($commitishPath, $commitishLength); From d797adeae915abe8c7205aa5028aab922763e344 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Thu, 15 May 2014 19:05:22 +0300 Subject: [PATCH 3/3] Make the code PSR-2-compliant. --- src/GitList/Util/Routing.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/GitList/Util/Routing.php b/src/GitList/Util/Routing.php index e32e49a..a8dcc17 100644 --- a/src/GitList/Util/Routing.php +++ b/src/GitList/Util/Routing.php @@ -60,21 +60,18 @@ class Routing if ($matchedBranch !== null) { $commitish = $matchedBranch; - } - else - { + } else { // We may have partial commit hash as our commitish. $hash = $slashPosition === false ? $commitishPath : substr($commitishPath, 0, $slashPosition); if ($repository->hasCommit($hash)) { $commit = $repository->getCommit($hash); $commitish = $commit->getHash(); - } - else + } else { throw new EmptyRepositoryException('This repository is currently empty. There are no commits.'); + } } } - $commitishLength = strlen($commitish); $path = substr($commitishPath, $commitishLength); if (strpos($path, '/') === 0) {