2011-08-10 20:29:08 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-01-17 01:54:05 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-08-10 20:29:08 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2011-08-10 22:46:01 +02:00
|
|
|
/**
|
|
|
|
* Describes and implements the behavior for a custom field on Differential
|
|
|
|
* revisions. Along with other configuration, you can extend this class to add
|
|
|
|
* custom fields to Differential revisions and commit messages.
|
|
|
|
*
|
|
|
|
* Generally, you should implement all methods from the storage task and then
|
|
|
|
* the methods from one or more interface tasks.
|
|
|
|
*
|
|
|
|
* @task storage Field Storage
|
|
|
|
* @task edit Extending the Revision Edit Interface
|
|
|
|
* @task view Extending the Revision View Interface
|
2012-02-20 14:38:21 +01:00
|
|
|
* @task list Extending the Revision List Interface
|
2011-08-11 00:48:44 +02:00
|
|
|
* @task conduit Extending the Conduit View Interface
|
2011-08-15 03:52:09 +02:00
|
|
|
* @task commit Extending Commit Messages
|
2011-08-14 22:55:30 +02:00
|
|
|
* @task load Loading Additional Data
|
2011-08-14 20:29:56 +02:00
|
|
|
* @task context Contextual Data
|
2011-08-10 22:46:01 +02:00
|
|
|
*/
|
2011-08-10 20:29:08 +02:00
|
|
|
abstract class DifferentialFieldSpecification {
|
|
|
|
|
2011-08-14 20:29:56 +02:00
|
|
|
private $revision;
|
|
|
|
private $diff;
|
2011-08-14 21:33:54 +02:00
|
|
|
private $handles;
|
2011-08-14 22:55:30 +02:00
|
|
|
private $diffProperties;
|
2011-08-14 23:28:08 +02:00
|
|
|
private $user;
|
2011-08-14 20:29:56 +02:00
|
|
|
|
2011-08-10 22:46:01 +02:00
|
|
|
|
|
|
|
/* -( Storage )------------------------------------------------------------ */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a unique string used to key storage of this field's value, like
|
2011-08-14 20:29:56 +02:00
|
|
|
* "mycompany.fieldname" or similar. You can return null (the default) to
|
|
|
|
* indicate that this field does not use any storage. This is appropriate for
|
|
|
|
* display fields, like @{class:DifferentialLinesFieldSpecification}. If you
|
|
|
|
* implement this, you must also implement @{method:getValueForStorage} and
|
|
|
|
* @{method:setValueFromStorage}.
|
2011-08-10 22:46:01 +02:00
|
|
|
*
|
2011-08-14 20:29:56 +02:00
|
|
|
* @return string|null Unique key which identifies this field in auxiliary
|
|
|
|
* field storage. Maximum length is 32. Alternatively,
|
|
|
|
* null (default) to indicate that this field does not
|
|
|
|
* use auxiliary field storage.
|
|
|
|
* @task storage
|
2011-08-10 22:46:01 +02:00
|
|
|
*/
|
2011-08-14 20:29:56 +02:00
|
|
|
public function getStorageKey() {
|
|
|
|
return null;
|
|
|
|
}
|
2011-08-10 22:46:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a serialized representation of the field value, appropriate for
|
2011-08-14 20:29:56 +02:00
|
|
|
* storing in auxiliary field storage. You must implement this method if
|
|
|
|
* you implement @{method:getStorageKey}.
|
2011-08-10 22:46:01 +02:00
|
|
|
*
|
|
|
|
* @return string Serialized field value.
|
2011-08-14 20:29:56 +02:00
|
|
|
* @task storage
|
2011-08-10 22:46:01 +02:00
|
|
|
*/
|
2011-08-14 20:29:56 +02:00
|
|
|
public function getValueForStorage() {
|
|
|
|
throw new DifferentialFieldSpecificationIncompleteException($this);
|
|
|
|
}
|
2011-08-10 22:46:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the field's value given a serialized storage value. This is called
|
|
|
|
* when the field is loaded; if no data is available, the value will be
|
2011-08-14 20:29:56 +02:00
|
|
|
* null. You must implement this method if you implement
|
|
|
|
* @{method:getStorageKey}.
|
2011-08-10 22:46:01 +02:00
|
|
|
*
|
|
|
|
* @param string|null Serialized field representation (from
|
2011-08-14 20:29:56 +02:00
|
|
|
* @{method:getValueForStorage}) or null if no value has
|
|
|
|
* ever been stored.
|
2011-08-10 22:46:01 +02:00
|
|
|
* @return this
|
2011-08-14 20:29:56 +02:00
|
|
|
* @task storage
|
2011-08-10 22:46:01 +02:00
|
|
|
*/
|
2011-08-14 20:29:56 +02:00
|
|
|
public function setValueFromStorage($value) {
|
|
|
|
throw new DifferentialFieldSpecificationIncompleteException($this);
|
|
|
|
}
|
2011-08-10 22:46:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* -( Extending the Revision Edit Interface )------------------------------ */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-08-14 20:29:56 +02:00
|
|
|
* Determine if this field should appear on the "Edit Revision" interface. If
|
|
|
|
* you return true from this method, you must implement
|
|
|
|
* @{method:setValueFromRequest}, @{method:renderEditControl} and
|
|
|
|
* @{method:validateField}.
|
|
|
|
*
|
|
|
|
* For a concrete example of a field which implements an edit interface, see
|
|
|
|
* @{class:DifferentialRevertPlanFieldSpecification}.
|
|
|
|
*
|
|
|
|
* @return bool True to indicate that this field implements an edit interface.
|
2011-08-10 22:46:01 +02:00
|
|
|
* @task edit
|
|
|
|
*/
|
|
|
|
public function shouldAppearOnEdit() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-08-14 20:29:56 +02:00
|
|
|
* Set the field's value from an HTTP request. Generally, you should read
|
|
|
|
* the value of some field name you emitted in @{method:renderEditControl}
|
|
|
|
* and save it into the object, e.g.:
|
|
|
|
*
|
|
|
|
* $this->value = $request->getStr('my-custom-field');
|
|
|
|
*
|
|
|
|
* If you have some particularly complicated field, you may need to read
|
|
|
|
* more data; this is why you have access to the entire request.
|
|
|
|
*
|
|
|
|
* You must implement this if you implement @{method:shouldAppearOnEdit}.
|
|
|
|
*
|
|
|
|
* You should not perform field validation here; instead, you should implement
|
|
|
|
* @{method:validateField}.
|
|
|
|
*
|
|
|
|
* @param AphrontRequest HTTP request representing a user submitting a form
|
|
|
|
* with this field in it.
|
|
|
|
* @return this
|
2011-08-10 22:46:01 +02:00
|
|
|
* @task edit
|
|
|
|
*/
|
|
|
|
public function setValueFromRequest(AphrontRequest $request) {
|
|
|
|
throw new DifferentialFieldSpecificationIncompleteException($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-08-14 20:29:56 +02:00
|
|
|
* Build a renderable object (generally, some @{class:AphrontFormControl})
|
|
|
|
* which can be appended to a @{class:AphrontFormView} and represents the
|
|
|
|
* interface the user sees on the "Edit Revision" screen when interacting
|
|
|
|
* with this field.
|
|
|
|
*
|
|
|
|
* For example:
|
|
|
|
*
|
|
|
|
* return id(new AphrontFormTextControl())
|
|
|
|
* ->setLabel('Custom Field')
|
|
|
|
* ->setName('my-custom-key')
|
|
|
|
* ->setValue($this->value);
|
|
|
|
*
|
|
|
|
* You must implement this if you implement @{method:shouldAppearOnEdit}.
|
|
|
|
*
|
|
|
|
* @return AphrontView|string Something renderable.
|
2011-08-10 22:46:01 +02:00
|
|
|
* @task edit
|
|
|
|
*/
|
|
|
|
public function renderEditControl() {
|
|
|
|
throw new DifferentialFieldSpecificationIncompleteException($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-08-14 20:29:56 +02:00
|
|
|
* This method will be called after @{method:setValueFromRequest} but before
|
|
|
|
* the field is saved. It gives you an opportunity to inspect the field value
|
|
|
|
* and throw a @{class:DifferentialFieldValidationException} if there is a
|
|
|
|
* problem with the value the user has provided (for example, the value the
|
2011-12-02 00:43:25 +01:00
|
|
|
* user entered is not correctly formatted). This method is also called after
|
|
|
|
* @{method:setValueFromParsedCommitMessage} before the revision is saved.
|
2011-08-14 20:29:56 +02:00
|
|
|
*
|
|
|
|
* By default, fields are not validated.
|
|
|
|
*
|
|
|
|
* @return void
|
2011-08-10 22:46:01 +02:00
|
|
|
* @task edit
|
|
|
|
*/
|
|
|
|
public function validateField() {
|
2011-08-14 20:29:56 +02:00
|
|
|
return;
|
2011-08-10 22:46:01 +02:00
|
|
|
}
|
|
|
|
|
2011-08-14 22:55:30 +02:00
|
|
|
/**
|
2011-08-15 03:52:09 +02:00
|
|
|
* Hook for applying revision changes via the editor. Normally, you should
|
|
|
|
* not implement this, but a number of builtin fields use the revision object
|
|
|
|
* itself as storage. If you need to do something similar for whatever reason,
|
|
|
|
* this method gives you an opportunity to interact with the editor or
|
|
|
|
* revision before changes are saved (for example, you can write the field's
|
|
|
|
* value into some property of the revision).
|
|
|
|
*
|
|
|
|
* @param DifferentialRevisionEditor Active editor which is applying changes
|
|
|
|
* to the revision.
|
|
|
|
* @return void
|
2011-08-14 22:55:30 +02:00
|
|
|
* @task edit
|
|
|
|
*/
|
|
|
|
public function willWriteRevision(DifferentialRevisionEditor $editor) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-08-15 03:52:09 +02:00
|
|
|
* Hook after an edit operation has completed. This allows you to update
|
|
|
|
* link tables or do other write operations which should happen after the
|
|
|
|
* revision is saved. Normally you don't need to implement this.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param DifferentialRevisionEditor Active editor which has just applied
|
|
|
|
* changes to the revision.
|
|
|
|
* @return void
|
2011-08-14 22:55:30 +02:00
|
|
|
* @task edit
|
|
|
|
*/
|
|
|
|
public function didWriteRevision(DifferentialRevisionEditor $editor) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-10 22:46:01 +02:00
|
|
|
|
|
|
|
/* -( Extending the Revision View Interface )------------------------------ */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-08-14 22:55:30 +02:00
|
|
|
* Determine if this field should appear on the revision detail view
|
|
|
|
* interface. One use of this interface is to add purely informational
|
|
|
|
* fields to the revision view, without any sort of backing storage.
|
|
|
|
*
|
|
|
|
* If you return true from this method, you must implement the methods
|
|
|
|
* @{method:renderLabelForRevisionView} and
|
|
|
|
* @{method:renderValueForRevisionView}.
|
|
|
|
*
|
|
|
|
* @return bool True if this field should appear when viewing a revision.
|
2011-08-10 22:46:01 +02:00
|
|
|
* @task view
|
|
|
|
*/
|
|
|
|
public function shouldAppearOnRevisionView() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-08-14 22:55:30 +02:00
|
|
|
* Return a string field label which will appear in the revision detail
|
|
|
|
* table.
|
|
|
|
*
|
|
|
|
* You must implement this method if you return true from
|
|
|
|
* @{method:shouldAppearOnRevisionView}.
|
|
|
|
*
|
|
|
|
* @return string Label for field in revision detail view.
|
2011-08-10 22:46:01 +02:00
|
|
|
* @task view
|
|
|
|
*/
|
|
|
|
public function renderLabelForRevisionView() {
|
|
|
|
throw new DifferentialFieldSpecificationIncompleteException($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-08-14 22:55:30 +02:00
|
|
|
* Return a markup block representing the field for the revision detail
|
|
|
|
* view. Note that you can return null to suppress display (for instance,
|
|
|
|
* if the field shows related objects of some type and the revision doesn't
|
|
|
|
* have any related objects).
|
|
|
|
*
|
|
|
|
* You must implement this method if you return true from
|
|
|
|
* @{method:shouldAppearOnRevisionView}.
|
|
|
|
*
|
|
|
|
* @return string|null Display markup for field value, or null to suppress
|
|
|
|
* field rendering.
|
2011-08-10 22:46:01 +02:00
|
|
|
* @task view
|
|
|
|
*/
|
|
|
|
public function renderValueForRevisionView() {
|
|
|
|
throw new DifferentialFieldSpecificationIncompleteException($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-16 23:38:16 +02:00
|
|
|
/**
|
|
|
|
* Load users, their current statuses and return a markup with links to the
|
|
|
|
* user profiles and information about their current status.
|
|
|
|
*
|
|
|
|
* @return string Display markup.
|
|
|
|
* @task view
|
|
|
|
*/
|
|
|
|
public function renderUserList(array $user_phids) {
|
|
|
|
if (!$user_phids) {
|
|
|
|
return '<em>None</em>';
|
|
|
|
}
|
|
|
|
|
2012-05-17 03:42:06 +02:00
|
|
|
$statuses = id(new PhabricatorUserStatus())->loadCurrentStatuses(
|
2012-05-16 23:38:16 +02:00
|
|
|
$user_phids);
|
|
|
|
|
|
|
|
$links = array();
|
|
|
|
foreach ($user_phids as $user_phid) {
|
|
|
|
$handle = $this->getHandle($user_phid);
|
|
|
|
$extra = null;
|
|
|
|
$status = idx($statuses, $handle->getPHID());
|
|
|
|
if ($handle->isDisabled()) {
|
|
|
|
$extra = ' <strong>(disabled)</strong>';
|
|
|
|
} else if ($status) {
|
|
|
|
$until = phabricator_date($status->getDateTo(), $this->getUser());
|
|
|
|
if ($status->getStatus() == PhabricatorUserStatus::STATUS_SPORADIC) {
|
|
|
|
$extra = ' <strong title="until '.$until.'">(sporadic)</strong>';
|
|
|
|
} else {
|
|
|
|
$extra = ' <strong title="until '.$until.'">(away)</strong>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$links[] = $handle->renderLink().$extra;
|
|
|
|
}
|
|
|
|
|
|
|
|
return implode(', ', $links);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-27 07:16:46 +02:00
|
|
|
/**
|
|
|
|
* Return a markup block representing a warning to display with the comment
|
|
|
|
* box when preparing to accept a diff. A return value of null indicates no
|
|
|
|
* warning box should be displayed for this field.
|
|
|
|
*
|
|
|
|
* @return string|null Display markup for warning box, or null for no warning
|
|
|
|
*/
|
|
|
|
public function renderWarningBoxForRevisionAccept() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-20 14:38:21 +01:00
|
|
|
/* -( Extending the Revision List Interface )------------------------------ */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if this field should appear in the table on the revision list
|
|
|
|
* interface.
|
|
|
|
*
|
|
|
|
* @return bool True if this field should appear in the table.
|
|
|
|
*
|
|
|
|
* @task list
|
|
|
|
*/
|
|
|
|
public function shouldAppearOnRevisionList() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a column header for revision list tables.
|
|
|
|
*
|
|
|
|
* @return string Column header.
|
|
|
|
*
|
|
|
|
* @task list
|
|
|
|
*/
|
|
|
|
public function renderHeaderForRevisionList() {
|
|
|
|
throw new DifferentialFieldSpecificationIncompleteException($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Optionally, return a column class for revision list tables.
|
|
|
|
*
|
|
|
|
* @return string CSS class for table cells.
|
|
|
|
*
|
|
|
|
* @task list
|
|
|
|
*/
|
|
|
|
public function getColumnClassForRevisionList() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a table cell value for revision list tables.
|
|
|
|
*
|
|
|
|
* @param DifferentialRevision The revision to render a value for.
|
|
|
|
* @return string Table cell value.
|
|
|
|
*
|
|
|
|
* @task list
|
|
|
|
*/
|
|
|
|
public function renderValueForRevisionList(DifferentialRevision $revision) {
|
|
|
|
throw new DifferentialFieldSpecificationIncompleteException($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-11 00:48:44 +02:00
|
|
|
/* -( Extending the Conduit Interface )------------------------------------ */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @task conduit
|
|
|
|
*/
|
|
|
|
public function shouldAppearOnConduitView() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @task conduit
|
|
|
|
*/
|
|
|
|
public function getValueForConduit() {
|
|
|
|
throw new DifferentialFieldSpecificationIncompleteException($this);
|
|
|
|
}
|
|
|
|
|
2011-08-14 20:29:56 +02:00
|
|
|
/**
|
|
|
|
* @task conduit
|
|
|
|
*/
|
|
|
|
public function getKeyForConduit() {
|
|
|
|
$key = $this->getStorageKey();
|
|
|
|
if ($key === null) {
|
|
|
|
throw new DifferentialFieldSpecificationIncompleteException($this);
|
|
|
|
}
|
|
|
|
return $key;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-15 03:52:09 +02:00
|
|
|
/* -( Extending Commit Messages )------------------------------------------ */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if this field should appear in commit messages. You should return
|
|
|
|
* true if this field participates in any part of the commit message workflow,
|
|
|
|
* even if it is not rendered by default.
|
|
|
|
*
|
|
|
|
* If you implement this method, you must implement
|
|
|
|
* @{method:getCommitMessageKey} and
|
|
|
|
* @{method:setValueFromParsedCommitMessage}.
|
|
|
|
*
|
|
|
|
* @return bool True if this field appears in commit messages in any capacity.
|
|
|
|
* @task commit
|
|
|
|
*/
|
|
|
|
public function shouldAppearOnCommitMessage() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Key which identifies this field in parsed commit messages. Commit messages
|
|
|
|
* exist in two forms: raw textual commit messages and parsed dictionaries of
|
|
|
|
* fields. This method must return a unique string which identifies this field
|
|
|
|
* in dictionaries. Principally, this dictionary is shipped to and from arc
|
|
|
|
* over Conduit. Keys should be appropriate property names, like "testPlan"
|
|
|
|
* (not "Test Plan") and must be globally unique.
|
|
|
|
*
|
|
|
|
* You must implement this method if you return true from
|
|
|
|
* @{method:shouldAppearOnCommitMessage}.
|
|
|
|
*
|
|
|
|
* @return string Key which identifies the field in dictionaries.
|
|
|
|
* @task commit
|
|
|
|
*/
|
|
|
|
public function getCommitMessageKey() {
|
|
|
|
throw new DifferentialFieldSpecificationIncompleteException($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set this field's value from a value in a parsed commit message dictionary.
|
|
|
|
* Afterward, this field will go through the normal write workflows and the
|
|
|
|
* change will be permanently stored via either the storage mechanisms (if
|
|
|
|
* your field implements them), revision write hooks (if your field implements
|
|
|
|
* them) or discarded (if your field implements neither, e.g. is just a
|
|
|
|
* display field).
|
|
|
|
*
|
Drive Differential commit message parsing through extensible fields
Summary:
I think this is the last major step -- use the fields to parse commit messages,
not a hard-coded list of stuff. This adds two primary methods to fields, one to
get all the labels they'll parse (so we can do "CC" and "CCs" and treat them as
the same field) and one to parse the string into a canonical representation
(e.g., lookup reviewers and such).
You'll need to impelement the one block of task-specific stuff I removed in
Facebook's task field:
list($pre_comment) = split(' -- ', $data);
$data = array_filter(preg_split('/[^\d]+/', $pre_comment));
foreach ($data as $k => $v) {
$data[$k] = (int)$v;
}
$data = array_unique($data);
break;
Otherwise I think this is clean.
Test Plan:
- Called the conduit method with various commit messages, parsed fields/errors
seemed correct.
- "arc diff"'d this diff onto localhost, then updated it.
- "arc amend"'d this diff.
Reviewers: jungejason, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason, epriestley
Differential Revision: 829
2011-08-18 21:08:18 +02:00
|
|
|
* The value you receive will either be null or something you originally
|
|
|
|
* returned from @{method:parseValueFromCommitMessage}.
|
|
|
|
*
|
2011-08-15 03:52:09 +02:00
|
|
|
* You must implement this method if you return true from
|
|
|
|
* @{method:shouldAppearOnCommitMessage}.
|
|
|
|
*
|
|
|
|
* @param mixed Field value from a parsed commit message dictionary.
|
|
|
|
* @return this
|
|
|
|
* @task commit
|
|
|
|
*/
|
|
|
|
public function setValueFromParsedCommitMessage($value) {
|
|
|
|
throw new DifferentialFieldSpecificationIncompleteException($this);
|
|
|
|
}
|
|
|
|
|
Drive commit message rendering from field specifications
Summary:
When rendering commit messages, drive all the logic through field specification
classes instead of the hard-coded DifferentialCommitMessageData class. This
removes DifferentialCommitMessageData and support classes.
Note that this effectively reverts D546, and will cause a minor break for
Facebook (Task IDs will no longer render in commit messages generated by "arc
amend", and will not be editable via "arc diff --edit"). This can be resolved by
implementing the feature as a custom field. While I've been able to preserve the
task ID functionality elsewhere, I felt this implementation was too complex to
reasonably leave hooks for, and the break is pretty minor.
Test Plan:
- Made numerous calls to differential.getcommitmessage across many diffs in
various states, with and without 'edit' and with and without various field
overrides.
- General behavior seems correct (messages look accurate, and have the
expected information). Special fields like "Reviewed By" and "git-svn-id" seem
to work correctly.
- Edit behavior seems correct (edit mode shows all editable fields, hides
fields like "Reviewed By").
- Field overwrite behavior seems correct (overwritable fields show the correct
values when overwritten, ignore provided values otherwise).
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: aran, jungejason
Differential Revision: 814
2011-08-16 06:06:58 +02:00
|
|
|
/**
|
|
|
|
* In revision control systems which read revision information from the
|
|
|
|
* working copy, the user may edit the commit message outside of invoking
|
|
|
|
* "arc diff --edit". When they do this, only some fields (those fields which
|
|
|
|
* can not be edited by other users) are safe to overwrite. For instance, it
|
|
|
|
* is fine to overwrite "Summary" because no one else can edit it, but not
|
|
|
|
* to overwrite "Reviewers" because reviewers may have been added or removed
|
|
|
|
* via the web interface.
|
|
|
|
*
|
|
|
|
* If a field is safe to overwrite when edited in a working copy commit
|
|
|
|
* message, return true. If the authoritative value should always be used,
|
|
|
|
* return false. By default, fields can not be overwritten.
|
|
|
|
*
|
Allow "Differential Revision ID" field appear on create/edit messages
Summary:
- In practice, 'edit' has two modes, 'create' and 'edit'. These seem like they should map to "create a revision" and "update a revision", but they are completely different.
- We use the "create" mode:
- When creating a message from the working copy.
- When creating a message from a file.
- When creating a message from a commit.
- When creating a message from a user template.
- When creating a message from an "--edit"!
- We use the "edit" mode:
- ONLY when updating a revision with `arc diff --verbatim`.
- The only difference is in which fields may be overwritten. Under "create", all fields may be overwritten. Under "edit", only safe fields may be overwritten.
- The "Differential Revision" field currently does not render in either edit mode. This is wrong. Even though it can not be updated in the "edit" mode, it should still render in both modes. This is the only material change this revision makes.
- Without this change, when we "create" a new message from a working copy and the working copy has a "Differential Revision" field, we incorrectly discard it.
- The only field which does not render on edit modes now is "Reviewed by" (not "Reviewers"), which is correct, since we do not read the value.
Test Plan: Ran "arc diff" to create/update revisions. Ran "arc diff --verbatim" to create/update revisions with implicit edits (with D2411). Ran "arc diff --edit" to update revisions with explicit edits.
Reviewers: jungejason, btrahan
Reviewed by: jungejason
CC: vrana, aran
Differential Revision: https://secure.phabricator.com/D2412
2012-05-07 16:35:56 +02:00
|
|
|
* arc will only attempt to overwrite field values if run with "--verbatim".
|
|
|
|
*
|
Drive commit message rendering from field specifications
Summary:
When rendering commit messages, drive all the logic through field specification
classes instead of the hard-coded DifferentialCommitMessageData class. This
removes DifferentialCommitMessageData and support classes.
Note that this effectively reverts D546, and will cause a minor break for
Facebook (Task IDs will no longer render in commit messages generated by "arc
amend", and will not be editable via "arc diff --edit"). This can be resolved by
implementing the feature as a custom field. While I've been able to preserve the
task ID functionality elsewhere, I felt this implementation was too complex to
reasonably leave hooks for, and the break is pretty minor.
Test Plan:
- Made numerous calls to differential.getcommitmessage across many diffs in
various states, with and without 'edit' and with and without various field
overrides.
- General behavior seems correct (messages look accurate, and have the
expected information). Special fields like "Reviewed By" and "git-svn-id" seem
to work correctly.
- Edit behavior seems correct (edit mode shows all editable fields, hides
fields like "Reviewed By").
- Field overwrite behavior seems correct (overwritable fields show the correct
values when overwritten, ignore provided values otherwise).
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: aran, jungejason
Differential Revision: 814
2011-08-16 06:06:58 +02:00
|
|
|
* @return bool True to indicate the field is save to overwrite.
|
|
|
|
* @task commit
|
|
|
|
*/
|
|
|
|
public function shouldOverwriteWhenCommitMessageIsEdited() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if this field should be suggested to the user during
|
|
|
|
* "arc diff --edit". Basicially, return true if the field is something the
|
|
|
|
* user might want to fill out (like "Summary"), and false if it's a
|
|
|
|
* system/display/readonly field (like "Differential Revision"). If this
|
|
|
|
* method returns true, the field will be rendered even if it has no value
|
|
|
|
* during edit and update operations.
|
|
|
|
*
|
|
|
|
* @return bool True to indicate the field should appear in the edit template.
|
|
|
|
* @task commit
|
|
|
|
*/
|
|
|
|
public function shouldAppearOnCommitMessageTemplate() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render a human-readable label for this field, like "Summary" or
|
|
|
|
* "Test Plan". This is distinct from the commit message key, but generally
|
|
|
|
* they should be similar.
|
|
|
|
*
|
|
|
|
* @return string Human-readable field label for commit messages.
|
|
|
|
* @task commit
|
|
|
|
*/
|
|
|
|
public function renderLabelForCommitMessage() {
|
|
|
|
throw new DifferentialFieldSpecificationIncompleteException($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render a human-readable value for this field when it appears in commit
|
|
|
|
* messages (for instance, lists of users should be rendered as user names).
|
|
|
|
*
|
|
|
|
* The ##$is_edit## parameter allows you to distinguish between commit
|
|
|
|
* messages being rendered for editing and those being rendered for amending
|
|
|
|
* or commit. Some fields may decline to render a value in one mode (for
|
|
|
|
* example, "Reviewed By" appears only when doing commit/amend, not while
|
|
|
|
* editing).
|
|
|
|
*
|
|
|
|
* @param bool True if the message is being edited.
|
|
|
|
* @return string Human-readable field value.
|
|
|
|
* @task commit
|
|
|
|
*/
|
|
|
|
public function renderValueForCommitMessage($is_edit) {
|
|
|
|
throw new DifferentialFieldSpecificationIncompleteException($this);
|
|
|
|
}
|
|
|
|
|
Drive Differential commit message parsing through extensible fields
Summary:
I think this is the last major step -- use the fields to parse commit messages,
not a hard-coded list of stuff. This adds two primary methods to fields, one to
get all the labels they'll parse (so we can do "CC" and "CCs" and treat them as
the same field) and one to parse the string into a canonical representation
(e.g., lookup reviewers and such).
You'll need to impelement the one block of task-specific stuff I removed in
Facebook's task field:
list($pre_comment) = split(' -- ', $data);
$data = array_filter(preg_split('/[^\d]+/', $pre_comment));
foreach ($data as $k => $v) {
$data[$k] = (int)$v;
}
$data = array_unique($data);
break;
Otherwise I think this is clean.
Test Plan:
- Called the conduit method with various commit messages, parsed fields/errors
seemed correct.
- "arc diff"'d this diff onto localhost, then updated it.
- "arc amend"'d this diff.
Reviewers: jungejason, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason, epriestley
Differential Revision: 829
2011-08-18 21:08:18 +02:00
|
|
|
/**
|
|
|
|
* Return one or more labels which this field parses in commit messages. For
|
|
|
|
* example, you might parse all of "Task", "Tasks" and "Task Numbers" or
|
|
|
|
* similar. This is just to make it easier to get commit messages to parse
|
|
|
|
* when users are typing in the fields manually as opposed to using a
|
|
|
|
* template, by accepting alternate spellings / pluralizations / etc. By
|
|
|
|
* default, only the label returned from @{method:renderLabelForCommitMessage}
|
|
|
|
* is parsed.
|
|
|
|
*
|
|
|
|
* @return list List of supported labels that this field can parse from commit
|
|
|
|
* messages.
|
|
|
|
* @task commit
|
|
|
|
*/
|
|
|
|
public function getSupportedCommitMessageLabels() {
|
|
|
|
return array($this->renderLabelForCommitMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a raw text block from a commit message into a canonical
|
|
|
|
* representation of the field value. For example, the "CC" field accepts a
|
|
|
|
* comma-delimited list of usernames and emails and parses them into valid
|
|
|
|
* PHIDs, emitting a PHID list.
|
|
|
|
*
|
|
|
|
* If you encounter errors (like a nonexistent username) while parsing,
|
|
|
|
* you should throw a @{class:DifferentialFieldParseException}.
|
|
|
|
*
|
|
|
|
* Generally, this method should accept whatever you return from
|
|
|
|
* @{method:renderValueForCommitMessage} and parse it back into a sensible
|
|
|
|
* representation.
|
|
|
|
*
|
|
|
|
* You must implement this method if you return true from
|
|
|
|
* @{method:shouldAppearOnCommitMessage}.
|
|
|
|
*
|
|
|
|
* @param string
|
|
|
|
* @return mixed The canonical representation of the field value. For example,
|
|
|
|
* you should lookup usernames and object references.
|
|
|
|
* @task commit
|
|
|
|
*/
|
|
|
|
public function parseValueFromCommitMessage($value) {
|
|
|
|
throw new DifferentialFieldSpecificationIncompleteException($this);
|
|
|
|
}
|
|
|
|
|
2011-08-15 03:52:09 +02:00
|
|
|
|
2011-08-14 22:55:30 +02:00
|
|
|
/* -( Loading Additional Data )-------------------------------------------- */
|
2011-08-14 21:33:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specify which @{class:PhabricatorObjectHandles} need to be loaded for your
|
|
|
|
* field to render correctly.
|
|
|
|
*
|
|
|
|
* This is a convenience method which makes the handles available on all
|
|
|
|
* interfaces where the field appears. If your field needs handles on only
|
|
|
|
* some interfaces (or needs different handles on different interfaces) you
|
|
|
|
* can overload the more specific methods to customize which interfaces you
|
|
|
|
* retrieve handles for. Requesting only the handles you need will improve
|
|
|
|
* the performance of your field.
|
|
|
|
*
|
|
|
|
* You can later retrieve these handles by calling @{method:getHandle}.
|
|
|
|
*
|
|
|
|
* @return list List of PHIDs to load handles for.
|
2011-08-14 22:55:30 +02:00
|
|
|
* @task load
|
2011-08-14 21:33:54 +02:00
|
|
|
*/
|
|
|
|
protected function getRequiredHandlePHIDs() {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2012-02-20 14:38:21 +01:00
|
|
|
|
2011-08-14 21:33:54 +02:00
|
|
|
/**
|
|
|
|
* Specify which @{class:PhabricatorObjectHandles} need to be loaded for your
|
|
|
|
* field to render correctly on the view interface.
|
|
|
|
*
|
|
|
|
* This is a more specific version of @{method:getRequiredHandlePHIDs} which
|
|
|
|
* can be overridden to improve field performance by loading only data you
|
|
|
|
* need.
|
|
|
|
*
|
|
|
|
* @return list List of PHIDs to load handles for.
|
2011-08-14 22:55:30 +02:00
|
|
|
* @task load
|
2011-08-14 21:33:54 +02:00
|
|
|
*/
|
|
|
|
public function getRequiredHandlePHIDsForRevisionView() {
|
|
|
|
return $this->getRequiredHandlePHIDs();
|
|
|
|
}
|
|
|
|
|
2012-02-20 14:38:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Specify which @{class:PhabricatorObjectHandles} need to be loaded for your
|
|
|
|
* field to render correctly on the list interface.
|
|
|
|
*
|
|
|
|
* This is a more specific version of @{method:getRequiredHandlePHIDs} which
|
|
|
|
* can be overridden to improve field performance by loading only data you
|
|
|
|
* need.
|
|
|
|
*
|
|
|
|
* @param DifferentialRevision The revision to pull PHIDs for.
|
|
|
|
* @return list List of PHIDs to load handles for.
|
|
|
|
* @task load
|
|
|
|
*/
|
|
|
|
public function getRequiredHandlePHIDsForRevisionList(
|
|
|
|
DifferentialRevision $revision) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-14 21:33:54 +02:00
|
|
|
/**
|
|
|
|
* Specify which @{class:PhabricatorObjectHandles} need to be loaded for your
|
|
|
|
* field to render correctly on the edit interface.
|
|
|
|
*
|
|
|
|
* This is a more specific version of @{method:getRequiredHandlePHIDs} which
|
|
|
|
* can be overridden to improve field performance by loading only data you
|
|
|
|
* need.
|
|
|
|
*
|
|
|
|
* @return list List of PHIDs to load handles for.
|
2011-08-14 22:55:30 +02:00
|
|
|
* @task load
|
2011-08-14 21:33:54 +02:00
|
|
|
*/
|
2011-08-14 23:28:08 +02:00
|
|
|
public function getRequiredHandlePHIDsForRevisionEdit() {
|
2011-08-14 21:33:54 +02:00
|
|
|
return $this->getRequiredHandlePHIDs();
|
|
|
|
}
|
|
|
|
|
Drive commit message rendering from field specifications
Summary:
When rendering commit messages, drive all the logic through field specification
classes instead of the hard-coded DifferentialCommitMessageData class. This
removes DifferentialCommitMessageData and support classes.
Note that this effectively reverts D546, and will cause a minor break for
Facebook (Task IDs will no longer render in commit messages generated by "arc
amend", and will not be editable via "arc diff --edit"). This can be resolved by
implementing the feature as a custom field. While I've been able to preserve the
task ID functionality elsewhere, I felt this implementation was too complex to
reasonably leave hooks for, and the break is pretty minor.
Test Plan:
- Made numerous calls to differential.getcommitmessage across many diffs in
various states, with and without 'edit' and with and without various field
overrides.
- General behavior seems correct (messages look accurate, and have the
expected information). Special fields like "Reviewed By" and "git-svn-id" seem
to work correctly.
- Edit behavior seems correct (edit mode shows all editable fields, hides
fields like "Reviewed By").
- Field overwrite behavior seems correct (overwritable fields show the correct
values when overwritten, ignore provided values otherwise).
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: aran, jungejason
Differential Revision: 814
2011-08-16 06:06:58 +02:00
|
|
|
/**
|
|
|
|
* Specify which @{class:PhabricatorObjectHandles} need to be loaded for your
|
|
|
|
* field to render correctly on the commit message interface.
|
|
|
|
*
|
|
|
|
* This is a more specific version of @{method:getRequiredHandlePHIDs} which
|
|
|
|
* can be overridden to improve field performance by loading only data you
|
|
|
|
* need.
|
|
|
|
*
|
|
|
|
* @return list List of PHIDs to load handles for.
|
|
|
|
* @task load
|
|
|
|
*/
|
|
|
|
public function getRequiredHandlePHIDsForCommitMessage() {
|
|
|
|
return $this->getRequiredHandlePHIDs();
|
|
|
|
}
|
|
|
|
|
2011-08-14 22:55:30 +02:00
|
|
|
/**
|
|
|
|
* Specify which diff properties this field needs to load.
|
|
|
|
*
|
|
|
|
* @return list List of diff property keys this field requires.
|
|
|
|
* @task load
|
|
|
|
*/
|
|
|
|
public function getRequiredDiffProperties() {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
Drive Differential commit message parsing through extensible fields
Summary:
I think this is the last major step -- use the fields to parse commit messages,
not a hard-coded list of stuff. This adds two primary methods to fields, one to
get all the labels they'll parse (so we can do "CC" and "CCs" and treat them as
the same field) and one to parse the string into a canonical representation
(e.g., lookup reviewers and such).
You'll need to impelement the one block of task-specific stuff I removed in
Facebook's task field:
list($pre_comment) = split(' -- ', $data);
$data = array_filter(preg_split('/[^\d]+/', $pre_comment));
foreach ($data as $k => $v) {
$data[$k] = (int)$v;
}
$data = array_unique($data);
break;
Otherwise I think this is clean.
Test Plan:
- Called the conduit method with various commit messages, parsed fields/errors
seemed correct.
- "arc diff"'d this diff onto localhost, then updated it.
- "arc amend"'d this diff.
Reviewers: jungejason, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason, epriestley
Differential Revision: 829
2011-08-18 21:08:18 +02:00
|
|
|
/**
|
|
|
|
* Parse a list of users into a canonical PHID list.
|
|
|
|
*
|
|
|
|
* @param string Raw list of comma-separated user names.
|
|
|
|
* @return list List of corresponding PHIDs.
|
|
|
|
* @task load
|
|
|
|
*/
|
|
|
|
protected function parseCommitMessageUserList($value) {
|
|
|
|
return $this->parseCommitMessageObjectList($value, $mailables = false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a list of mailable objects into a canonical PHID list.
|
|
|
|
*
|
|
|
|
* @param string Raw list of comma-separated mailable names.
|
|
|
|
* @return list List of corresponding PHIDs.
|
|
|
|
* @task load
|
|
|
|
*/
|
|
|
|
protected function parseCommitMessageMailableList($value) {
|
|
|
|
return $this->parseCommitMessageObjectList($value, $mailables = true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse and lookup a list of object names, converting them to PHIDs.
|
|
|
|
*
|
|
|
|
* @param string Raw list of comma-separated object names.
|
2012-03-07 00:10:35 +01:00
|
|
|
* @param bool True to include mailing lists.
|
|
|
|
* @param bool True to make a best effort. By default, an exception is
|
|
|
|
* thrown if any item is invalid.
|
Drive Differential commit message parsing through extensible fields
Summary:
I think this is the last major step -- use the fields to parse commit messages,
not a hard-coded list of stuff. This adds two primary methods to fields, one to
get all the labels they'll parse (so we can do "CC" and "CCs" and treat them as
the same field) and one to parse the string into a canonical representation
(e.g., lookup reviewers and such).
You'll need to impelement the one block of task-specific stuff I removed in
Facebook's task field:
list($pre_comment) = split(' -- ', $data);
$data = array_filter(preg_split('/[^\d]+/', $pre_comment));
foreach ($data as $k => $v) {
$data[$k] = (int)$v;
}
$data = array_unique($data);
break;
Otherwise I think this is clean.
Test Plan:
- Called the conduit method with various commit messages, parsed fields/errors
seemed correct.
- "arc diff"'d this diff onto localhost, then updated it.
- "arc amend"'d this diff.
Reviewers: jungejason, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason, epriestley
Differential Revision: 829
2011-08-18 21:08:18 +02:00
|
|
|
* @return list List of corresponding PHIDs.
|
|
|
|
* @task load
|
|
|
|
*/
|
2012-03-07 00:10:35 +01:00
|
|
|
public static function parseCommitMessageObjectList(
|
|
|
|
$value,
|
|
|
|
$include_mailables,
|
|
|
|
$allow_partial = false) {
|
|
|
|
|
Drive Differential commit message parsing through extensible fields
Summary:
I think this is the last major step -- use the fields to parse commit messages,
not a hard-coded list of stuff. This adds two primary methods to fields, one to
get all the labels they'll parse (so we can do "CC" and "CCs" and treat them as
the same field) and one to parse the string into a canonical representation
(e.g., lookup reviewers and such).
You'll need to impelement the one block of task-specific stuff I removed in
Facebook's task field:
list($pre_comment) = split(' -- ', $data);
$data = array_filter(preg_split('/[^\d]+/', $pre_comment));
foreach ($data as $k => $v) {
$data[$k] = (int)$v;
}
$data = array_unique($data);
break;
Otherwise I think this is clean.
Test Plan:
- Called the conduit method with various commit messages, parsed fields/errors
seemed correct.
- "arc diff"'d this diff onto localhost, then updated it.
- "arc amend"'d this diff.
Reviewers: jungejason, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason, epriestley
Differential Revision: 829
2011-08-18 21:08:18 +02:00
|
|
|
$value = array_unique(array_filter(preg_split('/[\s,]+/', $value)));
|
|
|
|
if (!$value) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$object_map = array();
|
|
|
|
|
|
|
|
$users = id(new PhabricatorUser())->loadAllWhere(
|
2012-05-07 19:29:33 +02:00
|
|
|
'(username IN (%Ls))',
|
Drive Differential commit message parsing through extensible fields
Summary:
I think this is the last major step -- use the fields to parse commit messages,
not a hard-coded list of stuff. This adds two primary methods to fields, one to
get all the labels they'll parse (so we can do "CC" and "CCs" and treat them as
the same field) and one to parse the string into a canonical representation
(e.g., lookup reviewers and such).
You'll need to impelement the one block of task-specific stuff I removed in
Facebook's task field:
list($pre_comment) = split(' -- ', $data);
$data = array_filter(preg_split('/[^\d]+/', $pre_comment));
foreach ($data as $k => $v) {
$data[$k] = (int)$v;
}
$data = array_unique($data);
break;
Otherwise I think this is clean.
Test Plan:
- Called the conduit method with various commit messages, parsed fields/errors
seemed correct.
- "arc diff"'d this diff onto localhost, then updated it.
- "arc amend"'d this diff.
Reviewers: jungejason, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason, epriestley
Differential Revision: 829
2011-08-18 21:08:18 +02:00
|
|
|
$value);
|
2012-01-17 01:54:05 +01:00
|
|
|
|
2011-12-21 04:38:19 +01:00
|
|
|
$user_map = mpull($users, 'getPHID', 'getUsername');
|
|
|
|
foreach ($user_map as $username => $phid) {
|
|
|
|
// Usernames may have uppercase letters in them. Put both names in the
|
|
|
|
// map so we can try the original case first, so that username *always*
|
|
|
|
// works in weird edge cases where some other mailable object collides.
|
|
|
|
$object_map[$username] = $phid;
|
|
|
|
$object_map[strtolower($username)] = $phid;
|
|
|
|
}
|
|
|
|
|
Drive Differential commit message parsing through extensible fields
Summary:
I think this is the last major step -- use the fields to parse commit messages,
not a hard-coded list of stuff. This adds two primary methods to fields, one to
get all the labels they'll parse (so we can do "CC" and "CCs" and treat them as
the same field) and one to parse the string into a canonical representation
(e.g., lookup reviewers and such).
You'll need to impelement the one block of task-specific stuff I removed in
Facebook's task field:
list($pre_comment) = split(' -- ', $data);
$data = array_filter(preg_split('/[^\d]+/', $pre_comment));
foreach ($data as $k => $v) {
$data[$k] = (int)$v;
}
$data = array_unique($data);
break;
Otherwise I think this is clean.
Test Plan:
- Called the conduit method with various commit messages, parsed fields/errors
seemed correct.
- "arc diff"'d this diff onto localhost, then updated it.
- "arc amend"'d this diff.
Reviewers: jungejason, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason, epriestley
Differential Revision: 829
2011-08-18 21:08:18 +02:00
|
|
|
if ($include_mailables) {
|
|
|
|
$mailables = id(new PhabricatorMetaMTAMailingList())->loadAllWhere(
|
|
|
|
'(email IN (%Ls)) OR (name IN (%Ls))',
|
|
|
|
$value,
|
|
|
|
$value);
|
|
|
|
$object_map += mpull($mailables, 'getPHID', 'getName');
|
|
|
|
$object_map += mpull($mailables, 'getPHID', 'getEmail');
|
|
|
|
}
|
|
|
|
|
|
|
|
$invalid = array();
|
|
|
|
$results = array();
|
|
|
|
foreach ($value as $name) {
|
|
|
|
if (empty($object_map[$name])) {
|
2011-12-21 04:38:19 +01:00
|
|
|
if (empty($object_map[strtolower($name)])) {
|
|
|
|
$invalid[] = $name;
|
|
|
|
} else {
|
|
|
|
$results[] = $object_map[strtolower($name)];
|
|
|
|
}
|
Drive Differential commit message parsing through extensible fields
Summary:
I think this is the last major step -- use the fields to parse commit messages,
not a hard-coded list of stuff. This adds two primary methods to fields, one to
get all the labels they'll parse (so we can do "CC" and "CCs" and treat them as
the same field) and one to parse the string into a canonical representation
(e.g., lookup reviewers and such).
You'll need to impelement the one block of task-specific stuff I removed in
Facebook's task field:
list($pre_comment) = split(' -- ', $data);
$data = array_filter(preg_split('/[^\d]+/', $pre_comment));
foreach ($data as $k => $v) {
$data[$k] = (int)$v;
}
$data = array_unique($data);
break;
Otherwise I think this is clean.
Test Plan:
- Called the conduit method with various commit messages, parsed fields/errors
seemed correct.
- "arc diff"'d this diff onto localhost, then updated it.
- "arc amend"'d this diff.
Reviewers: jungejason, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason, epriestley
Differential Revision: 829
2011-08-18 21:08:18 +02:00
|
|
|
} else {
|
|
|
|
$results[] = $object_map[$name];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-07 00:10:35 +01:00
|
|
|
if ($invalid && !$allow_partial) {
|
Drive Differential commit message parsing through extensible fields
Summary:
I think this is the last major step -- use the fields to parse commit messages,
not a hard-coded list of stuff. This adds two primary methods to fields, one to
get all the labels they'll parse (so we can do "CC" and "CCs" and treat them as
the same field) and one to parse the string into a canonical representation
(e.g., lookup reviewers and such).
You'll need to impelement the one block of task-specific stuff I removed in
Facebook's task field:
list($pre_comment) = split(' -- ', $data);
$data = array_filter(preg_split('/[^\d]+/', $pre_comment));
foreach ($data as $k => $v) {
$data[$k] = (int)$v;
}
$data = array_unique($data);
break;
Otherwise I think this is clean.
Test Plan:
- Called the conduit method with various commit messages, parsed fields/errors
seemed correct.
- "arc diff"'d this diff onto localhost, then updated it.
- "arc amend"'d this diff.
Reviewers: jungejason, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason, epriestley
Differential Revision: 829
2011-08-18 21:08:18 +02:00
|
|
|
$invalid = implode(', ', $invalid);
|
|
|
|
$what = $include_mailables
|
|
|
|
? "users and mailing lists"
|
|
|
|
: "users";
|
|
|
|
throw new DifferentialFieldParseException(
|
2012-05-23 02:47:12 +02:00
|
|
|
"Commit message references nonexistent {$what}: {$invalid}.",
|
|
|
|
array_unique($results));
|
Drive Differential commit message parsing through extensible fields
Summary:
I think this is the last major step -- use the fields to parse commit messages,
not a hard-coded list of stuff. This adds two primary methods to fields, one to
get all the labels they'll parse (so we can do "CC" and "CCs" and treat them as
the same field) and one to parse the string into a canonical representation
(e.g., lookup reviewers and such).
You'll need to impelement the one block of task-specific stuff I removed in
Facebook's task field:
list($pre_comment) = split(' -- ', $data);
$data = array_filter(preg_split('/[^\d]+/', $pre_comment));
foreach ($data as $k => $v) {
$data[$k] = (int)$v;
}
$data = array_unique($data);
break;
Otherwise I think this is clean.
Test Plan:
- Called the conduit method with various commit messages, parsed fields/errors
seemed correct.
- "arc diff"'d this diff onto localhost, then updated it.
- "arc amend"'d this diff.
Reviewers: jungejason, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason, epriestley
Differential Revision: 829
2011-08-18 21:08:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return array_unique($results);
|
|
|
|
}
|
|
|
|
|
2011-08-14 22:55:30 +02:00
|
|
|
|
2011-08-14 20:29:56 +02:00
|
|
|
/* -( Contextual Data )---------------------------------------------------- */
|
|
|
|
|
2011-08-14 21:33:54 +02:00
|
|
|
|
2011-08-14 20:29:56 +02:00
|
|
|
/**
|
|
|
|
* @task context
|
|
|
|
*/
|
|
|
|
final public function setRevision(DifferentialRevision $revision) {
|
|
|
|
$this->revision = $revision;
|
Drive commit message rendering from field specifications
Summary:
When rendering commit messages, drive all the logic through field specification
classes instead of the hard-coded DifferentialCommitMessageData class. This
removes DifferentialCommitMessageData and support classes.
Note that this effectively reverts D546, and will cause a minor break for
Facebook (Task IDs will no longer render in commit messages generated by "arc
amend", and will not be editable via "arc diff --edit"). This can be resolved by
implementing the feature as a custom field. While I've been able to preserve the
task ID functionality elsewhere, I felt this implementation was too complex to
reasonably leave hooks for, and the break is pretty minor.
Test Plan:
- Made numerous calls to differential.getcommitmessage across many diffs in
various states, with and without 'edit' and with and without various field
overrides.
- General behavior seems correct (messages look accurate, and have the
expected information). Special fields like "Reviewed By" and "git-svn-id" seem
to work correctly.
- Edit behavior seems correct (edit mode shows all editable fields, hides
fields like "Reviewed By").
- Field overwrite behavior seems correct (overwritable fields show the correct
values when overwritten, ignore provided values otherwise).
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: aran, jungejason
Differential Revision: 814
2011-08-16 06:06:58 +02:00
|
|
|
$this->didSetRevision();
|
2011-08-14 20:29:56 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
Drive commit message rendering from field specifications
Summary:
When rendering commit messages, drive all the logic through field specification
classes instead of the hard-coded DifferentialCommitMessageData class. This
removes DifferentialCommitMessageData and support classes.
Note that this effectively reverts D546, and will cause a minor break for
Facebook (Task IDs will no longer render in commit messages generated by "arc
amend", and will not be editable via "arc diff --edit"). This can be resolved by
implementing the feature as a custom field. While I've been able to preserve the
task ID functionality elsewhere, I felt this implementation was too complex to
reasonably leave hooks for, and the break is pretty minor.
Test Plan:
- Made numerous calls to differential.getcommitmessage across many diffs in
various states, with and without 'edit' and with and without various field
overrides.
- General behavior seems correct (messages look accurate, and have the
expected information). Special fields like "Reviewed By" and "git-svn-id" seem
to work correctly.
- Edit behavior seems correct (edit mode shows all editable fields, hides
fields like "Reviewed By").
- Field overwrite behavior seems correct (overwritable fields show the correct
values when overwritten, ignore provided values otherwise).
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: aran, jungejason
Differential Revision: 814
2011-08-16 06:06:58 +02:00
|
|
|
/**
|
|
|
|
* @task context
|
|
|
|
*/
|
|
|
|
protected function didSetRevision() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-14 20:29:56 +02:00
|
|
|
/**
|
|
|
|
* @task context
|
|
|
|
*/
|
|
|
|
final public function setDiff(DifferentialDiff $diff) {
|
|
|
|
$this->diff = $diff;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-08-14 21:33:54 +02:00
|
|
|
/**
|
|
|
|
* @task context
|
|
|
|
*/
|
|
|
|
final public function setHandles(array $handles) {
|
2012-04-04 22:13:08 +02:00
|
|
|
assert_instances_of($handles, 'PhabricatorObjectHandle');
|
2011-08-14 21:33:54 +02:00
|
|
|
$this->handles = $handles;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-08-14 22:55:30 +02:00
|
|
|
/**
|
|
|
|
* @task context
|
|
|
|
*/
|
|
|
|
final public function setDiffProperties(array $diff_properties) {
|
|
|
|
$this->diffProperties = $diff_properties;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-08-14 23:28:08 +02:00
|
|
|
/**
|
|
|
|
* @task context
|
|
|
|
*/
|
|
|
|
final public function setUser(PhabricatorUser $user) {
|
|
|
|
$this->user = $user;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-08-14 20:29:56 +02:00
|
|
|
/**
|
|
|
|
* @task context
|
|
|
|
*/
|
|
|
|
final protected function getRevision() {
|
|
|
|
if (empty($this->revision)) {
|
|
|
|
throw new DifferentialFieldDataNotAvailableException($this);
|
|
|
|
}
|
|
|
|
return $this->revision;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @task context
|
|
|
|
*/
|
|
|
|
final protected function getDiff() {
|
|
|
|
if (empty($this->diff)) {
|
|
|
|
throw new DifferentialFieldDataNotAvailableException($this);
|
|
|
|
}
|
|
|
|
return $this->diff;
|
|
|
|
}
|
|
|
|
|
2011-08-14 23:28:08 +02:00
|
|
|
/**
|
|
|
|
* @task context
|
|
|
|
*/
|
|
|
|
final protected function getUser() {
|
|
|
|
if (empty($this->user)) {
|
|
|
|
throw new DifferentialFieldDataNotAvailableException($this);
|
|
|
|
}
|
|
|
|
return $this->user;
|
|
|
|
}
|
|
|
|
|
2011-08-14 21:33:54 +02:00
|
|
|
/**
|
|
|
|
* Get the handle for an object PHID. You must overload
|
|
|
|
* @{method:getRequiredHandlePHIDs} (or a more specific version thereof)
|
|
|
|
* and include the PHID you want in the list for it to be available here.
|
|
|
|
*
|
|
|
|
* @return PhabricatorObjectHandle Handle to the object.
|
|
|
|
* @task context
|
|
|
|
*/
|
|
|
|
final protected function getHandle($phid) {
|
2011-08-14 22:55:30 +02:00
|
|
|
if ($this->handles === null) {
|
|
|
|
throw new DifferentialFieldDataNotAvailableException($this);
|
|
|
|
}
|
2011-08-14 21:33:54 +02:00
|
|
|
if (empty($this->handles[$phid])) {
|
|
|
|
$class = get_class($this);
|
|
|
|
throw new Exception(
|
|
|
|
"A differential field (of class '{$class}') is attempting to retrieve ".
|
|
|
|
"a handle ('{$phid}') which it did not request. Return all handle ".
|
|
|
|
"PHIDs you need from getRequiredHandlePHIDs().");
|
|
|
|
}
|
|
|
|
return $this->handles[$phid];
|
|
|
|
}
|
|
|
|
|
2011-08-14 22:55:30 +02:00
|
|
|
/**
|
|
|
|
* Get a diff property which this field previously requested by returning
|
|
|
|
* the key from @{method:getRequiredDiffProperties}.
|
|
|
|
*
|
|
|
|
* @param string Diff property key.
|
|
|
|
* @return string|null Diff property, or null if the property does not have
|
|
|
|
* a value.
|
|
|
|
* @task context
|
|
|
|
*/
|
|
|
|
final public function getDiffProperty($key) {
|
|
|
|
if ($this->diffProperties === null) {
|
|
|
|
// This will be set to some (possibly empty) array if we've loaded
|
|
|
|
// properties, so null means diff properties aren't available in this
|
|
|
|
// context.
|
|
|
|
throw new DifferentialFieldDataNotAvailableException($this);
|
|
|
|
}
|
|
|
|
if (!array_key_exists($key, $this->diffProperties)) {
|
|
|
|
$class = get_class($this);
|
|
|
|
throw new Exception(
|
|
|
|
"A differential field (of class '{$class}') is attempting to retrieve ".
|
|
|
|
"a diff property ('{$key}') which it did not request. Return all ".
|
|
|
|
"diff property keys you need from getRequiredDiffProperties().");
|
|
|
|
}
|
|
|
|
return $this->diffProperties[$key];
|
|
|
|
}
|
|
|
|
|
2011-08-10 20:29:08 +02:00
|
|
|
}
|