| 1 |
<?php
|
| 2 |
// $Id: cvs_deploy.inc,v 1.5 2009/10/14 13:19:29 adrian Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
*
|
| 7 |
* This include file is based on the cvs_deploy module by Derek Wright.
|
| 8 |
* @author Derek Wright ("dww") http://drupal.org/user/46549
|
| 9 |
*/
|
| 10 |
|
| 11 |
/**
|
| 12 |
* Used by provision to hook into the cvs_deploy system.
|
| 13 |
*/
|
| 14 |
function _provision_cvs_deploy(&$file) {
|
| 15 |
$file->filename = realpath($file->filename);
|
| 16 |
$project = (isset($file->info['project'])) ? $file->info['project'] : _provision_cvs_deploy_get_project_name($file);
|
| 17 |
$file->project = $project;
|
| 18 |
_provision_cvs_deploy_version_alter($file->info['version'], $file);
|
| 19 |
$file->version = $file->info['version'];
|
| 20 |
}
|
| 21 |
|
| 22 |
/**
|
| 23 |
* Private helper to alter the 'project' of a module based on what directory
|
| 24 |
* in the CVS repository the module has been checked out from.
|
| 25 |
*/
|
| 26 |
function _provision_cvs_deploy_get_project_name($file) {
|
| 27 |
static $projects = array();
|
| 28 |
$name = $file->name;
|
| 29 |
if (empty($projects[$name])) {
|
| 30 |
// TODO: cache this in {cache}, too?
|
| 31 |
$cvs_dir = dirname($file->filename) .'/CVS';
|
| 32 |
if (is_dir($cvs_dir)) {
|
| 33 |
$repository = '';
|
| 34 |
if (file_exists($cvs_dir .'/Repository')) {
|
| 35 |
$repo_file = trim(file_get_contents($cvs_dir .'/Repository'));
|
| 36 |
if ($repo_file) {
|
| 37 |
$parts = explode('/', $repo_file);
|
| 38 |
if ($parts[0] == 'drupal') {
|
| 39 |
$projects[$name] = $parts[0];
|
| 40 |
}
|
| 41 |
else {
|
| 42 |
$projects[$name] = $parts[2];
|
| 43 |
}
|
| 44 |
}
|
| 45 |
}
|
| 46 |
}
|
| 47 |
}
|
| 48 |
return (isset($projects[$name]) ? $projects[$name] : '');
|
| 49 |
}
|
| 50 |
|
| 51 |
/**
|
| 52 |
* Private helper to alter the version of a module based on what we can figure
|
| 53 |
* out about the CVS tag in use.
|
| 54 |
*/
|
| 55 |
function _provision_cvs_deploy_version_alter(&$version, $file) {
|
| 56 |
static $available = array();
|
| 57 |
$match = array();
|
| 58 |
if (empty($version)) {
|
| 59 |
// The .info file contains no version data. Find the version based
|
| 60 |
// on the sticky tag in the local workspace (the CVS/Tag file).
|
| 61 |
$cvs_dir = dirname($file->filename) .'/CVS';
|
| 62 |
if (is_dir($cvs_dir)) {
|
| 63 |
$tag = ''; // If there's no Tag file, there's no tag, a.k.a. HEAD.
|
| 64 |
if (file_exists($cvs_dir .'/Tag')) {
|
| 65 |
$tag_file = trim(file_get_contents($cvs_dir .'/Tag'));
|
| 66 |
if ($tag_file) {
|
| 67 |
// Get the sticky tag for this workspace: strip off the leading 'T'.
|
| 68 |
$tag = preg_replace('@^(T|N)@', '', $tag_file);
|
| 69 |
}
|
| 70 |
}
|
| 71 |
$version = _provision_cvs_deploy_version_from_tag($tag);
|
| 72 |
}
|
| 73 |
}
|
| 74 |
// The weird concatenation prevents CVS from 'expanding' this $Name.
|
| 75 |
elseif (preg_match('/\$'.'Name: (.*?)\$/', $version, $match)) {
|
| 76 |
$version = _provision_cvs_deploy_version_from_tag(trim($match[1]));
|
| 77 |
}
|
| 78 |
}
|
| 79 |
|
| 80 |
/**
|
| 81 |
* Returns the human-readable version string from a given CVS tag.
|
| 82 |
*/
|
| 83 |
function _provision_cvs_deploy_version_from_tag($tag) {
|
| 84 |
// If there's nothing, it must be a HEAD checkout, and therefore,
|
| 85 |
// we have no idea what the version is.
|
| 86 |
if (!$tag || $tag == 'HEAD') {
|
| 87 |
$version = drush_drupal_major_version() . '.x-dev';
|
| 88 |
}
|
| 89 |
// See if it's a Drupal core release
|
| 90 |
elseif (preg_match('@^DRUPAL-(\d+)-(\d+)$@', $tag, $match)) {
|
| 91 |
$version = $match[1] . '.' . $match[2];
|
| 92 |
}
|
| 93 |
// See if it's a full, official release from a tag:
|
| 94 |
elseif (preg_match('@^DRUPAL-(\d+)--(\d+)-(\d+)(-.+)?@', $tag, $match)) {
|
| 95 |
$version = $match[1] .'.x-'. $match[2] .'.'. $match[3];
|
| 96 |
if (isset($match[4])) {
|
| 97 |
// This version's tag has 'extra', so clean that up.
|
| 98 |
$version .= '-'. preg_replace('/[_-]/', '', strtolower($match[4]));
|
| 99 |
}
|
| 100 |
}
|
| 101 |
// If not, see if it's from a branch (like a development snapshot).
|
| 102 |
elseif (preg_match('@^DRUPAL-(\d+)(--(\d+))?@', $tag, $match)) {
|
| 103 |
$version = $match[1] .'.x-'. (isset($match[3]) ? $match[3] : '1') .'.x-dev';
|
| 104 |
}
|
| 105 |
return $version;
|
| 106 |
}
|