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

Load commits affected by revert language in Diffusion message parser

Summary:
Ref T1751. This still doesn't do anything very interesting, but loads the acutal Commit objects that a commit message claims to revert.

The only tricky thing here is that we need to interpret "reverts rnnn" or "reverts nnn" in an SVN repository as "reverts rXnnn", where "X" is the current repository. This adds a method to do allow `DiffusionCommitQuery` to do that.

Test Plan:
Used `reparse.php --message` to reparse several commits with revert language and verify they loaded the correct affected commits.

In an SVN repository, created a commit with ambiguous revert language ("reverts n", "reverts rn", "reverts n, n") and verified it identified the affected commits correctly despite ambiguity.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1751

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

+35 -2
+14 -2
src/applications/differential/field/specification/DifferentialFreeformFieldSpecification.php
··· 200 200 201 201 $message = $this->renderValueForCommitMessage($is_edit = false); 202 202 203 - $commits = self::findRevertedCommits($message); 204 - 205 203 $user = id(new PhabricatorUser())->loadOneWhere( 206 204 'phid = %s', 207 205 $data->getCommitDetail('authorPHID')); 208 206 if (!$user) { 207 + // TODO: Maybe after grey users, we should find a way to proceed even 208 + // if we don't know who the author is. 209 209 return; 210 + } 211 + 212 + $commit_names = self::findRevertedCommits($message); 213 + if ($commit_names) { 214 + $reverts = id(new DiffusionCommitQuery()) 215 + ->setViewer($user) 216 + ->withIdentifiers($commit_names) 217 + ->withDefaultRepository($repository) 218 + ->execute(); 219 + foreach ($reverts as $revert) { 220 + // TODO: Do interesting things here. 221 + } 210 222 } 211 223 212 224 $tasks_statuses = $this->findMentionedTasks($message);
+21
src/applications/diffusion/query/DiffusionCommitQuery.php
··· 5 5 6 6 private $identifiers; 7 7 private $phids; 8 + private $defaultRepository; 8 9 9 10 /** 10 11 * Load commits by partial or full identifiers, e.g. "rXab82393", "rX1234", ··· 14 15 */ 15 16 public function withIdentifiers(array $identifiers) { 16 17 $this->identifiers = $identifiers; 18 + return $this; 19 + } 20 + 21 + /** 22 + * If a default repository is provided, ambiguous commit identifiers will 23 + * be assumed to belong to the default repository. 24 + * 25 + * For example, "r123" appearing in a commit message in repository X is 26 + * likely to be unambiguously "rX123". Normally the reference would be 27 + * considered ambiguous, but if you provide a default repository it will 28 + * be correctly resolved. 29 + */ 30 + public function withDefaultRepository(PhabricatorRepository $repository) { 31 + $this->defaultRepository = $repository; 17 32 return $this; 18 33 } 19 34 ··· 74 89 preg_match('/^(?:r([A-Z]+))?(.*)$/', $identifier, $matches); 75 90 $repo = nonempty($matches[1], null); 76 91 $identifier = nonempty($matches[2], null); 92 + 93 + if ($repo === null) { 94 + if ($this->defaultRepository) { 95 + $repo = $this->defaultRepository->getCallsign(); 96 + } 97 + } 77 98 78 99 if ($repo === null) { 79 100 if (strlen($identifier) < $min_unqualified) {