1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 05:50:55 +01:00

Don't fatal when viewing tags pointing at commits we haven't imported/parsed yet

Summary:
In Diffusion, the "Tags" view may read commits which haven't imported or parsed yet, and thus don't have loadable objects.

Most of this logic tests for `if ($commit)`, but the author part did not. Instead, don't render author information if `$commit` is not present.

Test Plan:
  - Loaded tags view with commits present.
  - Faked `$commit = null;`, loaded tag view, got this instead of a fatal:

{F5068432}

Reviewers: chad, amckinley

Reviewed By: chad

Differential Revision: https://secure.phabricator.com/D18290
This commit is contained in:
epriestley 2017-07-28 10:37:53 -07:00
parent d114bc4a19
commit ee884db1f9

View file

@ -52,24 +52,12 @@ final class DiffusionTagListView extends DiffusionView {
'commit' => $tag->getCommitIdentifier(),
));
$author = null;
if ($commit && $commit->getAuthorPHID()) {
$author = $this->handles[$commit->getAuthorPHID()]->renderLink();
} else if ($commit && $commit->getCommitData()) {
$author = self::renderName($commit->getCommitData()->getAuthorName());
if ($commit) {
$author = $this->renderAuthor($tag, $commit);
} else {
$author = self::renderName($tag->getAuthor());
$author = null;
}
$committed = phabricator_datetime($commit->getEpoch(), $viewer);
$author_name = phutil_tag(
'strong',
array(
'class' => 'diffusion-history-author-name',
),
$author);
$authored = pht('%s on %s.', $author_name, $committed);
$description = null;
if ($tag->getType() == 'git/tag') {
// In Git, a tag may be a "real" tag, or just a reference to a commit.
@ -139,16 +127,43 @@ final class DiffusionTagListView extends DiffusionView {
->setHref($tag_href)
->addAttribute(array($commit_tag))
->addAttribute($description)
->addAttribute($authored)
->setSideColumn(array(
$build_view,
$button_bar,
));
if ($author) {
$item->addAttribute($author);
}
$list->addItem($item);
}
return $list;
}
private function renderAuthor(
DiffusionRepositoryTag $tag,
PhabricatorRepositoryCommit $commit) {
$viewer = $this->getViewer();
if ($commit->getAuthorPHID()) {
$author = $this->handles[$commit->getAuthorPHID()]->renderLink();
} else if ($commit->getCommitData()) {
$author = self::renderName($commit->getCommitData()->getAuthorName());
} else {
$author = self::renderName($tag->getAuthor());
}
$committed = phabricator_datetime($commit->getEpoch(), $viewer);
$author_name = phutil_tag(
'strong',
array(
'class' => 'diffusion-history-author-name',
),
$author);
return pht('%s on %s.', $author_name, $committed);
}
}