1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-03-27 03:30:16 +01:00

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
This commit is contained in:
epriestley 2013-05-06 18:05:33 -07:00
parent 5263c2d0f3
commit 30b15e094c
2 changed files with 35 additions and 2 deletions

View file

@ -200,15 +200,27 @@ abstract class DifferentialFreeformFieldSpecification
$message = $this->renderValueForCommitMessage($is_edit = false);
$commits = self::findRevertedCommits($message);
$user = id(new PhabricatorUser())->loadOneWhere(
'phid = %s',
$data->getCommitDetail('authorPHID'));
if (!$user) {
// TODO: Maybe after grey users, we should find a way to proceed even
// if we don't know who the author is.
return;
}
$commit_names = self::findRevertedCommits($message);
if ($commit_names) {
$reverts = id(new DiffusionCommitQuery())
->setViewer($user)
->withIdentifiers($commit_names)
->withDefaultRepository($repository)
->execute();
foreach ($reverts as $revert) {
// TODO: Do interesting things here.
}
}
$tasks_statuses = $this->findMentionedTasks($message);
if (!$tasks_statuses) {
return;

View file

@ -5,6 +5,7 @@ final class DiffusionCommitQuery
private $identifiers;
private $phids;
private $defaultRepository;
/**
* Load commits by partial or full identifiers, e.g. "rXab82393", "rX1234",
@ -17,6 +18,20 @@ final class DiffusionCommitQuery
return $this;
}
/**
* If a default repository is provided, ambiguous commit identifiers will
* be assumed to belong to the default repository.
*
* For example, "r123" appearing in a commit message in repository X is
* likely to be unambiguously "rX123". Normally the reference would be
* considered ambiguous, but if you provide a default repository it will
* be correctly resolved.
*/
public function withDefaultRepository(PhabricatorRepository $repository) {
$this->defaultRepository = $repository;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
@ -75,6 +90,12 @@ final class DiffusionCommitQuery
$repo = nonempty($matches[1], null);
$identifier = nonempty($matches[2], null);
if ($repo === null) {
if ($this->defaultRepository) {
$repo = $this->defaultRepository->getCallsign();
}
}
if ($repo === null) {
if (strlen($identifier) < $min_unqualified) {
continue;