@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.

Remove `diffusion.getcommits` Conduit API method

Summary:
Ref T4245. This was obsoleted long ago and has no callers in Phabricator or Arcanist.

Also some minor cleanup.

Test Plan: `grep` for callers everywhere.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T4245

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

+3 -301
-2
src/__phutil_library_map__.php
··· 603 603 'DiffusionFileContentQuery' => 'applications/diffusion/query/filecontent/DiffusionFileContentQuery.php', 604 604 'DiffusionFileContentQueryConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionFileContentQueryConduitAPIMethod.php', 605 605 'DiffusionFindSymbolsConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionFindSymbolsConduitAPIMethod.php', 606 - 'DiffusionGetCommitsConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionGetCommitsConduitAPIMethod.php', 607 606 'DiffusionGetLintMessagesConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionGetLintMessagesConduitAPIMethod.php', 608 607 'DiffusionGetRecentCommitsByPathConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionGetRecentCommitsByPathConduitAPIMethod.php', 609 608 'DiffusionGitBranch' => 'applications/diffusion/data/DiffusionGitBranch.php', ··· 4566 4565 'DiffusionFileContentQuery' => 'DiffusionQuery', 4567 4566 'DiffusionFileContentQueryConduitAPIMethod' => 'DiffusionQueryConduitAPIMethod', 4568 4567 'DiffusionFindSymbolsConduitAPIMethod' => 'DiffusionConduitAPIMethod', 4569 - 'DiffusionGetCommitsConduitAPIMethod' => 'DiffusionConduitAPIMethod', 4570 4568 'DiffusionGetLintMessagesConduitAPIMethod' => 'DiffusionConduitAPIMethod', 4571 4569 'DiffusionGetRecentCommitsByPathConduitAPIMethod' => 'DiffusionConduitAPIMethod', 4572 4570 'DiffusionGitBranch' => 'Phobject',
-293
src/applications/diffusion/conduit/DiffusionGetCommitsConduitAPIMethod.php
··· 1 - <?php 2 - 3 - final class DiffusionGetCommitsConduitAPIMethod 4 - extends DiffusionConduitAPIMethod { 5 - 6 - public function getAPIMethodName() { 7 - return 'diffusion.getcommits'; 8 - } 9 - 10 - public function getMethodDescription() { 11 - return pht('Retrieve Diffusion commit information.'); 12 - } 13 - 14 - public function getMethodStatus() { 15 - return self::METHOD_STATUS_DEPRECATED; 16 - } 17 - 18 - public function getMethodStatusDescription() { 19 - return pht('Obsoleted by %s.', 'diffusion.querycommits'); 20 - } 21 - 22 - protected function defineParamTypes() { 23 - return array( 24 - 'commits' => 'required list<string>', 25 - ); 26 - } 27 - 28 - protected function defineReturnType() { 29 - return 'nonempty list<dict<string, wild>>'; 30 - } 31 - 32 - protected function execute(ConduitAPIRequest $request) { 33 - $results = array(); 34 - 35 - $commits = $request->getValue('commits'); 36 - $commits = array_fill_keys($commits, array()); 37 - foreach ($commits as $name => $info) { 38 - $matches = null; 39 - if (!preg_match('/^r([A-Z]+)([0-9a-f]+)\z/', $name, $matches)) { 40 - $results[$name] = array( 41 - 'error' => 'ERR-UNPARSEABLE', 42 - ); 43 - unset($commits[$name]); 44 - continue; 45 - } 46 - $commits[$name] = array( 47 - 'callsign' => $matches[1], 48 - 'commitIdentifier' => $matches[2], 49 - ); 50 - } 51 - 52 - if (!$commits) { 53 - return $results; 54 - } 55 - 56 - $callsigns = ipull($commits, 'callsign'); 57 - $callsigns = array_unique($callsigns); 58 - $repos = id(new PhabricatorRepositoryQuery()) 59 - ->setViewer($request->getUser()) 60 - ->withCallsigns($callsigns) 61 - ->execute(); 62 - $repos = mpull($repos, null, 'getCallsign'); 63 - 64 - foreach ($commits as $name => $info) { 65 - $repo = idx($repos, $info['callsign']); 66 - if (!$repo) { 67 - $results[$name] = $info + array( 68 - 'error' => 'ERR-UNKNOWN-REPOSITORY', 69 - ); 70 - unset($commits[$name]); 71 - continue; 72 - } 73 - $commits[$name] += array( 74 - 'repositoryPHID' => $repo->getPHID(), 75 - 'repositoryID' => $repo->getID(), 76 - ); 77 - } 78 - 79 - if (!$commits) { 80 - return $results; 81 - } 82 - 83 - // Execute a complicated query to figure out the primary commit information 84 - // for each referenced commit. 85 - $cdata = $this->queryCommitInformation($commits, $repos); 86 - 87 - // We've built the queries so that each row also has the identifier we used 88 - // to select it, which might be a git prefix rather than a full identifier. 89 - $ref_map = ipull($cdata, 'commitIdentifier', 'commitRef'); 90 - 91 - $cobjs = id(new PhabricatorRepositoryCommit())->loadAllFromArray($cdata); 92 - $cobjs = mgroup($cobjs, 'getRepositoryID', 'getCommitIdentifier'); 93 - foreach ($commits as $name => $commit) { 94 - 95 - // Expand short git names into full identifiers. For SVN this map is just 96 - // the identity. 97 - $full_identifier = idx($ref_map, $commit['commitIdentifier']); 98 - 99 - $repo_id = $commit['repositoryID']; 100 - unset($commits[$name]['repositoryID']); 101 - 102 - if (empty($full_identifier) || 103 - empty($cobjs[$commit['repositoryID']][$full_identifier])) { 104 - $results[$name] = $commit + array( 105 - 'error' => 'ERR-UNKNOWN-COMMIT', 106 - ); 107 - unset($commits[$name]); 108 - continue; 109 - } 110 - 111 - $cobj_arr = $cobjs[$commit['repositoryID']][$full_identifier]; 112 - $cobj = head($cobj_arr); 113 - 114 - $commits[$name] += array( 115 - 'epoch' => $cobj->getEpoch(), 116 - 'commitPHID' => $cobj->getPHID(), 117 - 'commitID' => $cobj->getID(), 118 - ); 119 - 120 - // Upgrade git short references into full commit identifiers. 121 - $identifier = $cobj->getCommitIdentifier(); 122 - $commits[$name]['commitIdentifier'] = $identifier; 123 - 124 - $callsign = $commits[$name]['callsign']; 125 - $uri = "/r{$callsign}{$identifier}"; 126 - $commits[$name]['uri'] = PhabricatorEnv::getProductionURI($uri); 127 - } 128 - 129 - if (!$commits) { 130 - return $results; 131 - } 132 - 133 - $commits = $this->addRepositoryCommitDataInformation($commits); 134 - $commits = $this->addDifferentialInformation($commits, $request); 135 - $commits = $this->addManiphestInformation($commits); 136 - 137 - foreach ($commits as $name => $commit) { 138 - $results[$name] = $commit; 139 - } 140 - 141 - return $results; 142 - } 143 - 144 - /** 145 - * Retrieve primary commit information for all referenced commits. 146 - */ 147 - private function queryCommitInformation(array $commits, array $repos) { 148 - assert_instances_of($repos, 'PhabricatorRepository'); 149 - $conn_r = id(new PhabricatorRepositoryCommit())->establishConnection('r'); 150 - $repos = mpull($repos, null, 'getID'); 151 - 152 - $groups = array(); 153 - foreach ($commits as $name => $commit) { 154 - $groups[$commit['repositoryID']][] = $commit['commitIdentifier']; 155 - } 156 - 157 - // NOTE: MySQL goes crazy and does a massive table scan if we build a more 158 - // sensible version of this query. Make sure the query plan is OK if you 159 - // attempt to reduce the craziness here. METANOTE: The addition of prefix 160 - // selection for Git further complicates matters. 161 - $query = array(); 162 - $commit_table = id(new PhabricatorRepositoryCommit())->getTableName(); 163 - 164 - foreach ($groups as $repository_id => $identifiers) { 165 - $vcs = $repos[$repository_id]->getVersionControlSystem(); 166 - $is_git = ($vcs == PhabricatorRepositoryType::REPOSITORY_TYPE_GIT); 167 - if ($is_git) { 168 - foreach ($identifiers as $identifier) { 169 - if (strlen($identifier) < 7) { 170 - // Don't bother with silly stuff like 'rX2', which will select 171 - // 1/16th of all commits. Note that with length 7 we'll still get 172 - // collisions in repositories at the tens-of-thousands-of-commits 173 - // scale. 174 - continue; 175 - } 176 - $query[] = qsprintf( 177 - $conn_r, 178 - 'SELECT %T.*, %s commitRef 179 - FROM %T WHERE repositoryID = %d 180 - AND commitIdentifier LIKE %>', 181 - $commit_table, 182 - $identifier, 183 - $commit_table, 184 - $repository_id, 185 - $identifier); 186 - } 187 - } else { 188 - $query[] = qsprintf( 189 - $conn_r, 190 - 'SELECT %T.*, commitIdentifier commitRef 191 - FROM %T WHERE repositoryID = %d 192 - AND commitIdentifier IN (%Ls)', 193 - $commit_table, 194 - $commit_table, 195 - $repository_id, 196 - $identifiers); 197 - } 198 - } 199 - 200 - return queryfx_all( 201 - $conn_r, 202 - '%Q', 203 - implode(' UNION ALL ', $query)); 204 - } 205 - 206 - /** 207 - * Enhance the commit list with RepositoryCommitData information. 208 - */ 209 - private function addRepositoryCommitDataInformation(array $commits) { 210 - $commit_ids = ipull($commits, 'commitID'); 211 - 212 - $data = id(new PhabricatorRepositoryCommitData())->loadAllWhere( 213 - 'commitID in (%Ld)', 214 - $commit_ids); 215 - $data = mpull($data, null, 'getCommitID'); 216 - 217 - foreach ($commits as $name => $commit) { 218 - if (isset($data[$commit['commitID']])) { 219 - $dobj = $data[$commit['commitID']]; 220 - $commits[$name] += array( 221 - 'commitMessage' => $dobj->getCommitMessage(), 222 - 'commitDetails' => $dobj->getCommitDetails(), 223 - ); 224 - } 225 - 226 - // Remove this information so we don't expose it via the API since 227 - // external services shouldn't be storing internal Commit IDs. 228 - unset($commits[$name]['commitID']); 229 - } 230 - 231 - return $commits; 232 - } 233 - 234 - /** 235 - * Enhance the commit list with Differential information. 236 - */ 237 - private function addDifferentialInformation( 238 - array $commits, 239 - ConduitAPIRequest $request) { 240 - 241 - $commit_phids = ipull($commits, 'commitPHID'); 242 - 243 - $revisions = id(new DifferentialRevisionQuery()) 244 - ->setViewer($request->getUser()) 245 - ->withCommitPHIDs($commit_phids) 246 - ->needCommitPHIDs(true) 247 - ->execute(); 248 - $rev_phid_commit_phids_map = mpull($revisions, 'getCommitPHIDs', 'getPHID'); 249 - $revisions = mpull($revisions, null, 'getPHID'); 250 - foreach ($rev_phid_commit_phids_map as $rev_phid => $commit_phids) { 251 - foreach ($commits as $name => $commit) { 252 - $commit_phid = $commit['commitPHID']; 253 - if (in_array($commit_phid, $commit_phids)) { 254 - $revision = $revisions[$rev_phid]; 255 - $commits[$name] += array( 256 - 'differentialRevisionID' => 'D'.$revision->getID(), 257 - 'differentialRevisionPHID' => $revision->getPHID(), 258 - ); 259 - } 260 - } 261 - } 262 - 263 - return $commits; 264 - } 265 - 266 - /** 267 - * Enhances the commits list with Maniphest information. 268 - */ 269 - private function addManiphestInformation(array $commits) { 270 - $task_type = DiffusionCommitHasTaskEdgeType::EDGECONST; 271 - 272 - $commit_phids = ipull($commits, 'commitPHID'); 273 - 274 - $edge_query = id(new PhabricatorEdgeQuery()) 275 - ->withSourcePHIDs($commit_phids) 276 - ->withEdgeTypes(array($task_type)); 277 - 278 - $edges = $edge_query->execute(); 279 - 280 - foreach ($commits as $name => $commit) { 281 - $task_phids = $edge_query->getDestinationPHIDs( 282 - array($commit['commitPHID']), 283 - array($task_type)); 284 - 285 - $commits[$name] += array( 286 - 'taskPHIDs' => $task_phids, 287 - ); 288 - } 289 - 290 - return $commits; 291 - } 292 - 293 - }
+1 -2
src/applications/diffusion/view/DiffusionView.php
··· 129 129 $summary = '') { 130 130 131 131 $commit_name = $repository->formatCommitName($commit); 132 - $callsign = $repository->getCallsign(); 133 132 134 133 if (strlen($summary)) { 135 134 $commit_name .= ': '.$summary; ··· 138 137 return phutil_tag( 139 138 'a', 140 139 array( 141 - 'href' => "/r{$callsign}{$commit}", 140 + 'href' => $repository->getCommitURI($commit), 142 141 ), 143 142 $commit_name); 144 143 }
-1
src/applications/repository/phid/PhabricatorRepositoryRepositoryPHIDType.php
··· 38 38 $repository = $objects[$phid]; 39 39 40 40 $monogram = $repository->getMonogram(); 41 - $callsign = $repository->getCallsign(); 42 41 $name = $repository->getName(); 43 42 $uri = $repository->getURI(); 44 43
+1 -1
src/applications/repository/worker/__tests__/PhabricatorChangeParserTestCase.php
··· 1186 1186 pht( 1187 1187 'No test entry for commit "%s" in repository "%s"!', 1188 1188 $commit_identifier, 1189 - $repository->getCallsign())); 1189 + $repository->getDisplayName())); 1190 1190 } 1191 1191 1192 1192 $changes = $this->parseCommit($repository, $commit);
+1 -2
src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php
··· 319 319 ->setDescription( 320 320 pht( 321 321 'Commit %s', 322 - 'r'.$this->repository->getCallsign(). 323 - $this->commit->getCommitIdentifier())); 322 + $this->commit->getMonogram())); 324 323 325 324 $parents = DiffusionQuery::callConduitWithDiffusionRequest( 326 325 $viewer,