protected function executeQuery() { $drequest = $this->getRequest(); $repository = $drequest->getRepository(); $path = $drequest->getPath(); $commit = $drequest->getCommit(); $conn_r = $repository->establishConnection('r'); $paths = queryfx_all($conn_r, 'SELECT id, path FROM %T WHERE pathHash IN (%Ls)', PhabricatorRepository::TABLE_PATH, array(md5('/' . trim($path, '/')))); $paths = ipull($paths, 'id', 'path'); $path_id = idx($paths, '/' . trim($path, '/')); if (!$path_id) { return array(); } $filter_query = ''; if ($this->needDirectChanges) { if ($this->needChildChanges) { $type = DifferentialChangeType::TYPE_CHILD; $filter_query = 'AND (isDirect = 1 OR changeType = ' . $type . ')'; } else { $filter_query = 'AND (isDirect = 1)'; } } $history_data = queryfx_all($conn_r, 'SELECT * FROM %T WHERE repositoryID = %d AND pathID = %d AND commitSequence <= %d %Q ORDER BY commitSequence DESC LIMIT %d, %d', PhabricatorRepository::TABLE_PATHCHANGE, $repository->getID(), $path_id, $commit ? $commit : 0x7fffffff, $filter_query, $this->getOffset(), $this->getLimit()); $commits = array(); $commit_data = array(); $commit_ids = ipull($history_data, 'commitID'); if ($commit_ids) { $commits = id(new PhabricatorRepositoryCommit())->loadAllWhere('id IN (%Ld)', $commit_ids); if ($commits) { $commit_data = id(new PhabricatorRepositoryCommitData())->loadAllWhere('commitID in (%Ld)', $commit_ids); $commit_data = mpull($commit_data, null, 'getCommitID'); } } $history = array(); foreach ($history_data as $row) { $item = new DiffusionPathChange(); $commit = idx($commits, $row['commitID']); if ($commit) { $item->setCommit($commit); $item->setCommitIdentifier($commit->getCommitIdentifier()); $data = idx($commit_data, $commit->getID()); if ($data) { $item->setCommitData($data); } } $item->setChangeType($row['changeType']); $item->setFileType($row['fileType']); $history[] = $item; } return $history; }
protected function executeQuery() { $drequest = $this->getRequest(); $repository = $drequest->getRepository(); $path = $drequest->getPath(); $commit_hash = $drequest->getCommit(); $local_path = $repository->getDetail('local-path'); list($stdout) = execx('(cd %s && git log ' . '--skip=%d ' . '-n %d ' . '--abbrev=40 ' . '--pretty=format:%%H ' . '%s -- %s)', $local_path, $this->getOffset(), $this->getLimit(), $commit_hash, $path); $hashes = explode("\n", $stdout); $hashes = array_filter($hashes); $commits = array(); $commit_data = array(); $path_changes = array(); $conn_r = $repository->establishConnection('r'); if ($hashes) { $commits = id(new PhabricatorRepositoryCommit())->loadAllWhere('repositoryID = %d AND commitIdentifier IN (%Ls)', $repository->getID(), $hashes); $commits = mpull($commits, null, 'getCommitIdentifier'); if ($commits) { $commit_data = id(new PhabricatorRepositoryCommitData())->loadAllWhere('commitID in (%Ld)', mpull($commits, 'getID')); $commit_data = mpull($commit_data, null, 'getCommitID'); } if ($commits) { $path_normal = '/' . trim($path, '/'); $paths = queryfx_all($conn_r, 'SELECT id, path FROM %T WHERE path IN (%Ls)', PhabricatorRepository::TABLE_PATH, array($path_normal)); $paths = ipull($paths, 'id', 'path'); $path_id = idx($paths, $path_normal); $path_changes = queryfx_all($conn_r, 'SELECT * FROM %T WHERE commitID IN (%Ld) AND pathID = %d', PhabricatorRepository::TABLE_PATHCHANGE, mpull($commits, 'getID'), $path_id); $path_changes = ipull($path_changes, null, 'commitID'); } } $history = array(); foreach ($hashes as $hash) { $item = new DiffusionPathChange(); $item->setCommitIdentifier($hash); $commit = idx($commits, $hash); if ($commit) { $item->setCommit($commit); $data = idx($commit_data, $commit->getID()); if ($data) { $item->setCommitData($data); } $change = idx($path_changes, $commit->getID()); if ($change) { $item->setChangeType($change['changeType']); $item->setFileType($change['fileType']); } } $history[] = $item; } return $history; }
public static final function loadHistoryForCommitIdentifiers(array $identifiers, DiffusionRequest $drequest) { if (!$identifiers) { return array(); } $repository = $drequest->getRepository(); $commits = self::loadCommitsByIdentifiers($identifiers, $drequest); if (!$commits) { return array(); } $path = $drequest->getPath(); $conn_r = $repository->establishConnection('r'); $path_normal = DiffusionPathIDQuery::normalizePath($path); $paths = queryfx_all($conn_r, 'SELECT id, path FROM %T WHERE pathHash IN (%Ls)', PhabricatorRepository::TABLE_PATH, array(md5($path_normal))); $paths = ipull($paths, 'id', 'path'); $path_id = idx($paths, $path_normal); $commit_ids = array_filter(mpull($commits, 'getID')); $path_changes = array(); if ($path_id && $commit_ids) { $path_changes = queryfx_all($conn_r, 'SELECT * FROM %T WHERE commitID IN (%Ld) AND pathID = %d', PhabricatorRepository::TABLE_PATHCHANGE, $commit_ids, $path_id); $path_changes = ipull($path_changes, null, 'commitID'); } $history = array(); foreach ($identifiers as $identifier) { $item = new DiffusionPathChange(); $item->setCommitIdentifier($identifier); $commit = idx($commits, $identifier); if ($commit) { $item->setCommit($commit); try { $item->setCommitData($commit->getCommitData()); } catch (Exception $ex) { // Ignore, commit just doesn't have data. } $change = idx($path_changes, $commit->getID()); if ($change) { $item->setChangeType($change['changeType']); $item->setFileType($change['fileType']); } } $history[] = $item; } return $history; }
protected final function loadHistoryForCommitIdentifiers(array $identifiers) { if (!$identifiers) { return array(); } $commits = array(); $commit_data = array(); $path_changes = array(); $drequest = $this->getRequest(); $repository = $drequest->getRepository(); $path = $drequest->getPath(); $commits = id(new PhabricatorRepositoryCommit())->loadAllWhere('repositoryID = %d AND commitIdentifier IN (%Ls)', $repository->getID(), $identifiers); $commits = mpull($commits, null, 'getCommitIdentifier'); if (!$commits) { return array(); } $commit_data = id(new PhabricatorRepositoryCommitData())->loadAllWhere('commitID in (%Ld)', mpull($commits, 'getID')); $commit_data = mpull($commit_data, null, 'getCommitID'); $conn_r = $repository->establishConnection('r'); $path_normal = DiffusionPathIDQuery::normalizePath($path); $paths = queryfx_all($conn_r, 'SELECT id, path FROM %T WHERE path IN (%Ls)', PhabricatorRepository::TABLE_PATH, array($path_normal)); $paths = ipull($paths, 'id', 'path'); $path_id = idx($paths, $path_normal); $path_changes = queryfx_all($conn_r, 'SELECT * FROM %T WHERE commitID IN (%Ld) AND pathID = %d', PhabricatorRepository::TABLE_PATHCHANGE, mpull($commits, 'getID'), $path_id); $path_changes = ipull($path_changes, null, 'commitID'); $history = array(); foreach ($identifiers as $identifier) { $item = new DiffusionPathChange(); $item->setCommitIdentifier($identifier); $commit = idx($commits, $identifier); if ($commit) { $item->setCommit($commit); $data = idx($commit_data, $commit->getID()); if ($data) { $item->setCommitData($data); } $change = idx($path_changes, $commit->getID()); if ($change) { $item->setChangeType($change['changeType']); $item->setFileType($change['fileType']); } } $history[] = $item; } return $history; }