/** * Detects if given project_path is known project root. * * @param string $path Path. * * @return boolean */ protected function isRef($path) { // Not a folder. if (substr($path, -1, 1) !== '/') { return false; } return $this->_repositoryConnector->isRefRoot($path); }
/** * Finds revisions by sub-match. * * @param integer $project_id Project ID. * @param string $path Path. * @param integer|null $max_revision Max revision. * * @return array */ protected function findBySubMatch($project_id, $path, $max_revision = null) { $path_id = $this->getPathId($path); if ($path_id === false) { return array(); } $sql = 'SELECT Revision, CopyPathId FROM CommitPaths WHERE PathId = :path_id AND CopyPathId IS NOT NULL ORDER BY Revision DESC LIMIT 1'; $copy_data = $this->database->fetchOne($sql, array('path_id' => $path_id)); if ($this->_repositoryConnector->isRefRoot($path)) { $where_clause = array('RefId = :ref_id'); $bind_params = array('ref_id' => $this->getRefId($project_id, $this->_repositoryConnector->getRefByPath($path))); // Revisions, made after copy revision. if ($copy_data) { $where_clause[] = 'Revision >= :min_revision'; $bind_params['min_revision'] = $copy_data['Revision']; } // Revisions made before copy revision. if (isset($max_revision)) { $where_clause[] = 'Revision < :max_revision'; $bind_params['max_revision'] = $max_revision; } $sql = 'SELECT DISTINCT Revision FROM CommitRefs WHERE (' . implode(') AND (', $where_clause) . ')'; $results = $this->database->fetchCol($sql, $bind_params); } else { $where_clause = array('cpr.ProjectId = :project_id', 'p.Path LIKE :path'); $bind_params = array('project_id' => $project_id, 'path' => $path . '%'); // Revisions, made after copy revision. if ($copy_data) { $where_clause[] = 'cpr.Revision >= :min_revision'; $bind_params['min_revision'] = $copy_data['Revision']; } // Revisions made before copy revision. if (isset($max_revision)) { $where_clause[] = 'cpr.Revision < :max_revision'; $bind_params['max_revision'] = $max_revision; } $sql = 'SELECT DISTINCT cpr.Revision FROM CommitProjects cpr JOIN CommitPaths cpa ON cpa.Revision = cpr.Revision JOIN Paths p ON p.Id = cpa.PathId WHERE (' . implode(') AND (', $where_clause) . ')'; $results = $this->database->fetchCol($sql, $bind_params); } if (!$copy_data) { return $results; } return array_merge($results, $this->findBySubMatch($project_id, $this->getPathFromId($copy_data['CopyPathId']), $copy_data['Revision'])); }
/** * @dataProvider isRefRootDataProvider */ public function testIsRefRoot($path, $result) { $this->assertSame($result, $this->_repositoryConnector->isRefRoot($path)); }