All pastes #246338 Raw Edit

Someone

public text v1 · immutable
#246338 ·published 2006-11-12 03:23 UTC
rendered paste body
/**
 * Returns an array of version number values based on the given tag.
 */
function cvs_get_version_from_tag($tag, $project) {
  // First, split on '--', if it's there, that tells us API vs. regular
  list($first_ver, $second_ver) = explode('--', $tag->tag);
  $first = explode('-', $first_ver, 5);
  $second = empty($second_ver) ? array() : explode('-', $second_ver, 3);

  if ($project->nid == 3060) {
    if ($first[1] >= 5) {
      $version->version_major = $first[1];
      if (isset($first[2])) {
        $version->version_patch = $first[2];
        $version->version_extra = _cvs_get_extra($first[3].$first[4]);
      }
      else {
        $version->version_patch = 'x';
        $version->version_extra = 'dev';
      }
    }
    else {
      if (isset($first[3])) {
        // Looks like "DRUPAL-X-Y-Z". Ignore the 'DRUPAL' part in $first[0].
        $version->version_major = $first[1];
        $version->version_minor = $first[2];
        $version->version_patch = $first[3];
        $version->version_extra = _cvs_get_extra($first[4]);
      }
      else {
        // Looks like "DRUPAL-X-Y", must be like "DRUPAL-4-7" (branch)
        $version->version_major = $first[1];
        $version->version_minor = $first[2];
        $version->version_patch = 'x';
        $version->version_extra = 'dev';
      }
    }
  }
  else {
    // Contrib tags don't need any special cases.  If there's nothing
    // after the '--' (the default stable branch), we want "-1.x-dev".
    $version->version_major = isset($second[0]) ? $second[0] : 1;
    $version->version_patch = isset($second[1]) ? $second[1] : 'x';
    $version->version_extra = $tag->branch ? 'dev' : _cvs_get_extra($second[2]);
  }
  if ($tree = project_release_get_api_taxonomy()) {
    // If we're using the compatibility taxonomy, find the right tid.
    // For both core and contrib, it's set by what we saw before the '--', 
    // namely, the stuff in the $first array...
    if (!isset($first[2])) {
      $target = "$first[1].x";
    }
    else {
      $target = "$first[1].$first[2].x";
    }
    foreach ($tree as $i => $term) {
      if ($term->name == $target) {
        $version->version_api_tid = $term->tid;
        break;
      }
    }
  }
  // TODO: add code to validate we parsed something reasonable, and ignore bad tags.
  return $version;
}