Page MenuHomePhabricator

Start changing DiffusionCommitController to use identities
ClosedPublic

Authored by amckinley on Jun 12 2018, 9:15 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Apr 25, 1:52 AM
Unknown Object (File)
Fri, Apr 19, 7:47 PM
Unknown Object (File)
Sat, Mar 30, 3:56 AM
Unknown Object (File)
Thu, Mar 28, 10:48 AM
Unknown Object (File)
Feb 16 2024, 8:39 AM
Unknown Object (File)
Feb 5 2024, 12:43 AM
Unknown Object (File)
Feb 3 2024, 7:02 PM
Unknown Object (File)
Jan 28 2024, 10:26 AM
Subscribers
Tokens
"Piece of Eight" token, awarded by epriestley.

Details

Summary

Depends on D19491. Ref T12164.

Test Plan

Viewed some commits where the identity was mapped to a user and another that wasn't; saw the header render either a link to the user or the identity object.

Diff Detail

Repository
rP Phabricator
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

src/applications/diffusion/controller/DiffusionCommitController.php
721–724

This turned out to be way easier than trying to render user handles inside the identity handle renderer, and less ugly than copy/pasting a long function that's used everywhere.

epriestley added inline comments.
src/applications/diffusion/controller/DiffusionCommitController.php
706

This may still be null for installs that haven't run rebuild-identities, right? We could reasonably require the migration before this lands, I think.

721–724

Oh, yeah, nice -- this is way cleaner.

This revision is now accepted and ready to land.Jun 12 2018, 10:26 PM

Try to isolate all the "if (hasIdentity)" logic in one place, and start using it.

Could we go further and just turn this:

// Update after T12164.
if ($commit->hasAuthorIdentity()) {
  $author_identity = $commit->getAuthorIdentity();
  $author_phid = $author_identity->getIdentityHandle();
} else {
  $author_phid = $data->getCommitDetail('authorPHID');
}

...into this:

$author_phid = $commit->getAuthorDisplayPHID();

Tthat should give us even less stuff to handle/update around null later on, since we have ~3 of those blocks here and probably (?) more elsewhere.

src/applications/repository/storage/PhabricatorRepositoryCommit.php
449

Minor, but $viewer can probably typehint as PhabricatorUser here and elsewhere.

458

Verrrrry verrrry nitpicky, but this might be more clear:

if (x) {
  return;
}

if (y) {
  return;
}

return;

...than this:

if (x) {
  return;
} else {
  if (y) {
    return;
  } else {
    return;
  }
}

These methods also both implicitly return null at the bottom and maybe that would be clearer as an explicit return null;

src/applications/repository/storage/PhabricatorRepositoryIdentity.php
81

It wasn't obvious to me that this returns a PHID rather than a Handle. Maybe call it getIdentityDisplayPHID() or similar to make it more clear that we aren't getting a Handle back?

This revision is now accepted and ready to land.Aug 13 2018, 9:36 PM
This revision was automatically updated to reflect the committed changes.

The array typehint on $handles might eventually run into trouble because it might be a PhabricatorHandleList (an object which works like an array, but resolves lazily) sometimes. If you hit that, all you can do is remove the array typehint since there's no way to formally say array|PhabricatorHandleList.

(We could create some PhabricatorHandleList::newFromAlreadyResolvedArray(...) and then force everything to be PhabricatorHandleList, I guess.)

Looks quite clean otherwise, way better than the old code.

The array typehint on $handles might eventually run into trouble because it might be a PhabricatorHandleList (an object which works like an array, but resolves lazily) sometimes. If you hit that, all you can do is remove the array typehint since there's no way to formally say array|PhabricatorHandleList.

Oh, ok, I'll clean up the other callsite I saw doing the same thing.

Yeah -- long ago they all got array typehints, and then a bunch of them got removed when PhabricatorHandleList / PhabricatorHandlePool landed, but the newer Handle stuff hasn't made its way into all the crevices yet so there are still a few array typehints hiding out. If you run into one, it's appropriate to just remove it.