1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-23 07:12:41 +01:00

Compare two branches

Summary:
This shows the commits list only (Actual `git diff` will show up at a later date).
The inputs are left as text-fields, to allow the form to accept anything that can be resolved. The form is GET, to allow sharing URIs.

The conduit method response array is compatible with that of `diffusion.historyquery`, to make it easy to build
the "history" table.

The hardest part here was, of course, Naming. I think "from" and "onto" are unconfusing, and I'm fairly confident that the "to merge"
instructions are in sync with the actual content of the page.

Test Plan: Look at several "compare" views, with various values of "from" and "onto".

Reviewers: #blessed_reviewers!, epriestley

Subscribers: caov297, 20after4, Sam2304, reardencode, baileyb, chad, Korvin

Maniphest Tasks: T929

Differential Revision: https://secure.phabricator.com/D15330
This commit is contained in:
Aviv Eyal 2016-12-05 16:19:26 -08:00 committed by epriestley
parent 0ad1dd640a
commit 43f9927a38
5 changed files with 279 additions and 4 deletions

View file

@ -635,6 +635,7 @@ phutil_register_library_map(array(
'DiffusionCommitRevisionReviewersHeraldField' => 'applications/diffusion/herald/DiffusionCommitRevisionReviewersHeraldField.php', 'DiffusionCommitRevisionReviewersHeraldField' => 'applications/diffusion/herald/DiffusionCommitRevisionReviewersHeraldField.php',
'DiffusionCommitRevisionSubscribersHeraldField' => 'applications/diffusion/herald/DiffusionCommitRevisionSubscribersHeraldField.php', 'DiffusionCommitRevisionSubscribersHeraldField' => 'applications/diffusion/herald/DiffusionCommitRevisionSubscribersHeraldField.php',
'DiffusionCommitTagsController' => 'applications/diffusion/controller/DiffusionCommitTagsController.php', 'DiffusionCommitTagsController' => 'applications/diffusion/controller/DiffusionCommitTagsController.php',
'DiffusionCompareController' => 'applications/diffusion/controller/DiffusionCompareController.php',
'DiffusionConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionConduitAPIMethod.php', 'DiffusionConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionConduitAPIMethod.php',
'DiffusionController' => 'applications/diffusion/controller/DiffusionController.php', 'DiffusionController' => 'applications/diffusion/controller/DiffusionController.php',
'DiffusionCreateCommentConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionCreateCommentConduitAPIMethod.php', 'DiffusionCreateCommentConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionCreateCommentConduitAPIMethod.php',
@ -5273,6 +5274,7 @@ phutil_register_library_map(array(
'DiffusionCommitRevisionReviewersHeraldField' => 'DiffusionCommitHeraldField', 'DiffusionCommitRevisionReviewersHeraldField' => 'DiffusionCommitHeraldField',
'DiffusionCommitRevisionSubscribersHeraldField' => 'DiffusionCommitHeraldField', 'DiffusionCommitRevisionSubscribersHeraldField' => 'DiffusionCommitHeraldField',
'DiffusionCommitTagsController' => 'DiffusionController', 'DiffusionCommitTagsController' => 'DiffusionController',
'DiffusionCompareController' => 'DiffusionController',
'DiffusionConduitAPIMethod' => 'ConduitAPIMethod', 'DiffusionConduitAPIMethod' => 'ConduitAPIMethod',
'DiffusionController' => 'PhabricatorController', 'DiffusionController' => 'PhabricatorController',
'DiffusionCreateCommentConduitAPIMethod' => 'DiffusionConduitAPIMethod', 'DiffusionCreateCommentConduitAPIMethod' => 'DiffusionConduitAPIMethod',

View file

@ -65,6 +65,7 @@ final class PhabricatorDiffusionApplication extends PhabricatorApplication {
=> 'DiffusionCommitTagsController', => 'DiffusionCommitTagsController',
'commit/(?P<commit>[a-z0-9]+)/edit/' 'commit/(?P<commit>[a-z0-9]+)/edit/'
=> 'DiffusionCommitEditController', => 'DiffusionCommitEditController',
'compare/' => 'DiffusionCompareController',
'manage/(?:(?P<panel>[^/]+)/)?' 'manage/(?:(?P<panel>[^/]+)/)?'
=> 'DiffusionRepositoryManagePanelsController', => 'DiffusionRepositoryManagePanelsController',
'uri/' => array( 'uri/' => array(

View file

@ -22,6 +22,7 @@ final class DiffusionHistoryQueryConduitAPIMethod
protected function defineCustomParamTypes() { protected function defineCustomParamTypes() {
return array( return array(
'commit' => 'required string', 'commit' => 'required string',
'against' => 'optional string',
'path' => 'required string', 'path' => 'required string',
'offset' => 'required int', 'offset' => 'required int',
'limit' => 'required int', 'limit' => 'required int',
@ -43,10 +44,17 @@ final class DiffusionHistoryQueryConduitAPIMethod
$drequest = $this->getDiffusionRequest(); $drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository(); $repository = $drequest->getRepository();
$commit_hash = $request->getValue('commit'); $commit_hash = $request->getValue('commit');
$against_hash = $request->getValue('against');
$path = $request->getValue('path'); $path = $request->getValue('path');
$offset = $request->getValue('offset'); $offset = $request->getValue('offset');
$limit = $request->getValue('limit'); $limit = $request->getValue('limit');
if (strlen($against_hash)) {
$commit_range = "${against_hash}..${commit_hash}";
} else {
$commit_range = $commit_hash;
}
list($stdout) = $repository->execxLocalCommand( list($stdout) = $repository->execxLocalCommand(
'log '. 'log '.
'--skip=%d '. '--skip=%d '.
@ -56,15 +64,12 @@ final class DiffusionHistoryQueryConduitAPIMethod
$offset, $offset,
$limit, $limit,
'%H:%P', '%H:%P',
$commit_hash, $commit_range,
// Git omits merge commits if the path is provided, even if it is empty. // Git omits merge commits if the path is provided, even if it is empty.
(strlen($path) ? csprintf('%s', $path) : '')); (strlen($path) ? csprintf('%s', $path) : ''));
$lines = explode("\n", trim($stdout)); $lines = explode("\n", trim($stdout));
$lines = array_filter($lines); $lines = array_filter($lines);
if (!$lines) {
return array();
}
$hash_list = array(); $hash_list = array();
$parent_map = array(); $parent_map = array();
@ -76,6 +81,10 @@ final class DiffusionHistoryQueryConduitAPIMethod
$this->parents = $parent_map; $this->parents = $parent_map;
if (!$hash_list) {
return array();
}
return DiffusionQuery::loadHistoryForCommitIdentifiers( return DiffusionQuery::loadHistoryForCommitIdentifiers(
$hash_list, $hash_list,
$drequest); $drequest);

View file

@ -0,0 +1,260 @@
<?php
final class DiffusionCompareController extends DiffusionController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$response = $this->loadDiffusionContext();
if ($response) {
return $response;
}
$viewer = $this->getViewer();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$content = array();
$crumbs = $this->buildCrumbs(array('view' => 'compare'));
$empty_title = null;
$error_message = null;
if ($repository->getVersionControlSystem() !=
PhabricatorRepositoryType::REPOSITORY_TYPE_GIT) {
$empty_title = pht('Not supported');
$error_message = pht(
'This feature is not yet supported for %s repositories.',
$repository->getVersionControlSystem());
$content[] = id(new PHUIInfoView())
->setTitle($empty_title)
->setSeverity(PHUIInfoView::SEVERITY_WARNING)
->setErrors(array($error_message));
}
$head_ref = $request->getStr('head');
$against_ref = $request->getStr('against');
$refs = id(new DiffusionCachedResolveRefsQuery())
->setRepository($repository)
->withRefs(array($head_ref, $against_ref))
->execute();
if (count($refs) == 2) {
$content[] = $this->buildCompareContent($drequest);
} else {
$content[] = $this->buildCompareForm($request, $refs);
}
return $this->newPage()
->setTitle(
array(
$repository->getName(),
$repository->getDisplayName(),
))
->setCrumbs($crumbs)
->appendChild($content);
}
private function buildCompareForm(AphrontRequest $request, array $resolved) {
$viewer = $this->getViewer();
$head_ref = $request->getStr('head');
$against_ref = $request->getStr('against');
if (idx($resolved, $head_ref)) {
$e_head = null;
} else {
$e_head = 'Not Found';
}
if (idx($resolved, $against_ref)) {
$e_against = null;
} else {
$e_against = 'Not Found';
}
$form = id(new AphrontFormView())
->setUser($viewer)
->setMethod('GET')
->appendControl(
id(new AphrontFormTextControl())
->setLabel(pht('Head'))
->setName('head')
->setError($e_head)
->setValue($head_ref))
->appendControl(
id(new AphrontFormTextControl())
->setLabel(pht('Against'))
->setName('against')
->setError($e_against)
->setValue($against_ref))
->appendControl(
id(new AphrontFormSubmitControl())
->setValue('Compare'));
return $form;
}
private function buildCompareContent(DiffusionRequest $drequest) {
$request = $this->getRequest();
$repository = $drequest->getRepository();
$head_ref = $request->getStr('head');
$against_ref = $request->getStr('against');
$content = array();
$pager = id(new PHUIPagerView())
->readFromRequest($request);
try {
$history_results = $this->callConduitWithDiffusionRequest(
'diffusion.historyquery',
array(
'commit' => $head_ref,
'against' => $against_ref,
'path' => $drequest->getPath(),
'offset' => $pager->getOffset(),
'limit' => $pager->getPageSize() + 1,
));
$history = DiffusionPathChange::newFromConduit(
$history_results['pathChanges']);
$history = $pager->sliceResults($history);
$history_exception = null;
} catch (Exception $ex) {
$history_results = null;
$history = null;
$history_exception = $ex;
}
if ($history_results) {
$content[] = $this->buildCompareProperties($drequest, $history_results);
}
$content[] = $this->buildCompareForm(
$request,
array($head_ref => true, $against_ref => true));
$content[] = $this->buildHistoryTable(
$history_results,
$history,
$pager,
$history_exception);
$content[] = $this->renderTablePagerBox($pager);
return $content;
}
private function buildCompareProperties($drequest, array $history_results) {
$viewer = $this->getViewer();
$request = $this->getRequest();
$repository = $drequest->getRepository();
$head_ref = $request->getStr('head');
$against_ref = $request->getStr('against');
$reverse_uri = $repository->getPathURI(
"compare/?head=${against_ref}&against=${head_ref}");
$actions = id(new PhabricatorActionListView());
$actions->setUser($viewer);
$actions->addAction(id(new PhabricatorActionView())
->setName(pht('Reverse Comparison'))
->setHref($reverse_uri)
->setIcon('fa-list'));
$view = id(new PHUIPropertyListView())
->setUser($viewer)
->setActionList($actions);
$readme =
'These are the commits that are reachable from **Head** commit and not '.
'from the **Against** commit.';
$readme = new PHUIRemarkupView($viewer, $readme);
$view->addTextContent($readme);
$view->addProperty(pht('Head'), $head_ref);
$view->addProperty(pht('Against'), $against_ref);
$header = id(new PHUIHeaderView())
->setUser($viewer)
->setPolicyObject($drequest->getRepository());
$box = id(new PHUIObjectBoxView())
->setUser($viewer)
->setHeader($header)
->addPropertyList($view);
return $box;
}
private function buildHistoryTable(
$history_results,
$history,
$pager,
$history_exception) {
$request = $this->getRequest();
$viewer = $request->getUser();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
if ($history_exception) {
if ($repository->isImporting()) {
return $this->renderStatusMessage(
pht('Still Importing...'),
pht(
'This repository is still importing. History is not yet '.
'available.'));
} else {
return $this->renderStatusMessage(
pht('Unable to Retrieve History'),
$history_exception->getMessage());
}
}
if (!$history) {
return $this->renderStatusMessage(
pht('Up to date'),
new PHUIRemarkupView(
$viewer,
pht(
'**Against** is strictly ahead of **Head** '.
'- no commits are missing.')));
}
$history_table = id(new DiffusionHistoryTableView())
->setUser($viewer)
->setDiffusionRequest($drequest)
->setHistory($history);
// TODO: Super sketchy?
$history_table->loadRevisions();
if ($history_results) {
$history_table->setParents($history_results['parents']);
$history_table->setIsHead(!$pager->getOffset());
$history_table->setIsTail(!$pager->getHasMorePages());
}
// TODO also expose diff.
$panel = new PHUIObjectBoxView();
$header = id(new PHUIHeaderView())
->setHeader(pht('Missing Commits'));
$panel->setHeader($header);
$panel->setTable($history_table);
return $panel;
}
}

View file

@ -213,6 +213,9 @@ abstract class DiffusionController extends PhabricatorController {
case 'change': case 'change':
$view_name = pht('Change'); $view_name = pht('Change');
break; break;
case 'compare':
$view_name = pht('Compare');
break;
} }
$crumb = id(new PHUICrumbView()) $crumb = id(new PHUICrumbView())