diff --git includes/VersioncontrolItem.php includes/VersioncontrolItem.php index 1bbfe80..fbea654 100644 --- includes/VersioncontrolItem.php +++ includes/VersioncontrolItem.php @@ -78,8 +78,8 @@ abstract class VersioncontrolItem extends VersioncontrolEntity { public $line_changes_removed; /** - * The type of the item. Either - * VERSIONCONTROL_ITEM_{FILE,DIRECTORY,FILE_DELETED,DIRECTORY_DELETED}. + * The type of the item. Permutations of + * VERSIONCONTROL_ITEM_{EMPTY,FILE,DIRECTORY,DELETED}. */ public $type; @@ -111,38 +111,27 @@ abstract class VersioncontrolItem extends VersioncontrolEntity { // } /** - * Return TRUE if the given item is an existing or an already deleted - * file, or FALSE if it's not. + * Return VERSIONCONTROL_ITEM_FILE if the given item is an existing or an + * already deleted file, or 0 if it's not. */ public function isFile() { - if ($this->type == VERSIONCONTROL_ITEM_FILE - || $this->type == VERSIONCONTROL_ITEM_FILE_DELETED) { - return TRUE; - } - return FALSE; + return ($this->type & VERSIONCONTROL_ITEM_FILE); } /** - * Return TRUE if the given item is an existing or an already deleted - * directory, or FALSE if it's not. + * Return VERSIONCONTROL_ITEM_DIRECTORY if the given item is an existing or + * an already deleted directory, or 0 if it's not. */ public function isDirectory() { - if ($this->type == VERSIONCONTROL_ITEM_DIRECTORY - || $this->type == VERSIONCONTROL_ITEM_DIRECTORY_DELETED) { - return TRUE; - } - return FALSE; + return ($this->type & VERSIONCONTROL_ITEM_DIRECTORY); } /** - * Return TRUE if the given item is marked as deleted, or FALSE if it exists. + * Return VERSIONCONTROL_ITEM_DELETED if the given item is marked as deleted, + * or 0 if it exists. */ public function isDeleted() { - if ($this->type == VERSIONCONTROL_ITEM_FILE_DELETED - || $this->type == VERSIONCONTROL_ITEM_DIRECTORY_DELETED) { - return TRUE; - } - return FALSE; + return ($this->type & VERSIONCONTROL_ITEM_DELETED); } /** diff --git includes/interfaces.inc includes/interfaces.inc index 70d39af..7b60d14 100644 --- includes/interfaces.inc +++ includes/interfaces.inc @@ -21,11 +21,10 @@ interface VersioncontrolItemParallelItems { * - 'item': An item array, consisting of the following elements: * * - 'type': Specifies the item type, which is either - * VERSIONCONTROL_ITEM_FILE or VERSIONCONTROL_ITEM_DIRECTORY for - * items that still exist, or VERSIONCONTROL_ITEM_FILE_DELETED - * respectively VERSIONCONTROL_ITEM_DIRECTORY_DELETED for items - * that have been removed. - 'path': The path of the item at - * the specific revision. - 'revision': The currently selected + * VERSIONCONTROL_ITEM_FILE or VERSIONCONTROL_ITEM_DIRECTORY and + * optionally flagged VERSIONCONTROL_ITEM_DELETED for items that + * have been removed. - 'path': The path of the item at the + * specific revision. - 'revision': The currently selected * (file-level) revision of the item. If there is no such * revision (which may be the case for directory items) then the * 'revision' element is an empty string. diff --git versioncontrol.api.php versioncontrol.api.php index e2ed620..fb73820 100644 --- versioncontrol.api.php +++ versioncontrol.api.php @@ -87,11 +87,10 @@ * The associated array elements are structured item arrays and consist of * the following elements: * - * - 'type': Specifies the item type, which is either - * VERSIONCONTROL_ITEM_FILE or VERSIONCONTROL_ITEM_DIRECTORY for items - * that still exist, or VERSIONCONTROL_ITEM_FILE_DELETED respectively - * VERSIONCONTROL_ITEM_DIRECTORY_DELETED for items that have been - * removed (by a commit's delete action). + * - 'type': Specifies the item type bitmask, which is either + * VERSIONCONTROL_ITEM_FILE or VERSIONCONTROL_ITEM_DIRECTORY and + * optionally flagged VERSIONCONTROL_ITEM_DELETED for items that have + * been removed (by a commit's delete action). * - 'path': The path of the item at the specific revision. * - 'revision': The (file-level) revision when the item was changed. * If there is no such revision (which may be the case for diff --git versioncontrol.install versioncontrol.install index 1a61a80..f67c874 100644 --- versioncontrol.install +++ versioncontrol.install @@ -235,8 +235,7 @@ function versioncontrol_schema() { 'default' => '', ), 'type' => array( - 'description' => - 'Specifies whether the item is a file or directory, and whether it exists or is deleted. Deleted items might exist for real, such as in CVS repositories (the "Attic") or they might just be recorded as part of a commit operation where the item was deleted, even though the version control system does not know about this revision. In Version Control API, deleted items only exist for display purposes, backends are expected not to retrieve information about them other than item history. Possible values for the item type are VERSIONCONTROL_ITEM_FILE, VERSIONCONTROL_ITEM_FILE_DELETED, VERSIONCONTROL_ITEM_DIRECTORY and VERSIONCONTROL_ITEM_DIRECTORY_DELETED. Usually though, API users should only use the functions VersioncontrolItem::isFile(), VersioncontrolItem::isDirectory() and VersioncontrolItem::isDeleted() for testing these constants.', + 'description' => 'Bitmask which specifies whether the item is a file or directory, and whether it exists or is deleted. Deleted items might exist for real, such as in CVS repositories (the "Attic") or they might just be recorded as part of a commit operation where the item was deleted, even though the version control system does not know about this revision. In Version Control API, deleted items only exist for display purposes, backends are expected not to retrieve information about them other than item history. Possible flags for the item type are VERSIONCONTROL_ITEM_EMPTY, VERSIONCONTROL_ITEM_FILE, VERSIONCONTROL_ITEM_DIRECTORY and VERSIONCONTROL_ITEM_DELETED. Usually though, API users should only use the functions VersioncontrolItem::isFile(), VersioncontrolItem::isDirectory() and VersioncontrolItem::isDeleted() for testing these constants.', 'type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, @@ -1164,3 +1163,14 @@ function versioncontrol_update_6313() { db_drop_unique_key(&$ret, 'versioncontrol_repositories', 'name'); return $ret; } + +/** + * Implements hook_update_N(). + * + * Alter stored value for VersioncontrolItem::type to use proper bitmasks + */ +function versioncontrol_update_6314() { + $ret = array(); + db_query('UPDATE {versioncontrol_item_revisions} SET type = %d WHERE type = 4', (VERSIONCONTROL_ITEM_DIRECTORY | VERSIONCONTROL_ITEM_DELETED)); + db_query('UPDATE {versioncontrol_item_revisions} SET type = %d WHERE type = 3', (VERSIONCONTROL_ITEM_FILE | VERSIONCONTROL_ITEM_DELETED)); +} diff --git versioncontrol.module versioncontrol.module index 5cd60bc..314873f 100644 --- versioncontrol.module +++ versioncontrol.module @@ -76,11 +76,13 @@ define('VERSIONCONTROL_OPERATION_TAG', 3); //@} /** - * @name VCS item types. + * @name VCS item type bitmasks. */ //@{ +define('VERSIONCONTROL_ITEM_EMPTY', 0); define('VERSIONCONTROL_ITEM_FILE', 1); define('VERSIONCONTROL_ITEM_DIRECTORY', 2); +define('VERSIONCONTROL_ITEM_DELETED', 4); //@} /** * @name VCS "Deleted" item types. @@ -91,8 +93,8 @@ define('VERSIONCONTROL_ITEM_DIRECTORY', 2); * returned by directory listings for CVS, representing "dead files". */ //@{ -define('VERSIONCONTROL_ITEM_FILE_DELETED', 3); -define('VERSIONCONTROL_ITEM_DIRECTORY_DELETED', 4); +define('VERSIONCONTROL_ITEM_FILE_DELETED', VERSIONCONTROL_ITEM_FILE | VERSIONCONTROL_ITEM_DELETED); +define('VERSIONCONTROL_ITEM_DIRECTORY_DELETED', VERSIONCONTROL_ITEM_DIRECTORY | VERSIONCONTROL_ITEM_DELETED); //@} /** diff --git versioncontrol_fakevcs/includes/classes.inc versioncontrol_fakevcs/includes/classes.inc index b9d529b..b4ecc95 100644 --- versioncontrol_fakevcs/includes/classes.inc +++ versioncontrol_fakevcs/includes/classes.inc @@ -385,7 +385,7 @@ implements VersioncontrolItemParallelItems, VersioncontrolItemDirectoryContents, ), '/contributions/modules/versioncontrol/fakevcs_backend/fakevcs_backend.module' => array( 'item' => new VersioncontrolFakeItem( - VERSIONCONTROL_ITEM_FILE_DELETED, // only for non-atomic-commit VCSs (= CVS), + VERSIONCONTROL_ITEM_FILE | VERSIONCONTROL_ITEM_DELETED, // only for non-atomic-commit VCSs (= CVS), '/contributions/modules/versioncontrol/fakevcs_backend/fakevcs_backend.module', '1.11', NULL,