1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-02 09:58:24 +01:00

Prevent "Differential Revision: ..." from counting as a mention in commit messages

Summary:
Ref T13290. Ref T13291. Now that a full URI is a "mention", the full URI in "Differential Revision: ..." also triggers a mention.

Stop it from doing that, since these mentions are silly/redundant/unintended.

The API here is also slightly odd; simplify it a little bit to get rid of doing "append" with "get + append + set".

Test Plan: Used `bin/repository reparse --publish` to republish commits with "Differential Revision: ..." and verified that the revision PHID was properly dropped from the mention list.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13291, T13290

Differential Revision: https://secure.phabricator.com/D20544
This commit is contained in:
epriestley 2019-05-22 14:04:15 -07:00
parent fa4dcaa3aa
commit 1eff4fdca3
5 changed files with 28 additions and 20 deletions

View file

@ -239,7 +239,7 @@ final class PhabricatorAuditEditor
$object); $object);
if ($request) { if ($request) {
$xactions[] = $request; $xactions[] = $request;
$this->setUnmentionablePHIDMap($request->getNewValue()); $this->addUnmentionablePHIDs($request->getNewValue());
} }
break; break;
default: default:
@ -360,7 +360,6 @@ final class PhabricatorAuditEditor
$flat_blocks = mpull($changes, 'getNewValue'); $flat_blocks = mpull($changes, 'getNewValue');
$huge_block = implode("\n\n", $flat_blocks); $huge_block = implode("\n\n", $flat_blocks);
$phid_map = array(); $phid_map = array();
$phid_map[] = $this->getUnmentionablePHIDMap();
$monograms = array(); $monograms = array();
$task_refs = id(new ManiphestCustomFieldStatusParser()) $task_refs = id(new ManiphestCustomFieldStatusParser())
@ -385,7 +384,6 @@ final class PhabricatorAuditEditor
->execute(); ->execute();
$phid_map[] = mpull($objects, 'getPHID', 'getPHID'); $phid_map[] = mpull($objects, 'getPHID', 'getPHID');
$reverts_refs = id(new DifferentialCustomFieldRevertsParser()) $reverts_refs = id(new DifferentialCustomFieldRevertsParser())
->parseCorpus($huge_block); ->parseCorpus($huge_block);
$reverts = array_mergev(ipull($reverts_refs, 'monograms')); $reverts = array_mergev(ipull($reverts_refs, 'monograms'));
@ -408,7 +406,7 @@ final class PhabricatorAuditEditor
} }
$phid_map = array_mergev($phid_map); $phid_map = array_mergev($phid_map);
$this->setUnmentionablePHIDMap($phid_map); $this->addUnmentionablePHIDs($phid_map);
return $result; return $result;
} }

View file

@ -846,13 +846,9 @@ final class DifferentialTransactionEditor
$revert_phids = array(); $revert_phids = array();
} }
// See PHI574. Respect any unmentionable PHIDs which were set on the $this->addUnmentionablePHIDs($task_phids);
// Editor by the caller. $this->addUnmentionablePHIDs($rev_phids);
$unmentionable_map = $this->getUnmentionablePHIDMap(); $this->addUnmentionablePHIDs($revert_phids);
$unmentionable_map += $task_phids;
$unmentionable_map += $rev_phids;
$unmentionable_map += $revert_phids;
$this->setUnmentionablePHIDMap($unmentionable_map);
$result = array(); $result = array();
foreach ($edges as $type => $specs) { foreach ($edges as $type => $specs) {

View file

@ -139,10 +139,7 @@ final class DiffusionUpdateObjectAfterCommitWorker
->setContentSource($content_source) ->setContentSource($content_source)
->setContinueOnNoEffect(true) ->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true) ->setContinueOnMissingFields(true)
->setUnmentionablePHIDMap( ->addUnmentionablePHIDs(array($commit_phid));
array(
$commit_phid => $commit_phid,
));
$editor->applyTransactions($task, $xactions); $editor->applyTransactions($task, $xactions);
} }

View file

@ -62,12 +62,25 @@ final class PhabricatorRepositoryCommitPublishWorker
$acting_phid = $this->getPublishAsPHID($commit); $acting_phid = $this->getPublishAsPHID($commit);
$content_source = $this->newContentSource(); $content_source = $this->newContentSource();
$revision = DiffusionCommitRevisionQuery::loadRevisionForCommit(
$viewer,
$commit);
// Prevent the commit from generating a mention of the associated
// revision, if one exists, so we don't double up because of the URI
// in the commit message.
$unmentionable_phids = array();
if ($revision) {
$unmentionable_phids[] = $revision->getPHID();
}
$editor = $commit->getApplicationTransactionEditor() $editor = $commit->getApplicationTransactionEditor()
->setActor($viewer) ->setActor($viewer)
->setActingAsPHID($acting_phid) ->setActingAsPHID($acting_phid)
->setContinueOnNoEffect(true) ->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true) ->setContinueOnMissingFields(true)
->setContentSource($content_source); ->setContentSource($content_source)
->addUnmentionablePHIDs($unmentionable_phids);
try { try {
$raw_patch = $this->loadRawPatchText($repository, $commit); $raw_patch = $this->loadRawPatchText($repository, $commit);

View file

@ -260,12 +260,14 @@ abstract class PhabricatorApplicationTransactionEditor
return $this->isHeraldEditor; return $this->isHeraldEditor;
} }
public function setUnmentionablePHIDMap(array $map) { public function addUnmentionablePHIDs(array $phids) {
$this->unmentionablePHIDMap = $map; foreach ($phids as $phid) {
$this->unmentionablePHIDMap[$phid] = true;
}
return $this; return $this;
} }
public function getUnmentionablePHIDMap() { private function getUnmentionablePHIDMap() {
return $this->unmentionablePHIDMap; return $this->unmentionablePHIDMap;
} }
@ -2090,12 +2092,14 @@ abstract class PhabricatorApplicationTransactionEditor
->withPHIDs($mentioned_phids) ->withPHIDs($mentioned_phids)
->execute(); ->execute();
$unmentionable_map = $this->getUnmentionablePHIDMap();
$mentionable_phids = array(); $mentionable_phids = array();
if ($this->shouldEnableMentions($object, $xactions)) { if ($this->shouldEnableMentions($object, $xactions)) {
foreach ($mentioned_objects as $mentioned_object) { foreach ($mentioned_objects as $mentioned_object) {
if ($mentioned_object instanceof PhabricatorMentionableInterface) { if ($mentioned_object instanceof PhabricatorMentionableInterface) {
$mentioned_phid = $mentioned_object->getPHID(); $mentioned_phid = $mentioned_object->getPHID();
if (idx($this->getUnmentionablePHIDMap(), $mentioned_phid)) { if (isset($unmentionable_map[$mentioned_phid])) {
continue; continue;
} }
// don't let objects mention themselves // don't let objects mention themselves