@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Modernize "Author" and "Committer" rendering for commits

Summary:
Ref T13552. Give "Commit" objects a more modern, identity-aware way to render author and committer information.

This uses handles in a more modern way and gives us a single read callsite for raw author and committer names.

Test Plan:
- Grepped for callers to the old methods, found none. (There are a lot of "renderAuthor()" callers in transactions, but this call takes no parameters.)
- Viewed some commits, saw sensible lists of authors and committers.

Maniphest Tasks: T13552

Differential Revision: https://secure.phabricator.com/D21405

+98 -76
+5 -13
src/applications/audit/view/PhabricatorAuditListView.php
··· 90 90 foreach ($commit->getAudits() as $audit) { 91 91 $phids[] = $audit->getAuditorPHID(); 92 92 } 93 - 94 - $author_phid = $commit->getAuthorPHID(); 95 - if ($author_phid) { 96 - $phids[] = $author_phid; 97 - } 98 93 } 99 94 100 95 $handles = $viewer->loadHandles($phids); ··· 126 121 $status_color = $status->getColor(); 127 122 $status_icon = $status->getIcon(); 128 123 129 - $author_phid = $commit->getAuthorPHID(); 130 - if ($author_phid) { 131 - $author_name = $handles[$author_phid]->renderLink(); 132 - } else { 133 - $author_name = $commit->getCommitData()->getAuthorName(); 134 - } 135 - 136 124 $item = id(new PHUIObjectItemView()) 137 125 ->setObjectName($commit_name) 138 126 ->setHeader($commit_desc) 139 127 ->setHref($commit_link) 140 128 ->setDisabled($commit->isUnreachable()) 141 - ->addByline(pht('Author: %s', $author_name)) 142 129 ->addIcon('none', $committed); 130 + 131 + $author_name = $commit->newCommitAuthorView($viewer); 132 + if ($author_name) { 133 + $item->addByline(pht('Author: %s', $author_name)); 134 + } 143 135 144 136 if ($show_drafts) { 145 137 if ($commit->getHasDraft($viewer)) {
+34 -17
src/applications/diffusion/controller/DiffusionCommitController.php
··· 625 625 } 626 626 } 627 627 628 - $author_epoch = $data->getCommitDetail('authorEpoch'); 628 + $provenance_list = new PHUIStatusListView(); 629 629 630 - $committed_info = id(new PHUIStatusItemView()) 631 - ->setNote(phabricator_datetime($commit->getEpoch(), $viewer)) 632 - ->setTarget($commit->renderAnyCommitter($viewer, $handles)); 630 + $author_view = $commit->newCommitAuthorView($viewer); 631 + if ($author_view) { 632 + $author_date = $data->getCommitDetail('authorEpoch'); 633 + $author_date = phabricator_datetime($author_date, $viewer); 633 634 634 - $committed_list = new PHUIStatusListView(); 635 - $committed_list->addItem($committed_info); 636 - $view->addProperty( 637 - pht('Committed'), 638 - $committed_list); 635 + $provenance_list->addItem( 636 + id(new PHUIStatusItemView()) 637 + ->setTarget($author_view) 638 + ->setNote(pht('Authored on %s', $author_date))); 639 + } 640 + 641 + if (!$commit->isAuthorSameAsCommitter()) { 642 + $committer_view = $commit->newCommitCommitterView($viewer); 643 + if ($committer_view) { 644 + $committer_date = $commit->getEpoch(); 645 + $committer_date = phabricator_datetime($committer_date, $viewer); 646 + 647 + $provenance_list->addItem( 648 + id(new PHUIStatusItemView()) 649 + ->setTarget($committer_view) 650 + ->setNote(pht('Committed on %s', $committer_date))); 651 + } 652 + } 639 653 640 654 if ($push_logs) { 641 655 $pushed_list = new PHUIStatusListView(); 642 656 643 657 foreach ($push_logs as $push_log) { 644 - $pushed_item = id(new PHUIStatusItemView()) 645 - ->setTarget($handles[$push_log->getPusherPHID()]->renderLink()) 646 - ->setNote(phabricator_datetime($push_log->getEpoch(), $viewer)); 647 - $pushed_list->addItem($pushed_item); 658 + $pusher_date = $push_log->getEpoch(); 659 + $pusher_date = phabricator_datetime($pusher_date, $viewer); 660 + 661 + $pusher_view = $handles[$push_log->getPusherPHID()]->renderLink(); 662 + 663 + $provenance_list->addItem( 664 + id(new PHUIStatusItemView()) 665 + ->setTarget($pusher_view) 666 + ->setNote(pht('Pushed on %s', $pusher_date))); 648 667 } 649 - 650 - $view->addProperty( 651 - pht('Pushed'), 652 - $pushed_list); 653 668 } 669 + 670 + $view->addProperty(pht('Provenance'), $provenance_list); 654 671 655 672 $reviewer_phid = $data->getCommitDetail('reviewerPHID'); 656 673 if ($reviewer_phid) {
+59 -46
src/applications/repository/storage/PhabricatorRepositoryCommit.php
··· 377 377 return $repository->formatCommitName($identifier, $local = true); 378 378 } 379 379 380 - /** 381 - * Make a strong effort to find a way to render this commit's committer. 382 - * This currently attempts to use @{PhabricatorRepositoryIdentity}, and 383 - * falls back to examining the commit detail information. After we force 384 - * the migration to using identities, update this method to remove the 385 - * fallback. See T12164 for details. 386 - */ 387 - public function renderAnyCommitter(PhabricatorUser $viewer, $handles) { 388 - $committer = $this->renderCommitter($viewer, $handles); 389 - if ($committer) { 390 - return $committer; 391 - } 392 - 393 - return $this->renderAuthor($viewer, $handles); 394 - } 395 - 396 - public function renderCommitter(PhabricatorUser $viewer, $handles) { 397 - $committer_phid = $this->getCommitterDisplayPHID(); 398 - if ($committer_phid) { 399 - return $handles[$committer_phid]->renderLink(); 400 - } 401 - 402 - $data = $this->getCommitData(); 403 - $committer_name = $data->getCommitDetail('committer'); 404 - if (strlen($committer_name)) { 405 - return DiffusionView::renderName($committer_name); 406 - } 407 - 408 - return null; 409 - } 410 - 411 - public function renderAuthor(PhabricatorUser $viewer, $handles) { 412 - $author_phid = $this->getAuthorDisplayPHID(); 413 - if ($author_phid) { 414 - return $handles[$author_phid]->renderLink(); 415 - } 416 - 417 - $data = $this->getCommitData(); 418 - $author_name = $data->getAuthorName(); 419 - if (strlen($author_name)) { 420 - return DiffusionView::renderName($author_name); 421 - } 422 - 423 - return null; 424 - } 425 - 426 380 public function loadIdentities(PhabricatorUser $viewer) { 427 381 if ($this->authorIdentity !== self::ATTACHABLE) { 428 382 return $this; ··· 510 464 public function isPermanentCommit() { 511 465 return (bool)$this->isPartiallyImported(self::IMPORTED_CLOSEABLE); 512 466 } 467 + 468 + public function newCommitAuthorView(PhabricatorUser $viewer) { 469 + $author_phid = $this->getAuthorDisplayPHID(); 470 + if ($author_phid) { 471 + $handles = $viewer->loadHandles(array($author_phid)); 472 + return $handles[$author_phid]->renderLink(); 473 + } 474 + 475 + $author = $this->getRawAuthorStringForDisplay(); 476 + if (strlen($author)) { 477 + return DiffusionView::renderName($author); 478 + } 479 + 480 + return null; 481 + } 482 + 483 + public function newCommitCommitterView(PhabricatorUser $viewer) { 484 + $committer_phid = $this->getCommitterDisplayPHID(); 485 + if ($committer_phid) { 486 + $handles = $viewer->loadHandles(array($committer_phid)); 487 + return $handles[$committer_phid]->renderLink(); 488 + } 489 + 490 + $committer = $this->getRawCommitterStringForDisplay(); 491 + if (strlen($committer)) { 492 + return DiffusionView::renderName($committer); 493 + } 494 + 495 + return null; 496 + } 497 + 498 + public function isAuthorSameAsCommitter() { 499 + $author_phid = $this->getAuthorDisplayPHID(); 500 + $committer_phid = $this->getCommitterDisplayPHID(); 501 + 502 + if ($author_phid && $committer_phid) { 503 + return ($author_phid === $committer_phid); 504 + } 505 + 506 + if ($author_phid || $committer_phid) { 507 + return false; 508 + } 509 + 510 + $author = $this->getRawAuthorStringForDisplay(); 511 + $committer = $this->getRawCommitterStringForDisplay(); 512 + 513 + return ($author === $committer); 514 + } 515 + 516 + private function getRawAuthorStringForDisplay() { 517 + $data = $this->getCommitData(); 518 + return $data->getAuthorName(); 519 + } 520 + 521 + private function getRawCommitterStringForDisplay() { 522 + $data = $this->getCommitData(); 523 + return $data->getCommitDetail('committer'); 524 + } 525 + 513 526 514 527 /* -( PhabricatorPolicyInterface )----------------------------------------- */ 515 528