mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-14 19:02:41 +01:00
ab117c2baf
Summary: Fixes T4601. The "Differential Revision" field needs to be present in the "editable" version of the message so that `--verbatim` works correctly. Some day all of this might get rewritten to be a little easier to follow, maybe, but keep things working properly for now. Test Plan: Used `arc diff`, `arc diff --edit`, `arc diff --verbatim` Reviewers: btrahan Reviewed By: btrahan Subscribers: aran, epriestley Maniphest Tasks: T4601 Differential Revision: https://secure.phabricator.com/D8526
74 lines
1.7 KiB
PHP
74 lines
1.7 KiB
PHP
<?php
|
|
|
|
final class DifferentialRevisionIDField
|
|
extends DifferentialCustomField {
|
|
|
|
private $revisionID;
|
|
|
|
public function getFieldKey() {
|
|
return 'differential:revision-id';
|
|
}
|
|
|
|
public function getFieldKeyForConduit() {
|
|
return 'revisionID';
|
|
}
|
|
|
|
public function getFieldName() {
|
|
return pht('Differential Revision');
|
|
}
|
|
|
|
public function getFieldDescription() {
|
|
return pht(
|
|
'Ties commits to revisions and provides a permananent link between '.
|
|
'them.');
|
|
}
|
|
|
|
public function canDisableField() {
|
|
return false;
|
|
}
|
|
|
|
public function shouldAppearInCommitMessage() {
|
|
return true;
|
|
}
|
|
|
|
public function parseValueFromCommitMessage($value) {
|
|
return self::parseRevisionIDFromURI($value);
|
|
}
|
|
|
|
public function renderCommitMessageValue(array $handles) {
|
|
$id = coalesce($this->revisionID, $this->getObject()->getID());
|
|
if (!$id) {
|
|
return null;
|
|
}
|
|
return PhabricatorEnv::getProductionURI('/D'.$id);
|
|
}
|
|
|
|
public function readValueFromCommitMessage($value) {
|
|
$this->revisionID = $value;
|
|
}
|
|
|
|
private static function parseRevisionIDFromURI($uri) {
|
|
$path = id(new PhutilURI($uri))->getPath();
|
|
|
|
$matches = null;
|
|
if (preg_match('#^/D(\d+)$#', $path, $matches)) {
|
|
$id = (int)$matches[1];
|
|
// Make sure the URI is the same as our URI. Basically, we want to ignore
|
|
// commits from other Phabricator installs.
|
|
if ($uri == PhabricatorEnv::getProductionURI('/D'.$id)) {
|
|
return $id;
|
|
}
|
|
|
|
$allowed_uris = PhabricatorEnv::getAllowedURIs('/D'.$id);
|
|
|
|
foreach ($allowed_uris as $allowed_uri) {
|
|
if ($uri == $allowed_uri) {
|
|
return $id;
|
|
}
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
}
|