| 261 | |
| 262 | === git_subtree_system_info_alter() === |
| 263 | {{{ |
| 264 | /** |
| 265 | * Implement hook_system_info_alter() to provide metadata to drupal from git. |
| 266 | * |
| 267 | * We support populating $info from a gitinfo file. |
| 268 | * |
| 269 | * @param $info |
| 270 | * The module/theme info array we're altering. |
| 271 | * @param $file |
| 272 | * An object describing the filesystem location of the module/theme. |
| 273 | */ |
| 274 | function git_subtree_system_info_alter(&$info, $file) { |
| 275 | // Determine whether this is a theme or a module |
| 276 | $type = isset($info['engine']) ? 'theme' : 'module'; |
| 277 | // We only need to look for a version if it is not yet set |
| 278 | if (empty($info['version'])) { |
| 279 | // Get the filename |
| 280 | $filename = check_plain($file->filename); |
| 281 | // Get the directory of the theme/module |
| 282 | $directory = dirname($filename); |
| 283 | // Check whether this belongs to core. Speed optimization. |
| 284 | if (drupal_substr($directory, 0, drupal_strlen($type)) != $type) { |
| 285 | // Guess the gitinfo filename |
| 286 | $gitinfo_filename = preg_replace('/\.[^.]*/', '.gitinfo', $filename); |
| 287 | // Check whether a gitinfo file exists |
| 288 | if (file_exists($gitinfo_filename) && is_readable ($gitinfo_filename)) { |
| 289 | // Parse the gitinfo file |
| 290 | $gitinfo = parse_ini_file($gitinfo_filename); |
| 291 | foreach (array_keys($gitinfo) as $key) { |
| 292 | if (isset($gitinfo[$key])) { |
| 293 | $info[$key] = $gitinfo[$key]; |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | }}} |