function git_deploy_system_info_alter in Git Deploy 6.2
Same name and namespace in other branches
- 8.2 git_deploy.module \git_deploy_system_info_alter()
- 6 git_deploy.module \git_deploy_system_info_alter()
- 7.2 git_deploy.module \git_deploy_system_info_alter()
- 7 git_deploy.module \git_deploy_system_info_alter()
Implements hook_system_info_alter().
File
- ./
git_deploy.module, line 68 - Adds project, version and date information to projects checked out with Git.
Code
function git_deploy_system_info_alter(&$info, $file) {
// Use _git_deploy_static() so we can share static variables and free up
// memory later.
$projects =& _git_deploy_static('projects', array());
$available =& _git_deploy_static('available');
$update =& _git_deploy_static('update', array());
$last_check =& _git_deploy_static('last_check');
// Core has hard-coded version numbers, so we need to verify them. Otherwise,
// a valid version number indicates that this project was not installed with
// Git.
$is_core = isset($info['package']) && strpos($info['package'], 'Core -') !== FALSE;
if (empty($info['version']) || ($is_core ? strstr($info['version'], '-dev') == '-dev' : $info['version'] == VERSION || !preg_match('/^6\\.x-\\d+\\..+/', $info['version']))) {
// Work around bug that causes Git to fail for users without home directory.
$home = getenv('HOME') === FALSE ? 'HOME=' . DRUPAL_ROOT . ' ' : '';
// Verify that we are in a Git repository. For core, also verify that this
// is really a Drupal repository.
$directory = exec($home . 'git -C ' . escapeshellarg(dirname($file->filename)) . ' rev-parse --show-toplevel 2> ' . GIT_DEPLOY_ERROR_DUMP);
if (!empty($directory) && (!$is_core || $directory == DRUPAL_ROOT)) {
// Only check Git once per repository.
if (!isset($projects[$directory])) {
$projects[$directory] = array();
// Make sure Git operates in the right directory.
$git = $home . 'git -C ' . escapeshellarg($directory);
// Ensure file is in repository.
if (exec("{$git} ls-files " . escapeshellarg(str_replace("{$directory}/", '', realpath($file->filename))) . ' 2> ' . GIT_DEPLOY_ERROR_DUMP)) {
// Get upstream info.
$upstream = _git_deploy_get_upstream($git, $is_core ? array(
'6',
) : array(
'6.x-*',
));
if ($is_core) {
$project_name = 'drupal';
}
elseif (isset($upstream['remote'])) {
// Find the project name based on fetch URL.
$fetch_url = exec("{$git} config --get " . escapeshellarg("remote.{$upstream['remote']}.url") . ' 2> ' . GIT_DEPLOY_ERROR_DUMP);
if (!empty($fetch_url)) {
$project_name = basename($fetch_url, '.git');
$projects[$directory]['project'] = $project_name;
}
}
// Set project datestamp.
if (isset($upstream['datestamp'])) {
$projects[$directory]['datestamp'] = $upstream['datestamp'];
// The '_info_file_ctime' should always get the latest value.
if (empty($info['_info_file_ctime'])) {
$projects[$directory]['_info_file_ctime'] = $upstream['datestamp'];
}
else {
$projects[$directory]['_info_file_ctime'] = max($info['_info_file_ctime'], $upstream['datestamp']);
}
}
// Set version from tag.
if (isset($upstream['tag'])) {
$projects[$directory]['version'] = $upstream['tag'];
}
elseif (isset($upstream['branch'])) {
if ($upstream['branch'] != 'master') {
$projects[$directory]['version'] = "{$upstream['branch']}-dev";
}
if (module_exists('mydropwizard') && ($upstream['synced'] || $upstream['branch'] == 'master')) {
if (!isset($available)) {
// We only get this from the cache because an update status
// query is supposed to done only after processing all enabled
// modules and themes.
if (($cache = _mydropwizard_cache_get('mydropwizard_available_releases')) && $cache->expire > time()) {
$available = $cache->data;
$last_check = variable_get('mydropwizard_last_check', 0);
}
}
if (!empty($available[$project_name]['releases'])) {
if ($upstream['branch'] == 'master') {
// If there's available update_status data, we can use the
// version string the release node pointing to HEAD really
// has.
foreach ($available[$project_name]['releases'] as $release) {
if (isset($release['tag']) && $release['tag'] == 'HEAD') {
$projects[$directory]['version'] = $release['version'];
break;
}
}
}
if ($upstream['synced']) {
// This project's datestamp needs to be synced with upstream
// release.
$version = $projects[$directory]['version'];
if (!isset($available[$project_name]['releases'][$version]) || $projects[$directory]['_info_file_ctime'] > $last_check) {
// We need to update available release data for this
// project.
$update[] = $project_name;
}
else {
_git_deploy_datestamp_sync($projects[$directory], $available[$project_name]['releases'][$version]);
}
}
}
}
}
}
}
$info = $projects[$directory] + $info;
}
}
}