public function handleRequest(AphrontRequest $request)
 {
     $response = $this->loadDiffusionContext();
     if ($response) {
         return $response;
     }
     $viewer = $this->getViewer();
     $drequest = $this->getDiffusionRequest();
     $repository = $drequest->getRepository();
     $pager = id(new PHUIPagerView())->readFromRequest($request);
     $params = array('commit' => $drequest->getCommit(), 'path' => $drequest->getPath(), 'offset' => $pager->getOffset(), 'limit' => $pager->getPageSize() + 1);
     if (!$request->getBool('copies')) {
         $params['needDirectChanges'] = true;
         $params['needChildChanges'] = true;
     }
     $history_results = $this->callConduitWithDiffusionRequest('diffusion.historyquery', $params);
     $history = DiffusionPathChange::newFromConduit($history_results['pathChanges']);
     $history = $pager->sliceResults($history);
     $show_graph = !strlen($drequest->getPath());
     $history_table = id(new DiffusionHistoryTableView())->setUser($request->getUser())->setDiffusionRequest($drequest)->setHistory($history);
     $history_table->loadRevisions();
     if ($show_graph) {
         $history_table->setParents($history_results['parents']);
         $history_table->setIsHead(!$pager->getOffset());
         $history_table->setIsTail(!$pager->getHasMorePages());
     }
     $history_header = $this->buildHistoryHeader($drequest);
     $history_panel = id(new PHUIObjectBoxView())->setHeader($history_header)->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setTable($history_table);
     $header = $this->buildHeader($drequest, $repository);
     $crumbs = $this->buildCrumbs(array('branch' => true, 'path' => true, 'view' => 'history'));
     $crumbs->setBorder(true);
     $pager_box = $this->renderTablePagerBox($pager);
     $view = id(new PHUITwoColumnView())->setHeader($header)->setFooter(array($history_panel, $pager_box));
     return $this->newPage()->setTitle(array(pht('History'), $repository->getDisplayName()))->setCrumbs($crumbs)->appendChild(array($view));
 }
 public function updateTransactionMailBody(PhabricatorMetaMTAMailBody $body, PhabricatorApplicationTransactionEditor $editor, array $xactions)
 {
     // Put all the merged commits info int the mail body if this is a merge
     $merges_caption = '';
     // TODO: Make this limit configurable after T6030
     $limit = 50;
     $commit = $this->getObject();
     try {
         $merges = DiffusionPathChange::newFromConduit(id(new ConduitCall('diffusion.mergedcommitsquery', array('commit' => $commit->getCommitIdentifier(), 'limit' => $limit + 1, 'repository' => $commit->getRepository()->getPHID())))->setUser($this->getViewer())->execute());
         if (count($merges) > $limit) {
             $merges = array_slice($merges, 0, $limit);
             $merges_caption = pht("This commit merges more than %d changes. Only the first " . "%d are shown.\n", $limit, $limit);
         }
         if ($merges) {
             $merge_commits = array();
             foreach ($merges as $merge) {
                 $merge_commits[] = $merge->getAuthorName() . ': ' . $merge->getSummary();
             }
             $body->addTextSection(pht('MERGED COMMITS'), $merges_caption . implode("\n", $merge_commits));
         }
     } catch (ConduitException $ex) {
         // Log the exception into the email body
         $body->addTextSection(pht('MERGED COMMITS'), pht('Error generating merged commits: ') . $ex->getMessage());
     }
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $drequest = DiffusionRequest::newFromDictionary(array('user' => $request->getUser(), 'callsign' => $request->getValue('callsign'), 'path' => $request->getValue('path'), 'branch' => $request->getValue('branch')));
     $limit = nonempty($request->getValue('limit'), self::DEFAULT_LIMIT);
     $history_result = DiffusionQuery::callConduitWithDiffusionRequest($request->getUser(), $drequest, 'diffusion.historyquery', array('commit' => $drequest->getCommit(), 'path' => $drequest->getPath(), 'offset' => 0, 'limit' => $limit, 'needDirectChanges' => true, 'needChildChanges' => true));
     $history = DiffusionPathChange::newFromConduit($history_result['pathChanges']);
     $raw_commit_identifiers = mpull($history, 'getCommitIdentifier');
     $result = array();
     foreach ($raw_commit_identifiers as $id) {
         $result[] = 'r' . $request->getValue('callsign') . $id;
     }
     return $result;
 }
 protected function getSVNResult(ConduitAPIRequest $request)
 {
     $drequest = $this->getDiffusionRequest();
     $repository = $drequest->getRepository();
     $results = array();
     foreach ($request->getValue('paths') as $path => $commit) {
         $history_result = DiffusionQuery::callConduitWithDiffusionRequest($request->getUser(), $drequest, 'diffusion.historyquery', array('commit' => $commit, 'path' => $path, 'limit' => 1, 'offset' => 0, 'needDirectChanges' => true, 'needChildChanges' => true));
         $history_array = DiffusionPathChange::newFromConduit($history_result['pathChanges']);
         if ($history_array) {
             $results[$path] = head($history_array)->getCommit()->getCommitIdentifier();
         }
     }
     return $results;
 }
 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()))));
 }
 public function handleRequest(AphrontRequest $request)
 {
     $response = $this->loadDiffusionContext();
     if ($response) {
         return $response;
     }
     $viewer = $this->getViewer();
     $drequest = $this->getDiffusionRequest();
     $repository = $drequest->getRepository();
     $pager = id(new PHUIPagerView())->readFromRequest($request);
     $params = array('commit' => $drequest->getCommit(), 'path' => $drequest->getPath(), 'offset' => $pager->getOffset(), 'limit' => $pager->getPageSize() + 1);
     if (!$request->getBool('copies')) {
         $params['needDirectChanges'] = true;
         $params['needChildChanges'] = true;
     }
     $history_results = $this->callConduitWithDiffusionRequest('diffusion.historyquery', $params);
     $history = DiffusionPathChange::newFromConduit($history_results['pathChanges']);
     $history = $pager->sliceResults($history);
     $show_graph = !strlen($drequest->getPath());
     $content = array();
     $history_table = id(new DiffusionHistoryTableView())->setUser($request->getUser())->setDiffusionRequest($drequest)->setHistory($history);
     $history_table->loadRevisions();
     if ($show_graph) {
         $history_table->setParents($history_results['parents']);
         $history_table->setIsHead(!$pager->getOffset());
         $history_table->setIsTail(!$pager->getHasMorePages());
     }
     $history_panel = new PHUIObjectBoxView();
     $history_panel->setHeaderText(pht('History'));
     $history_panel->setTable($history_table);
     $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'));
     $pager_box = $this->renderTablePagerBox($pager);
     return $this->newPage()->setTitle(array(pht('History'), $repository->getDisplayName()))->setCrumbs($crumbs)->appendChild(array($object_box, $content, $pager_box));
 }
 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;
 }
 private function buildNormalContent(DiffusionRequest $drequest)
 {
     $repository = $drequest->getRepository();
     $phids = array();
     $content = array();
     try {
         $history_results = $this->callConduitWithDiffusionRequest('diffusion.historyquery', array('commit' => $drequest->getCommit(), 'path' => $drequest->getPath(), 'offset' => 0, 'limit' => 15));
         $history = DiffusionPathChange::newFromConduit($history_results['pathChanges']);
         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;
                 }
             }
         }
         $history_exception = null;
     } catch (Exception $ex) {
         $history_results = null;
         $history = null;
         $history_exception = $ex;
     }
     try {
         $browse_results = DiffusionBrowseResultSet::newFromConduit($this->callConduitWithDiffusionRequest('diffusion.browsequery', array('path' => $drequest->getPath(), 'commit' => $drequest->getCommit())));
         $browse_paths = $browse_results->getPaths();
         foreach ($browse_paths 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;
                 }
             }
         }
         $browse_exception = null;
     } catch (Exception $ex) {
         $browse_results = null;
         $browse_paths = null;
         $browse_exception = $ex;
     }
     $phids = array_keys($phids);
     $handles = $this->loadViewerHandles($phids);
     $readme = null;
     if ($browse_results) {
         $readme_path = $browse_results->getReadmePath();
         if ($readme_path) {
             $readme_content = $this->callConduitWithDiffusionRequest('diffusion.filecontentquery', array('path' => $readme_path, 'commit' => $drequest->getStableCommit()));
             if ($readme_content) {
                 $readme = id(new DiffusionReadmeView())->setUser($this->getViewer())->setPath($readme_path)->setContent($readme_content['corpus']);
             }
         }
     }
     $content[] = $this->buildBrowseTable($browse_results, $browse_paths, $browse_exception, $handles);
     $content[] = $this->buildHistoryTable($history_results, $history, $history_exception);
     try {
         $content[] = $this->buildTagListTable($drequest);
     } catch (Exception $ex) {
         if (!$repository->isImporting()) {
             $content[] = $this->renderStatusMessage(pht('Unable to Load Tags'), $ex->getMessage());
         }
     }
     try {
         $content[] = $this->buildBranchListTable($drequest);
     } catch (Exception $ex) {
         if (!$repository->isImporting()) {
             $content[] = $this->renderStatusMessage(pht('Unable to Load Branches'), $ex->getMessage());
         }
     }
     if ($readme) {
         $content[] = $readme;
     }
     return $content;
 }
 private function loadCommitState()
 {
     $viewer = $this->getViewer();
     $drequest = $this->getDiffusionRequest();
     $repository = $drequest->getRepository();
     $commit = $drequest->getCommit();
     // TODO: We could use futures here and resolve these calls in parallel.
     $exceptions = array();
     try {
         $parent_refs = $this->callConduitWithDiffusionRequest('diffusion.commitparentsquery', array('commit' => $commit));
         if ($parent_refs) {
             $parents = id(new DiffusionCommitQuery())->setViewer($viewer)->withRepository($repository)->withIdentifiers($parent_refs)->execute();
         } else {
             $parents = array();
         }
         $this->commitParents = $parents;
     } catch (Exception $ex) {
         $this->commitParents = false;
         $exceptions[] = $ex;
     }
     $merge_limit = $this->getMergeDisplayLimit();
     try {
         if ($repository->isSVN()) {
             $this->commitMerges = array();
         } else {
             $merges = $this->callConduitWithDiffusionRequest('diffusion.mergedcommitsquery', array('commit' => $commit, 'limit' => $merge_limit + 1));
             $this->commitMerges = DiffusionPathChange::newFromConduit($merges);
         }
     } catch (Exception $ex) {
         $this->commitMerges = false;
         $exceptions[] = $ex;
     }
     try {
         if ($repository->isGit()) {
             $refs = $this->callConduitWithDiffusionRequest('diffusion.refsquery', array('commit' => $commit));
         } else {
             $refs = array();
         }
         $this->commitRefs = $refs;
     } catch (Exception $ex) {
         $this->commitRefs = false;
         $exceptions[] = $ex;
     }
     if ($exceptions) {
         $exists = $this->callConduitWithDiffusionRequest('diffusion.existsquery', array('commit' => $commit));
         if ($exists) {
             $this->commitExists = true;
             foreach ($exceptions as $exception) {
                 $this->commitErrors[] = $exception->getMessage();
             }
         } else {
             $this->commitExists = false;
             $this->commitErrors[] = pht('This commit no longer exists in the repository. It may have ' . 'been part of a branch which was deleted.');
         }
     } else {
         $this->commitExists = true;
         $this->commitErrors = array();
     }
 }
 private function buildNormalContent(DiffusionRequest $drequest)
 {
     $repository = $drequest->getRepository();
     $phids = array();
     $content = array();
     try {
         $history_results = $this->callConduitWithDiffusionRequest('diffusion.historyquery', array('commit' => $drequest->getCommit(), 'path' => $drequest->getPath(), 'offset' => 0, 'limit' => 15));
         $history = DiffusionPathChange::newFromConduit($history_results['pathChanges']);
         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;
                 }
             }
         }
         $history_exception = null;
     } catch (Exception $ex) {
         $history_results = null;
         $history = null;
         $history_exception = $ex;
     }
     try {
         $browse_results = DiffusionBrowseResultSet::newFromConduit($this->callConduitWithDiffusionRequest('diffusion.browsequery', array('path' => $drequest->getPath(), 'commit' => $drequest->getCommit())));
         $browse_paths = $browse_results->getPaths();
         foreach ($browse_paths 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;
                 }
             }
         }
         $browse_exception = null;
     } catch (Exception $ex) {
         $browse_results = null;
         $browse_paths = null;
         $browse_exception = $ex;
     }
     $phids = array_keys($phids);
     $handles = $this->loadViewerHandles($phids);
     if ($browse_results) {
         $readme = $this->callConduitWithDiffusionRequest('diffusion.readmequery', array('paths' => $browse_results->getPathDicts(), 'commit' => $drequest->getStableCommit()));
     } else {
         $readme = null;
     }
     $content[] = $this->buildBrowseTable($browse_results, $browse_paths, $browse_exception, $handles);
     $content[] = $this->buildHistoryTable($history_results, $history, $history_exception, $handles);
     try {
         $content[] = $this->buildTagListTable($drequest);
     } catch (Exception $ex) {
         if (!$repository->isImporting()) {
             $content[] = $this->renderStatusMessage(pht('Unable to Load Tags'), $ex->getMessage());
         }
     }
     try {
         $content[] = $this->buildBranchListTable($drequest);
     } catch (Exception $ex) {
         if (!$repository->isImporting()) {
             $content[] = $this->renderStatusMessage(pht('Unable to Load Branches'), $ex->getMessage());
         }
     }
     if ($readme) {
         $box = new PHUIBoxView();
         $box->appendChild($readme);
         $box->addPadding(PHUI::PADDING_LARGE);
         $panel = new PHUIObjectBoxView();
         $panel->setHeaderText(pht('README'));
         $panel->appendChild($box);
         $content[] = $panel;
     }
     return $content;
 }