1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-30 09:20:58 +01:00

Modernize UI for "Compare" in Diffusion

Summary: Ref T929. We've made some UI updates since D15330.

Test Plan: {F2079125}

Reviewers: avivey, chad

Reviewed By: chad

Maniphest Tasks: T929

Differential Revision: https://secure.phabricator.com/D16990
This commit is contained in:
epriestley 2016-12-05 17:40:24 -08:00
parent 43f9927a38
commit fc1adf9875
4 changed files with 287 additions and 179 deletions

View file

@ -1651,6 +1651,7 @@ final class DiffusionBrowseController extends DiffusionController {
protected function buildCurtain(DiffusionRequest $drequest) { protected function buildCurtain(DiffusionRequest $drequest) {
$viewer = $this->getViewer(); $viewer = $this->getViewer();
$repository = $drequest->getRepository();
$curtain = $this->newCurtainView($drequest); $curtain = $this->newCurtainView($drequest);
@ -1666,6 +1667,21 @@ final class DiffusionBrowseController extends DiffusionController {
->setIcon('fa-list')); ->setIcon('fa-list'));
$behind_head = $drequest->getSymbolicCommit(); $behind_head = $drequest->getSymbolicCommit();
if ($repository->supportsBranchComparison()) {
$compare_uri = $drequest->generateURI(
array(
'action' => 'compare',
));
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('Compare Against...'))
->setIcon('fa-code-fork')
->setWorkflow(true)
->setHref($compare_uri));
}
$head_uri = $drequest->generateURI( $head_uri = $drequest->generateURI(
array( array(
'commit' => '', 'commit' => '',

View file

@ -16,104 +16,87 @@ final class DiffusionCompareController extends DiffusionController {
$drequest = $this->getDiffusionRequest(); $drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository(); $repository = $drequest->getRepository();
$content = array(); if (!$repository->supportsBranchComparison()) {
return $this->newDialog()
$crumbs = $this->buildCrumbs(array('view' => 'compare')); ->setTitle(pht('Not Supported'))
->appendParagraph(
$empty_title = null; pht(
$error_message = null; 'Branch comparison is not supported for this version control '.
'system.'))
if ($repository->getVersionControlSystem() != ->addCancelButton($this->getApplicationURI(), pht('Okay'));
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'); $head_ref = $request->getStr('head');
$against_ref = $request->getStr('against'); $against_ref = $request->getStr('against');
$refs = id(new DiffusionCachedResolveRefsQuery()) $must_prompt = false;
->setRepository($repository) if (!$request->isFormPost()) {
->withRefs(array($head_ref, $against_ref)) if (!strlen($head_ref)) {
->execute(); $head_ref = $drequest->getSymbolicCommit();
if (!strlen($head_ref)) {
$head_ref = $drequest->getBranch();
}
}
if (!strlen($against_ref)) {
$default_branch = $repository->getDefaultBranch();
if ($default_branch != $head_ref) {
$against_ref = $default_branch;
if (count($refs) == 2) { // If we filled this in by default, we want to prompt the user to
$content[] = $this->buildCompareContent($drequest); // confirm that this is really what they want.
} else { $must_prompt = true;
$content[] = $this->buildCompareForm($request, $refs); }
}
} }
$refs = $drequest->resolveRefs(
return $this->newPage() array_filter(
->setTitle(
array( array(
$repository->getName(), $head_ref,
$repository->getDisplayName(), $against_ref,
)) )));
->setCrumbs($crumbs)
->appendChild($content);
}
private function buildCompareForm(AphrontRequest $request, array $resolved) { $identical = false;
$viewer = $this->getViewer(); if ($head_ref === $against_ref) {
$identical = true;
$head_ref = $request->getStr('head');
$against_ref = $request->getStr('against');
if (idx($resolved, $head_ref)) {
$e_head = null;
} else { } else {
$e_head = 'Not Found'; if (count($refs) == 2) {
if ($refs[$head_ref] === $refs[$against_ref]) {
$identical = true;
}
}
} }
if (idx($resolved, $against_ref)) { if ($must_prompt || count($refs) != 2 || $identical) {
$e_against = null; return $this->buildCompareDialog(
} else { $head_ref,
$e_against = 'Not Found'; $against_ref,
$refs,
$identical);
} }
if ($request->isFormPost()) {
// Redirect to a stable URI that can be copy/pasted.
$compare_uri = $drequest->generateURI(
array(
'action' => 'compare',
'head' => $head_ref,
'against' => $against_ref,
));
$form = id(new AphrontFormView()) return id(new AphrontRedirectResponse())->setURI($compare_uri);
->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; $crumbs = $this->buildCrumbs(
} array(
'view' => 'compare',
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()) $pager = id(new PHUIPagerView())
->readFromRequest($request); ->readFromRequest($request);
$history = null;
try { try {
$history_results = $this->callConduitWithDiffusionRequest( $history_results = $this->callConduitWithDiffusionRequest(
'diffusion.historyquery', 'diffusion.historyquery',
@ -126,111 +109,189 @@ final class DiffusionCompareController extends DiffusionController {
)); ));
$history = DiffusionPathChange::newFromConduit( $history = DiffusionPathChange::newFromConduit(
$history_results['pathChanges']); $history_results['pathChanges']);
$history = $pager->sliceResults($history); $history = $pager->sliceResults($history);
$history_exception = null; $history_view = $this->newHistoryView(
$history_results,
$history,
$pager,
$head_ref,
$against_ref);
} catch (Exception $ex) { } 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()) { if ($repository->isImporting()) {
return $this->renderStatusMessage( $history_view = $this->renderStatusMessage(
pht('Still Importing...'), pht('Still Importing...'),
pht( pht(
'This repository is still importing. History is not yet '. 'This repository is still importing. History is not yet '.
'available.')); 'available.'));
} else { } else {
return $this->renderStatusMessage( $history_view = $this->renderStatusMessage(
pht('Unable to Retrieve History'), pht('Unable to Retrieve History'),
$history_exception->getMessage()); $ex->getMessage());
} }
} }
$header = id(new PHUIHeaderView())
->setHeader(
pht(
'Changes on %s but not %s',
phutil_tag('em', array(), $head_ref),
phutil_tag('em', array(), $against_ref)));
$curtain = $this->buildCurtain($head_ref, $against_ref);
$column_view = id(new PHUITwoColumnView())
->setHeader($header)
->setCurtain($curtain)
->setMainColumn(
array(
$history_view,
));
return $this->newPage()
->setTitle(
array(
$repository->getName(),
$repository->getDisplayName(),
))
->setCrumbs($crumbs)
->appendChild($column_view);
}
private function buildCompareDialog(
$head_ref,
$against_ref,
array $resolved,
$identical) {
$viewer = $this->getViewer();
$request = $this->getRequest();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$e_head = null;
$e_against = null;
$errors = array();
if ($request->isFormPost()) {
if (!strlen($head_ref)) {
$e_head = pht('Required');
$errors[] = pht(
'You must provide two different commits to compare.');
} else if (!isset($resolved[$head_ref])) {
$e_head = pht('Not Found');
$errors[] = pht(
'Commit "%s" is not a valid commit in this repository.',
$head_ref);
}
if (!strlen($against_ref)) {
$e_against = pht('Required');
$errors[] = pht(
'You must provide two different commits to compare.');
} else if (!isset($resolved[$against_ref])) {
$e_against = pht('Not Found');
$errors[] = pht(
'Commit "%s" is not a valid commit in this repository.',
$against_ref);
}
if ($identical) {
$e_head = pht('Identical');
$e_against = pht('Identical');
$errors[] = pht(
'Both references identify the same commit. You can not compare a '.
'commit against itself.');
}
}
$form = id(new AphrontFormView())
->setViewer($viewer)
->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));
$cancel_uri = $repository->generateURI(
array(
'action' => 'browse',
));
return $this->newDialog()
->setTitle(pht('Compare Against'))
->setWidth(AphrontDialogView::WIDTH_FORM)
->setErrors($errors)
->appendForm($form)
->addSubmitButton(pht('Compare'))
->addCancelButton($cancel_uri, pht('Cancel'));
}
private function buildCurtain($head_ref, $against_ref) {
$viewer = $this->getViewer();
$request = $this->getRequest();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$curtain = $this->newCurtainView(null);
$reverse_uri = $drequest->generateURI(
array(
'action' => 'compare',
'head' => $against_ref,
'against' => $head_ref,
));
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('Reverse Comparison'))
->setHref($reverse_uri)
->setIcon('fa-refresh'));
$compare_uri = $drequest->generateURI(
array(
'action' => 'compare',
'head' => $head_ref,
));
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('Compare Against...'))
->setIcon('fa-code-fork')
->setWorkflow(true)
->setHref($compare_uri));
// TODO: Provide a "Show Diff" action.
return $curtain;
}
private function newHistoryView(
array $results,
array $history,
PHUIPagerView $pager,
$head_ref,
$against_ref) {
$request = $this->getRequest();
$viewer = $this->getViewer();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
if (!$history) { if (!$history) {
return $this->renderStatusMessage( return $this->renderStatusMessage(
pht('Up to date'), pht('Up To Date'),
new PHUIRemarkupView( pht(
$viewer, 'There are no commits on %s that are not already on %s.',
pht( phutil_tag('strong', array(), $head_ref),
'**Against** is strictly ahead of **Head** '. phutil_tag('strong', array(), $against_ref)));
'- no commits are missing.')));
} }
$history_table = id(new DiffusionHistoryTableView()) $history_table = id(new DiffusionHistoryTableView())
@ -238,23 +299,27 @@ final class DiffusionCompareController extends DiffusionController {
->setDiffusionRequest($drequest) ->setDiffusionRequest($drequest)
->setHistory($history); ->setHistory($history);
// TODO: Super sketchy?
$history_table->loadRevisions(); $history_table->loadRevisions();
if ($history_results) { if ($history) {
$history_table->setParents($history_results['parents']); $history_table->setParents($results['parents']);
$history_table->setIsHead(!$pager->getOffset()); $history_table->setIsHead(!$pager->getOffset());
$history_table->setIsTail(!$pager->getHasMorePages()); $history_table->setIsTail(!$pager->getHasMorePages());
} }
// TODO also expose diff.
$panel = new PHUIObjectBoxView();
$header = id(new PHUIHeaderView()) $header = id(new PHUIHeaderView())
->setHeader(pht('Missing Commits')); ->setHeader(pht('Commits'));
$panel->setHeader($header);
$panel->setTable($history_table);
return $panel; $object_box = id(new PHUIObjectBoxView())
->setHeader($header)
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->setTable($history_table);
$pager_box = $this->renderTablePagerBox($pager);
return array(
$object_box,
$pager_box,
);
} }
} }

View file

@ -644,7 +644,7 @@ abstract class DiffusionRequest extends Phobject {
return $match; return $match;
} }
private function resolveRefs(array $refs, array $types) { public function resolveRefs(array $refs, array $types = array()) {
// First, try to resolve refs from fast cache sources. // First, try to resolve refs from fast cache sources.
$cached_query = id(new DiffusionCachedResolveRefsQuery()) $cached_query = id(new DiffusionCachedResolveRefsQuery())
->setRepository($this->getRepository()) ->setRepository($this->getRepository())

View file

@ -689,6 +689,7 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
case 'lint': case 'lint':
case 'pathtree': case 'pathtree':
case 'refs': case 'refs':
case 'compare':
break; break;
case 'branch': case 'branch':
// NOTE: This does not actually require a branch, and won't have one // NOTE: This does not actually require a branch, and won't have one
@ -710,6 +711,9 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
$commit = idx($params, 'commit'); $commit = idx($params, 'commit');
$line = idx($params, 'line'); $line = idx($params, 'line');
$head = idx($params, 'head');
$against = idx($params, 'against');
if ($req_commit && !strlen($commit)) { if ($req_commit && !strlen($commit)) {
throw new Exception( throw new Exception(
pht( pht(
@ -734,11 +738,13 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
$path = phutil_escape_uri($path); $path = phutil_escape_uri($path);
} }
$raw_branch = $branch;
if (strlen($branch)) { if (strlen($branch)) {
$branch = phutil_escape_uri_path_component($branch); $branch = phutil_escape_uri_path_component($branch);
$path = "{$branch}/{$path}"; $path = "{$branch}/{$path}";
} }
$raw_commit = $commit;
if (strlen($commit)) { if (strlen($commit)) {
$commit = str_replace('$', '$$', $commit); $commit = str_replace('$', '$$', $commit);
$commit = ';'.phutil_escape_uri($commit); $commit = ';'.phutil_escape_uri($commit);
@ -748,6 +754,7 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
$line = '$'.phutil_escape_uri($line); $line = '$'.phutil_escape_uri($line);
} }
$query = array();
switch ($action) { switch ($action) {
case 'change': case 'change':
case 'history': case 'history':
@ -760,6 +767,20 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
case 'refs': case 'refs':
$uri = $this->getPathURI("/{$action}/{$path}{$commit}{$line}"); $uri = $this->getPathURI("/{$action}/{$path}{$commit}{$line}");
break; break;
case 'compare':
$uri = $this->getPathURI("/{$action}/");
if (strlen($head)) {
$query['head'] = $head;
} else if (strlen($raw_commit)) {
$query['commit'] = $raw_commit;
} else if (strlen($raw_branch)) {
$query['head'] = $raw_branch;
}
if (strlen($against)) {
$query['against'] = $against;
}
break;
case 'branch': case 'branch':
if (strlen($path)) { if (strlen($path)) {
$uri = $this->getPathURI("/repository/{$path}"); $uri = $this->getPathURI("/repository/{$path}");
@ -791,8 +812,10 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
); );
} }
if (idx($params, 'params')) { $query = idx($params, 'params', array()) + $query;
$uri->setQueryParams($params['params']);
if ($query) {
$uri->setQueryParams($query);
} }
return $uri; return $uri;
@ -2066,6 +2089,10 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
return $result; return $result;
} }
public function supportsBranchComparison() {
return $this->isGit();
}
/* -( Repository URIs )---------------------------------------------------- */ /* -( Repository URIs )---------------------------------------------------- */