public function processRequest()
 {
     $drequest = $this->diffusionRequest;
     $request = $this->getRequest();
     $page_size = $request->getInt('pagesize', 100);
     $offset = $request->getInt('page', 0);
     $history_query = DiffusionHistoryQuery::newFromDiffusionRequest($drequest);
     $history_query->setOffset($offset);
     $history_query->setLimit($page_size + 1);
     if (!$request->getBool('copies')) {
         $history_query->needDirectChanges(true);
         $history_query->needChildChanges(true);
     }
     $history = $history_query->loadHistory();
     $phids = array();
     foreach ($history as $item) {
         $data = $item->getCommitData();
         if ($data) {
             if ($data->getCommitDetail('authorPHID')) {
                 $phids[$data->getCommitDetail('authorPHID')] = true;
             }
         }
     }
     $phids = array_keys($phids);
     $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
     $pager = new AphrontPagerView();
     $pager->setPageSize($page_size);
     $pager->setOffset($offset);
     if (count($history) == $page_size + 1) {
         array_pop($history);
         $pager->setHasMorePages(true);
     } else {
         $pager->setHasMorePages(false);
     }
     $pager->setURI($request->getRequestURI(), 'page');
     $content = array();
     $content[] = $this->buildCrumbs(array('branch' => true, 'path' => true, 'view' => 'history'));
     if ($request->getBool('copies')) {
         $button_title = 'Hide Copies/Branches';
     } else {
         $button_title = 'Show Copies/Branches';
     }
     $button_uri = $request->getRequestURI()->alter('copies', !$request->getBool('copies'));
     $button = phutil_render_tag('a', array('class' => 'button small grey', 'href' => $button_uri), phutil_escape_html($button_title));
     $history_table = new DiffusionHistoryTableView();
     $history_table->setDiffusionRequest($drequest);
     $history_table->setHandles($handles);
     $history_table->setHistory($history);
     $history_panel = new AphrontPanelView();
     $history_panel->setHeader('History');
     $history_panel->addButton($button);
     $history_panel->appendChild($history_table);
     $history_panel->appendChild($pager);
     $content[] = $history_panel;
     // TODO: Sometimes we do have a change view, we need to look at the most
     // recent history entry to figure it out.
     $nav = $this->buildSideNav('history', false);
     $nav->appendChild($content);
     return $this->buildStandardPageResponse($nav, array('title' => 'history'));
 }
 public function processRequest()
 {
     $drequest = $this->diffusionRequest;
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $repository = $drequest->getRepository();
     $page_size = $request->getInt('pagesize', 100);
     $offset = $request->getInt('offset', 0);
     $params = array('commit' => $drequest->getCommit(), 'path' => $drequest->getPath(), 'offset' => $offset, 'limit' => $page_size + 1);
     if (!$request->getBool('copies')) {
         $params['needDirectChanges'] = true;
         $params['needChildChanges'] = true;
     }
     $history_results = $this->callConduitWithDiffusionRequest('diffusion.historyquery', $params);
     $history = DiffusionPathChange::newFromConduit($history_results['pathChanges']);
     $pager = new AphrontPagerView();
     $pager->setPageSize($page_size);
     $pager->setOffset($offset);
     $history = $pager->sliceResults($history);
     $pager->setURI($request->getRequestURI(), 'offset');
     $show_graph = !strlen($drequest->getPath());
     $content = array();
     $history_table = new DiffusionHistoryTableView();
     $history_table->setUser($request->getUser());
     $history_table->setDiffusionRequest($drequest);
     $history_table->setHistory($history);
     $history_table->loadRevisions();
     $phids = $history_table->getRequiredHandlePHIDs();
     $handles = $this->loadViewerHandles($phids);
     $history_table->setHandles($handles);
     if ($show_graph) {
         $history_table->setParents($history_results['parents']);
         $history_table->setIsHead($offset == 0);
     }
     $history_panel = new AphrontPanelView();
     $history_panel->appendChild($history_table);
     $history_panel->appendChild($pager);
     $history_panel->setNoBackground();
     $content[] = $history_panel;
     $header = id(new PHUIHeaderView())->setUser($viewer)->setPolicyObject($repository)->setHeader($this->renderPathLinks($drequest, $mode = 'history'));
     $actions = $this->buildActionView($drequest);
     $properties = $this->buildPropertyView($drequest, $actions);
     $object_box = id(new PHUIObjectBoxView())->setHeader($header)->addPropertyList($properties);
     $crumbs = $this->buildCrumbs(array('branch' => true, 'path' => true, 'view' => 'history'));
     return $this->buildApplicationPage(array($crumbs, $object_box, $content), array('title' => array(pht('History'), pht('%s Repository', $drequest->getRepository()->getCallsign()))));
 }
 private function buildMergesTable(PhabricatorRepositoryCommit $commit)
 {
     $drequest = $this->getDiffusionRequest();
     $repository = $drequest->getRepository();
     $vcs = $repository->getVersionControlSystem();
     switch ($vcs) {
         case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
             // These aren't supported under SVN.
             return null;
     }
     $limit = 50;
     $merges = $this->callConduitWithDiffusionRequest('diffusion.mergedcommitsquery', array('commit' => $drequest->getCommit(), 'limit' => $limit + 1));
     if (!$merges) {
         return null;
     }
     $merges = DiffusionPathChange::newFromConduit($merges);
     $caption = null;
     if (count($merges) > $limit) {
         $merges = array_slice($merges, 0, $limit);
         $caption = new PHUIInfoView();
         $caption->setSeverity(PHUIInfoView::SEVERITY_NOTICE);
         $caption->appendChild(pht('This commit merges a very large number of changes. ' . 'Only the first %s are shown.', new PhutilNumber($limit)));
     }
     $history_table = new DiffusionHistoryTableView();
     $history_table->setUser($this->getRequest()->getUser());
     $history_table->setDiffusionRequest($drequest);
     $history_table->setHistory($merges);
     $history_table->loadRevisions();
     $phids = $history_table->getRequiredHandlePHIDs();
     $handles = $this->loadViewerHandles($phids);
     $history_table->setHandles($handles);
     $panel = new PHUIObjectBoxView();
     $panel->setHeaderText(pht('Merged Changes'));
     $panel->setTable($history_table);
     if ($caption) {
         $panel->setInfoView($caption);
     }
     return $panel;
 }
 public function processRequest()
 {
     $drequest = $this->diffusionRequest;
     $content = array();
     $crumbs = $this->buildCrumbs();
     $content[] = $crumbs;
     $content[] = $this->buildPropertiesTable($drequest->getRepository());
     $history_query = DiffusionHistoryQuery::newFromDiffusionRequest($drequest);
     $history_query->setLimit(15);
     $history_query->needParents(true);
     $history = $history_query->loadHistory();
     $browse_query = DiffusionBrowseQuery::newFromDiffusionRequest($drequest);
     $browse_results = $browse_query->loadPaths();
     $phids = array();
     foreach ($history as $item) {
         $data = $item->getCommitData();
         if ($data) {
             if ($data->getCommitDetail('authorPHID')) {
                 $phids[$data->getCommitDetail('authorPHID')] = true;
             }
             if ($data->getCommitDetail('committerPHID')) {
                 $phids[$data->getCommitDetail('committerPHID')] = true;
             }
         }
     }
     foreach ($browse_results as $item) {
         $data = $item->getLastCommitData();
         if ($data) {
             if ($data->getCommitDetail('authorPHID')) {
                 $phids[$data->getCommitDetail('authorPHID')] = true;
             }
             if ($data->getCommitDetail('committerPHID')) {
                 $phids[$data->getCommitDetail('committerPHID')] = true;
             }
         }
     }
     $phids = array_keys($phids);
     $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
     $history_table = new DiffusionHistoryTableView();
     $history_table->setDiffusionRequest($drequest);
     $history_table->setHandles($handles);
     $history_table->setHistory($history);
     $history_table->loadRevisions();
     $history_table->setParents($history_query->getParents());
     $history_table->setIsHead(true);
     $callsign = $drequest->getRepository()->getCallsign();
     $all = phutil_render_tag('a', array('href' => "/diffusion/{$callsign}/history/"), 'View Full Commit History');
     $panel = new AphrontPanelView();
     $panel->setHeader("Recent Commits · {$all}");
     $panel->appendChild($history_table);
     $content[] = $panel;
     $browse_table = new DiffusionBrowseTableView();
     $browse_table->setDiffusionRequest($drequest);
     $browse_table->setHandles($handles);
     $browse_table->setPaths($browse_results);
     $browse_panel = new AphrontPanelView();
     $browse_panel->setHeader('Browse Repository');
     $browse_panel->appendChild($browse_table);
     $content[] = $browse_panel;
     $content[] = $this->buildTagListTable($drequest);
     $content[] = $this->buildBranchListTable($drequest);
     $readme = $browse_query->renderReadme($browse_results);
     if ($readme) {
         $panel = new AphrontPanelView();
         $panel->setHeader('README');
         $panel->appendChild($readme);
         $content[] = $panel;
     }
     return $this->buildStandardPageResponse($content, array('title' => $drequest->getRepository()->getName()));
 }
 public function processRequest()
 {
     $drequest = $this->diffusionRequest;
     $request = $this->getRequest();
     $page_size = $request->getInt('pagesize', 100);
     $offset = $request->getInt('page', 0);
     $history_query = DiffusionHistoryQuery::newFromDiffusionRequest($drequest);
     $history_query->setOffset($offset);
     $history_query->setLimit($page_size + 1);
     if (!$request->getBool('copies')) {
         $history_query->needDirectChanges(true);
         $history_query->needChildChanges(true);
     }
     $show_graph = !strlen($drequest->getPath());
     if ($show_graph) {
         $history_query->needParents(true);
     }
     $history = $history_query->loadHistory();
     $pager = new AphrontPagerView();
     $pager->setPageSize($page_size);
     $pager->setOffset($offset);
     if (count($history) == $page_size + 1) {
         array_pop($history);
         $pager->setHasMorePages(true);
     } else {
         $pager->setHasMorePages(false);
     }
     $pager->setURI($request->getRequestURI(), 'page');
     $content = array();
     $content[] = $this->buildCrumbs(array('branch' => true, 'path' => true, 'view' => 'history'));
     if ($request->getBool('copies')) {
         $button_title = 'Hide Copies/Branches';
         $copies_new = null;
     } else {
         $button_title = 'Show Copies/Branches';
         $copies_new = true;
     }
     $button = phutil_render_tag('a', array('class' => 'button small grey', 'href' => $request->getRequestURI()->alter('copies', $copies_new)), phutil_escape_html($button_title));
     $history_table = new DiffusionHistoryTableView();
     $history_table->setDiffusionRequest($drequest);
     $history_table->setHistory($history);
     $history_table->loadRevisions();
     $phids = $history_table->getRequiredHandlePHIDs();
     $handles = $this->loadViewerHandles($phids);
     $history_table->setHandles($handles);
     if ($show_graph) {
         $history_table->setParents($history_query->getParents());
         $history_table->setIsHead($offset == 0);
     }
     $history_panel = new AphrontPanelView();
     $history_panel->setHeader('History');
     $history_panel->addButton($button);
     $history_panel->appendChild($history_table);
     $history_panel->appendChild($pager);
     $content[] = $history_panel;
     // TODO: Sometimes we do have a change view, we need to look at the most
     // recent history entry to figure it out.
     $nav = $this->buildSideNav('history', false);
     $nav->appendChild($content);
     return $this->buildStandardPageResponse($nav, array('title' => 'history'));
 }
 private function buildMergesTable(PhabricatorRepositoryCommit $commit)
 {
     $drequest = $this->getDiffusionRequest();
     $limit = 50;
     $merge_query = DiffusionMergedCommitsQuery::newFromDiffusionRequest($drequest);
     $merge_query->setLimit($limit + 1);
     $merges = $merge_query->loadMergedCommits();
     if (!$merges) {
         return null;
     }
     $caption = null;
     if (count($merges) > $limit) {
         $merges = array_slice($merges, 0, $limit);
         $caption = "This commit merges more than {$limit} changes. Only the first " . "{$limit} are shown.";
     }
     $history_table = new DiffusionHistoryTableView();
     $history_table->setDiffusionRequest($drequest);
     $history_table->setHistory($merges);
     $phids = $history_table->getRequiredHandlePHIDs();
     $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
     $history_table->setHandles($handles);
     $panel = new AphrontPanelView();
     $panel->setHeader('Merged Changes');
     $panel->setCaption($caption);
     $panel->appendChild($history_table);
     return $panel;
 }
 private function buildMergesTable(PhabricatorRepositoryCommit $commit)
 {
     $drequest = $this->getDiffusionRequest();
     $limit = 50;
     $merges = array();
     try {
         $merges = $this->callConduitWithDiffusionRequest('diffusion.mergedcommitsquery', array('commit' => $drequest->getCommit(), 'limit' => $limit + 1));
     } catch (ConduitException $ex) {
         if ($ex->getMessage() != 'ERR-UNSUPPORTED-VCS') {
             throw $ex;
         }
     }
     if (!$merges) {
         return null;
     }
     $caption = null;
     if (count($merges) > $limit) {
         $merges = array_slice($merges, 0, $limit);
         $caption = "This commit merges more than {$limit} changes. Only the first " . "{$limit} are shown.";
     }
     $history_table = new DiffusionHistoryTableView();
     $history_table->setUser($this->getRequest()->getUser());
     $history_table->setDiffusionRequest($drequest);
     $history_table->setHistory($merges);
     $history_table->loadRevisions();
     $phids = $history_table->getRequiredHandlePHIDs();
     $handles = $this->loadViewerHandles($phids);
     $history_table->setHandles($handles);
     $panel = new AphrontPanelView();
     $panel->setHeader(pht('Merged Changes'));
     $panel->setCaption($caption);
     $panel->appendChild($history_table);
     $panel->setNoBackground();
     return $panel;
 }