/** * Create revision log. * * @param string $repository_url Repository url. * @param Connector $repository_connector Repository connector. * @param ConsoleIO $io Console IO. */ public function __construct($repository_url, Connector $repository_connector, ConsoleIO $io = null) { $this->_io = $io; $this->_repositoryConnector = $repository_connector; $this->_repositoryRootUrl = $repository_connector->getRootUrl($repository_url); $relative_path = $repository_connector->getRelativePath($repository_url); $this->_projectPath = $repository_connector->getProjectUrl($relative_path) . '/'; $this->_refName = $repository_connector->getRefByPath($relative_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 getRefByPathDataProvider */ public function testGetRefByPath($path, $ref) { $this->assertSame($ref, $this->_repositoryConnector->getRefByPath($path)); }