Skip to content

Commit

Permalink
minor: use VERSIONCONTROL_LABEL_{BRANCH,TAG}
Browse files Browse the repository at this point in the history
instead of VERSIONCONTROL_OPERATION_{BRANCH,TAG} when it's necessary

ehm... lot of file changed.. but mainly on docs :p

VersioncontrolLabel and its children VersioncontrolBranch and VersioncontrolTag
were reviewed, and probably will not change a lot from now.
  • Loading branch information
marvil07 committed Jul 10, 2009
1 parent b723e2d commit db3c1d5
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 133 deletions.
4 changes: 2 additions & 2 deletions commit_restrictions/commit_restrictions.module
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,15 @@ function _commit_restrictions_label_access($operation, $restrictions) {

// This code will work for both branches and tags, given some preset values.
$labelinfos = array(
VERSIONCONTROL_OPERATION_BRANCH => array(
VERSIONCONTROL_LABEL_BRANCH => array(
'valid_restrictions' => $valid_branches,
'other_restrictions' => $valid_tags,
'simple_error' => t('** ERROR: the !labelname branch is not allowed in this repository.'),
'confusion_error' => t(
'** ERROR: "!labelname" is a valid name for a tag, but not for a branch.
** You must either create a tag with this name, or choose a valid branch name.'),
),
VERSIONCONTROL_OPERATION_TAG => array(
VERSIONCONTROL_LABEL_TAG => array(
'valid_restrictions' => $valid_tags,
'other_restrictions' => $valid_branches,
'simple_error' => '** ERROR: the !labelname tag is not allowed in this repository.',
Expand Down
10 changes: 5 additions & 5 deletions commitlog/commitlog.module
Original file line number Diff line number Diff line change
Expand Up @@ -786,13 +786,13 @@ function theme_commitlog_operation_caption($variables, $options = array()) {
$action_strings[] = t('committed !id to !labels', $replacements);
}
else if ($action == VERSIONCONTROL_ACTION_ADDED) {
$action_string = ($type == VERSIONCONTROL_OPERATION_BRANCH)
$action_string = ($type == VERSIONCONTROL_LABEL_BRANCH)
? format_plural(count($labels), 'created branch !labels', 'created branches !labels')
: format_plural(count($labels), 'created tag !labels', 'created tags !labels');
$action_strings[] = strtr($action_string, $replacements);
}
else if ($action == VERSIONCONTROL_ACTION_DELETED) {
$action_string = ($type == VERSIONCONTROL_OPERATION_BRANCH)
$action_string = ($type == VERSIONCONTROL_LABEL_BRANCH)
? format_plural(count($labels), 'deleted branch !labels', 'deleted branches !labels')
: format_plural(count($labels), 'deleted tag !labels', 'deleted tags !labels');
$action_strings[] = strtr($action_string, $replacements);
Expand Down Expand Up @@ -851,12 +851,12 @@ function theme_commitlog_operation_subject($variables, $options = array()) {
$replacements = array('!label' => $label_string, '!repo' => $repo_name);

if ($first_label['action'] == VERSIONCONTROL_ACTION_ADDED) {
$action_string = ($first_label['type'] == VERSIONCONTROL_OPERATION_BRANCH)
$action_string = ($first_label['type'] == VERSIONCONTROL_LABEL_BRANCH)
? t('Created branch !label', $replacements)
: t('Created tag !label', $replacements);
}
else if ($first_label['action'] == VERSIONCONTROL_ACTION_DELETED) {
$action_string = ($first_label['type'] == VERSIONCONTROL_OPERATION_BRANCH)
$action_string = ($first_label['type'] == VERSIONCONTROL_LABEL_BRANCH)
? t('Created branch !label', $replacements)
: t('Created tag !label', $replacements);
}
Expand All @@ -883,7 +883,7 @@ function theme_commitlog_label($label, $options = array()) {
$options = _commitlog_options($options);

if ($options['format'] == 'html') {
$label_type_filter = ($label['type'] == VERSIONCONTROL_OPERATION_BRANCH)
$label_type_filter = ($label['type'] == VERSIONCONTROL_LABEL_BRANCH)
? 'branch' : 'tag';
return l($label['name'], 'commitlog', array(
'query' => array($label_type_filter => $label['name']),
Expand Down
8 changes: 4 additions & 4 deletions hook_versioncontrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,12 @@ function hook_versioncontrol_write_access($operation, $operation_items) {

// Restrict disallowed branches and tags.
$valid_labels = array(
VERSIONCONTROL_OPERATION_BRANCH => array('@^HEAD$@', '@^DRUPAL-5(--[2-9])?$@', '@^DRUPAL-6--[1-9]$@'),
VERSIONCONTROL_OPERATION_TAG => array('@^DRUPAL-[56]--(\d+)-(\d+)(-[A-Z0-9]+)?$@'),
VERSIONCONTROL_LABEL_BRANCH => array('@^HEAD$@', '@^DRUPAL-5(--[2-9])?$@', '@^DRUPAL-6--[1-9]$@'),
VERSIONCONTROL_LABEL_TAG => array('@^DRUPAL-[56]--(\d+)-(\d+)(-[A-Z0-9]+)?$@'),
);

foreach ($operation['labels'] as $label) {
if ($label['type'] == VERSIONCONTROL_OPERATION_TAG
if ($label['type'] == VERSIONCONTROL_LABEL_TAG
&& $label['action'] == VERSIONCONTROL_ACTION_DELETED) {
continue; // no restrictions, even invalid tags should be allowed to be deleted
}
Expand All @@ -314,7 +314,7 @@ function hook_versioncontrol_write_access($operation, $operation_items) {
// No regexps match this label, so deny it.
$error_messages[] = t('** ERROR: the !name !labeltype is not allowed in this repository.', array(
'!name' => $label['name'],
'!labeltype' => ($label['type'] == VERSIONCONTROL_OPERATION_BRANCH)
'!labeltype' => ($label['type'] == VERSIONCONTROL_LABEL_BRANCH)
? t('branch')
: t('tag'),
));
Expand Down
1 change: 0 additions & 1 deletion includes/VersioncontrolBranch.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

/**
* Represents a branch of code
*
*/
class VersioncontrolBranch extends VersioncontrolLabel {
// Operations
Expand Down
14 changes: 3 additions & 11 deletions includes/VersioncontrolItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,7 @@ public function fetchItemRevisionId() {
* @return
* In case no branch or tag applies to that item or could not be retrieved
* for whatever reasons, the selected label can also be NULL. Otherwise, it's
* a label array describing the selected label, with the following keys:
*
* - 'label_id': The label identifier (a simple integer), used for unique
* identification of branches and tags in the database.
* - 'name': The branch or tag name (a string).
* - 'type': Whether this label is a branch (indicated by the
* VERSIONCONTROL_OPERATION_BRANCH constant) or a tag
* (VERSIONCONTROL_OPERATION_TAG).
* FIXME remove params and do not return, oop
* a VersioncontrolLabel object(tag or branch)
*/
public function getSelectedLabel() {
// If the label is already retrieved, we can return it just that way.
Expand Down Expand Up @@ -573,9 +565,9 @@ public function getParentItem($parent_path = NULL) {
* The repository that the item is located in.
* @param $item
* The item whose parallel sibling should be retrieved.
* @param $label_type
* @param $label_type_filter
* If unset, siblings will be retrieved both on branches and tags.
* If set to VERSIONCONTROL_OPERATION_BRANCH or VERSIONCONTROL_OPERATION_TAG,
* If set to VERSIONCONTROL_LABEL_BRANCH or VERSIONCONTROL_LABEL_TAG,
* results are limited to just that label type.
*
* @return
Expand Down
29 changes: 7 additions & 22 deletions includes/VersioncontrolLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
/**
* @name VCS label types
* Use same values as VERSIONCONTROL_OPERATION_* for backward compatibility
* TODO: change all involved label['type'] usages
*/
//@{
define('VERSIONCONTROL_LABEL_BRANCH', 2);
Expand All @@ -13,7 +12,6 @@

/**
* The parent of branches and tags classes
*
*/
abstract class VersioncontrolLabel implements ArrayAccess {
// Attributes
Expand All @@ -40,9 +38,9 @@ abstract class VersioncontrolLabel implements ArrayAccess {
public $repository;

/**
* Whether this label is a branch (indicated by the
* VERSIONCONTROL_LABEL_BRANCH constant) or a tag
* (VERSIONCONTROL_LABEL_TAG).
* Whether this label is a branch (indicated by the
* VERSIONCONTROL_LABEL_BRANCH constant) or a tag
* (VERSIONCONTROL_LABEL_TAG).
*
* @var int
*/
Expand Down Expand Up @@ -76,23 +74,10 @@ public function __construct($type, $name, $action, $label_id=NULL, $repository=N
* Insert a label entry into the {versioncontrol_labels} table,
* or retrieve the same one that's already there.
*
* @param $label
* A structured array describing the branch or tag that should be inserted
* into the database. A label array contains (at least) the following keys:
*
* - 'name': The branch or tag name (a string).
* - 'type': Whether this label is a branch (indicated by the
* VERSIONCONTROL_OPERATION_BRANCH constant) or a tag
* (VERSIONCONTROL_OPERATION_TAG).
* - 'label_id': Optional - if it doesn't exist yet, it will afterwards.
* The label identifier (a simple integer), used for unique
* identification of branches and tags in the database.
*
* @return
* The @p $label variable, enhanced with the newly added property 'label_id'
* specifying the database identifier for that label. There may be labels
* with a similar 'name' but different 'type' properties, those are considered
* to be different and will both go into the database side by side.
* The object is enhanced with the newly added property 'label_id'
* specifying the database identifier for that label. There may be labels
* with a similar 'name' but different 'type' properties, those are considered
* to be different and will both go into the database side by side.
*/
public function ensure() {
if (!empty($this->label_id)) { // already in the database
Expand Down
39 changes: 3 additions & 36 deletions includes/VersioncontrolOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,7 @@ class VersioncontrolOperation implements ArrayAccess {
* add/delete/move operations for labels, as detailed below.
* Mind that the main development branch - e.g. 'HEAD', 'trunk'
* or 'master' - is also considered a branch. Each element in 'labels'
* is a structured array with the following keys:
* FIXME: VersioncontrolLabel's array?
*
* - 'name': The branch or tag name (a string).
* - 'type': Whether this label is a branch (indicated by the
* VERSIONCONTROL_OPERATION_BRANCH constant) or a tag
* (VERSIONCONTROL_OPERATION_TAG).
* - 'action': Specifies what happened to this label in this operation.
* For plain commits, this is always VERSIONCONTROL_ACTION_MODIFIED.
* For branch or tag operations (or commits that emulate those),
* it can be either VERSIONCONTROL_ACTION_ADDED or
* VERSIONCONTROL_ACTION_DELETED.
* is a VersioncontrolLabel(VersioncontrolBranch VersioncontrolTag)
*
* @var array
*/
Expand Down Expand Up @@ -277,19 +266,7 @@ public function __construct($type, $committer, $date, $revision, $message, $auth
* add or delete operations for labels, as detailed below.
* Mind that the main development branch - e.g. 'HEAD', 'trunk'
* or 'master' - is also considered a branch. Each element in 'labels'
* is a structured array with the following keys:
*
* - 'label_id': The label identifier (a simple integer), used for unique
* identification of branches and tags in the database.
* - 'name': The branch or tag name (a string).
* - 'type': Whether this label is a branch (indicated by the
* VERSIONCONTROL_OPERATION_BRANCH constant) or a tag
* (VERSIONCONTROL_OPERATION_TAG).
* - 'action': Specifies what happened to this label in this operation.
* For plain commits, this is always VERSIONCONTROL_ACTION_MODIFIED.
* For branch or tag operations (or commits that emulate those),
* it can be either VERSIONCONTROL_ACTION_ADDED or
* VERSIONCONTROL_ACTION_DELETED.
* is a VersioncontrolLabel(VersioncontrolBranch VersioncontrolTag)
*
* If not a single operation matches these constraints,
* an empty array is returned.
Expand Down Expand Up @@ -953,17 +930,7 @@ protected function getAccessErrors() {
* add/delete/move operations for labels, as detailed below.
* Mind that the main development branch - e.g. 'HEAD', 'trunk'
* or 'master' - is also considered a branch. Each element in 'labels'
* is a structured array with the following keys:
*
* - 'name': The branch or tag name (a string).
* - 'type': Whether this label is a branch (indicated by the
* VERSIONCONTROL_OPERATION_BRANCH constant) or a tag
* (VERSIONCONTROL_OPERATION_TAG).
* - 'action': Specifies what happened to this label in this operation.
* For plain commits, this is always VERSIONCONTROL_ACTION_MODIFIED.
* For branch or tag operations (or commits that emulate those),
* it can be either VERSIONCONTROL_ACTION_ADDED or
* VERSIONCONTROL_ACTION_DELETED.
* is a VersioncontrolLabel(VersioncontrolBranch VersioncontrolTag)
*
* @param $operation_items
* A structured array containing the exact details of what is about to happen
Expand Down
8 changes: 4 additions & 4 deletions includes/VersioncontrolRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ private function _amend_repositories($repositories_by_backend, $backends, $const
*
* - 'label_ids': An array of label ids. If given, only labels with one of
* these identifiers will be returned.
* - 'type': Either VERSIONCONTROL_OPERATION_BRANCH or
* VERSIONCONTROL_OPERATION_TAG. If given, only labels of this type
* - 'type': Either VERSIONCONTROL_LABEL_BRANCH or
* VERSIONCONTROL_LABEL_TAG. If given, only labels of this type
* will be returned.
* - 'names': An array of label names to search for. If given, only labels
* matching one of these names will be returned. Matching is done with
Expand All @@ -348,8 +348,8 @@ private function _amend_repositories($repositories_by_backend, $backends, $const
* identification of branches and tags in the database.
* - 'name': The branch or tag name (a string).
* - 'type': Whether this label is a branch (indicated by the
* VERSIONCONTROL_OPERATION_BRANCH constant) or a tag
* (VERSIONCONTROL_OPERATION_TAG).
* VERSIONCONTROL_LABEL_BRANCH constant) or a tag
* (VERSIONCONTROL_LABEL_TAG).
*
* If not a single known label in the given repository matches these
* constraints, an empty array is returned.
Expand Down
1 change: 0 additions & 1 deletion includes/VersioncontrolTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

/**
* Represents a tag of code(not changing state)
*
*/
class VersioncontrolTag extends VersioncontrolLabel {

Expand Down
2 changes: 1 addition & 1 deletion versioncontrol.install
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function versioncontrol_schema() {
),
'type' => array(
'description' =>
'Whether this label is a branch or a tag. Consequently, this can be either VERSIONCONTROL_OPERATION_BRANCH or VERSIONCONTROL_OPERATION_TAG. (If we went for total correctness, it would have been VERSIONCONTROL_LABEL_{BRANCH,TAG} but I fear the confusion coming out of two similar constants. Therefore, reusing the operation constants.)',
'Whether this label is a branch or a tag. Consequently, this can be either VERSIONCONTROL_LABEL_BRANCH or VERSIONCONTROL_LABEL_TAG.',
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
Expand Down
8 changes: 4 additions & 4 deletions versioncontrol.module
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ function versioncontrol_operation_constraint_types($constraint, &$tables, &$and_
$tables['versioncontrol_labels']['alias'] .'.type = %d AND '.
$tables['versioncontrol_operation_labels']['alias'] .'.action <> %d
)';
$params[] = VERSIONCONTROL_OPERATION_BRANCH; // label.type
$params[] = VERSIONCONTROL_LABEL_BRANCH; // label.type
// oplabel.action is != normal commits, we don't want those:
$params[] = VERSIONCONTROL_ACTION_MODIFIED;
}
Expand Down Expand Up @@ -1336,7 +1336,7 @@ function versioncontrol_get_url_item_log_view($repository, &$item) {
$urls = _versioncontrol_get_repository_urls($repository);
$label = $item->getSelectedLabel();

if (isset($label['type']) && $label['type'] == VERSIONCONTROL_OPERATION_BRANCH) {
if (isset($label['type']) && $label['type'] == VERSIONCONTROL_LABEL_BRANCH) {
$current_branch = $label['name'];
}

Expand Down Expand Up @@ -1385,7 +1385,7 @@ function versioncontrol_get_url_item_view($repository, &$item) {
$urls = _versioncontrol_get_repository_urls($repository);
$label = $item->getSelectedLabel();

if (isset($label->type) && $label->type == VERSIONCONTROL_OPERATION_BRANCH) {
if (isset($label->type) && $label->type == VERSIONCONTROL_LABEL_BRANCH) {
$current_branch = $label->name;
}
$view_url = $item->isFile()
Expand Down Expand Up @@ -1419,7 +1419,7 @@ function versioncontrol_get_url_diff($repository, &$file_item_new, $file_item_ol
$urls = _versioncontrol_get_repository_urls($repository);
$label = $file_item_new->getSelectedLabel();

if (isset($label['type']) && $label['type'] == VERSIONCONTROL_OPERATION_BRANCH) {
if (isset($label['type']) && $label['type'] == VERSIONCONTROL_LABEL_BRANCH) {
$current_branch = $label['name'];
}
return strtr($urls['diff'], array(
Expand Down
Loading

0 comments on commit db3c1d5

Please sign in to comment.