protected function executeQuery()
 {
     $drequest = $this->getRequest();
     $repository = $drequest->getRepository();
     $commit = $drequest->loadCommit();
     $raw_changes = queryfx_all($repository->establishConnection('r'), 'SELECT c.*, p.path pathName, t.path targetPathName
     FROM %T c
       LEFT JOIN %T p ON c.pathID = p.id
       LEFT JOIN %T t on c.targetPathID = t.id
     WHERE c.commitID = %d AND isDirect = 1', PhabricatorRepository::TABLE_PATHCHANGE, PhabricatorRepository::TABLE_PATH, PhabricatorRepository::TABLE_PATH, $commit->getID());
     $changes = array();
     $raw_changes = isort($raw_changes, 'pathName');
     foreach ($raw_changes as $raw_change) {
         $type = $raw_change['changeType'];
         if ($type == DifferentialChangeType::TYPE_CHILD) {
             continue;
         }
         $change = new DiffusionPathChange();
         $change->setPath(ltrim($raw_change['pathName'], '/'));
         $change->setChangeType($raw_change['changeType']);
         $change->setFileType($raw_change['fileType']);
         $change->setCommitIdentifier($commit->getCommitIdentifier());
         $changes[] = $change;
     }
     return $changes;
 }
 protected function executeQuery()
 {
     $drequest = $this->getRequest();
     $repository = $drequest->getRepository();
     $commit = $drequest->loadCommit();
     $conn_r = $repository->establishConnection('r');
     $limit = '';
     if ($this->limit) {
         $limit = qsprintf($conn_r, 'LIMIT %d', $this->limit + 1);
     }
     $raw_changes = queryfx_all($conn_r, 'SELECT c.*, p.path pathName, t.path targetPathName,
       i.commitIdentifier targetCommitIdentifier
     FROM %T c
       LEFT JOIN %T p ON c.pathID = p.id
       LEFT JOIN %T t ON c.targetPathID = t.id
       LEFT JOIN %T i ON c.targetCommitID = i.id
     WHERE c.commitID = %d AND isDirect = 1 %Q', PhabricatorRepository::TABLE_PATHCHANGE, PhabricatorRepository::TABLE_PATH, PhabricatorRepository::TABLE_PATH, $commit->getTableName(), $commit->getID(), $limit);
     $limited = $this->limit && count($raw_changes) > $this->limit;
     if ($limited) {
         $raw_changes = array_slice($raw_changes, 0, $this->limit);
     }
     $changes = array();
     $raw_changes = isort($raw_changes, 'pathName');
     foreach ($raw_changes as $raw_change) {
         $type = $raw_change['changeType'];
         if ($type == DifferentialChangeType::TYPE_CHILD) {
             continue;
         }
         $change = new DiffusionPathChange();
         $change->setPath(ltrim($raw_change['pathName'], '/'));
         $change->setChangeType($raw_change['changeType']);
         $change->setFileType($raw_change['fileType']);
         $change->setCommitIdentifier($commit->getCommitIdentifier());
         $change->setTargetPath(ltrim($raw_change['targetPathName'], '/'));
         $change->setTargetCommitIdentifier($raw_change['targetCommitIdentifier']);
         $id = $raw_change['pathID'];
         $changes[$id] = $change;
     }
     // Deduce the away paths by examining all the changes, if we loaded them
     // all.
     if (!$limited) {
         $away = array();
         foreach ($changes as $change) {
             if ($change->getTargetPath()) {
                 $away[$change->getTargetPath()][] = $change->getPath();
             }
         }
         foreach ($changes as $change) {
             if (isset($away[$change->getPath()])) {
                 $change->setAwayPaths($away[$change->getPath()]);
             }
         }
     }
     return $changes;
 }
 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;
 }
Example #5
0
 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;
 }